[Libreoffice-commits] online.git: loolwsd/configure.ac loolwsd/.gitignore loolwsd/loolmap.c loolwsd/Makefile.am
Henry Castro
hcastro at collabora.com
Wed Dec 23 09:12:02 PST 2015
loolwsd/.gitignore | 3
loolwsd/Makefile.am | 4 -
loolwsd/configure.ac | 1
loolwsd/loolmap.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 184 insertions(+), 1 deletion(-)
New commits:
commit 1bd85bc6418d4dcaeb910a695b544ac90bdca9b5
Author: Henry Castro <hcastro at collabora.com>
Date: Wed Dec 23 09:55:56 2015 -0500
loolwsd: merged loolmap
Change-Id: I43845ce5f45c01a67db32ab136ad96b70bc31217
Reviewed-on: https://gerrit.libreoffice.org/20908
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/.gitignore b/loolwsd/.gitignore
index 1461eea..a50e3e6 100644
--- a/loolwsd/.gitignore
+++ b/loolwsd/.gitignore
@@ -13,6 +13,7 @@
/config.log
/config.status
/configure
+/compile
/depcomp
/install-sh
/missing
@@ -20,6 +21,7 @@
/systemplate
/test-driver
/jails
+/loolwsd.spec
*.o
*.exe
@@ -33,6 +35,7 @@ loadtest
loolwsd
loolkit
loolbroker
+loolmap
sockettransporttest
# Debug output
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index d1f76cb..02fe176 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS = test
-bin_PROGRAMS = loolwsd loolbroker loolkit
+bin_PROGRAMS = loolwsd loolbroker loolkit loolmap
dist_bin_SCRIPTS = loolwsd-systemplate-setup
@@ -25,6 +25,8 @@ loolkit_SOURCES = LOOLKit.cpp $(broker_shared_sources)
loolbroker_SOURCES = LOOLBroker.cpp $(broker_shared_sources)
+loolmap_SOURCES = loolmap.c
+
noinst_HEADERS = LOKitHelper.hpp LOOLProtocol.hpp LOOLSession.hpp MasterProcessSession.hpp ChildProcessSession.hpp LOOLWSD.hpp LoadTest.hpp MessageQueue.hpp TileCache.hpp Util.hpp Png.hpp \
bundled/include/LibreOfficeKit/LibreOfficeKit.h bundled/include/LibreOfficeKit/LibreOfficeKitEnums.h \
bundled/include/LibreOfficeKit/LibreOfficeKitInit.h bundled/include/LibreOfficeKit/LibreOfficeKitTypes.h
diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index dce87dc..fe58ce8 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -13,6 +13,7 @@ AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
+AC_PROG_CC
AC_LANG_PUSH([C++])
diff --git a/loolwsd/loolmap.c b/loolwsd/loolmap.c
new file mode 100644
index 0000000..08b149a
--- /dev/null
+++ b/loolwsd/loolmap.c
@@ -0,0 +1,177 @@
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <locale.h>
+
+#define MAP_SIZE 20
+#define PATH_SIZE 64
+#define BUFFER_SIZE 9600
+
+static int read_buffer( char *buffer, unsigned size,
+ const char *file, char sep )
+{
+ int file_desc;
+ unsigned total_bytes = 0;
+
+ file_desc = open(file, O_RDONLY);
+ if(file_desc == -1)
+ return 0;
+
+ for(;;)
+ {
+ ssize_t number_bytes = read( file_desc,
+ buffer + total_bytes,
+ size - total_bytes );
+ if(number_bytes == -1)
+ {
+ if(errno==EINTR)
+ continue;
+ break;
+ }
+
+ total_bytes += number_bytes;
+ if(total_bytes == size)
+ {
+ --total_bytes;
+ break;
+ }
+
+ if(number_bytes==0)
+ break; // EOF
+ }
+
+ close(file_desc);
+
+ if(total_bytes)
+ {
+ int i=total_bytes;
+
+ while(i--)
+ if(buffer[i]=='\n' || buffer[i]=='\0')
+ buffer[i]=sep;
+
+ if(buffer[total_bytes-1]==' ')
+ buffer[total_bytes-1]='\0';
+ }
+
+ buffer[total_bytes] = '\0';
+ return total_bytes;
+}
+
+static void total_smaps(unsigned proc_id, const char *file, const char *cmdline)
+{
+ FILE *file_pointer;
+ char buffer[BUFFER_SIZE];
+
+ unsigned long long private_dirty = 0ull;
+ unsigned long long private_clean = 0ull;
+ unsigned long long shared_dirty = 0ull;
+ unsigned long long shared_clean = 0ull;
+ unsigned long long total_private_dirty = 0ull;
+ unsigned long long total_private_clean = 0ull;
+ unsigned long long total_shared_dirty = 0ull;
+ unsigned long long total_shared_clean = 0ull;
+ unsigned long long smap_value;
+ char smap_key[MAP_SIZE];
+
+ if ((file_pointer = fopen(file, "r")) == NULL)
+ error(EXIT_FAILURE, errno, "%s", file);
+
+ while (fgets(buffer, sizeof(buffer), file_pointer))
+ {
+ if (buffer[0] >= 'A' && buffer[0] <= 'Z')
+ {
+ if (sscanf(buffer, "%20[^:]: %llu", smap_key, &smap_value) == 2)
+ {
+ if (strncmp("Shared_Dirty", smap_key, 12) == 0)
+ {
+ shared_dirty = smap_value;
+ total_shared_dirty += smap_value;
+ continue;
+ }
+ if (strncmp("Shared_Clean", smap_key, 12) == 0)
+ {
+ shared_clean = smap_value;
+ total_shared_clean += smap_value;
+ continue;
+ }
+ if (strncmp("Private_Dirty", smap_key, 13) == 0)
+ {
+ private_dirty = smap_value;
+ total_private_dirty += smap_value;
+ continue;
+ }
+ if (strncmp("Private_Clean", smap_key, 13) == 0)
+ {
+ private_clean = smap_value;
+ total_private_clean += smap_value;
+ continue;
+ }
+ }
+ }
+ }
+
+ if ( errno )
+ error(EXIT_FAILURE, errno, "%s\n", cmdline);
+
+ printf("%s\n", cmdline);
+ printf("Process ID :%20ld\n", proc_id);
+ printf("--------------------------------------\n");
+ printf("Shared Clean :%20ld kB\n", total_shared_clean);
+ printf("Shared Dirty :%20ld kB\n", total_shared_dirty);
+ printf("Private Clean :%20ld kB\n", total_private_clean);
+ printf("Private Dirty :%20ld kB\n", total_private_dirty);
+ printf("--------------------------------------\n");
+ printf("Shared :%20ld kB\n", total_shared_clean + total_shared_dirty);
+ printf("Private :%20ld kB\n\n", total_private_clean + total_private_dirty);
+}
+
+int main(int argc, char **argv)
+{
+ DIR *root_proc;
+ struct dirent *dir_proc;
+
+ unsigned pid_curr;
+ unsigned pid_proc;
+ char path_proc[PATH_SIZE];
+ char cmdline[BUFFER_SIZE];
+
+ setlocale (LC_ALL, "");
+ getopt(argc, argv, "");
+
+ if (argc != 2)
+ error(EXIT_FAILURE, EINVAL);
+
+ root_proc = opendir("/proc");
+ if (!root_proc)
+ error(EXIT_FAILURE, errno, "%s", "/proc");
+
+ while ( ( dir_proc = readdir(root_proc) ) )
+ {
+ if ( !dir_proc && !dir_proc->d_name )
+ error(EXIT_FAILURE, ENOTDIR );
+
+ if ( *dir_proc->d_name > '0' && *dir_proc->d_name <= '9' )
+ {
+ pid_proc = strtoul(dir_proc->d_name, NULL, 10);
+ snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "cmdline");
+ if (read_buffer(cmdline, sizeof(cmdline), path_proc, ' ') &&
+ strstr(cmdline, argv[1]) &&
+ !strstr(cmdline, argv[0]) )
+ {
+ snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "smaps");
+ total_smaps(pid_proc, path_proc, cmdline);
+ }
+ }
+ }
+
+ if ( errno )
+ error(EXIT_FAILURE, errno);
+
+ return EXIT_SUCCESS;
+}
More information about the Libreoffice-commits
mailing list