[Libreoffice-commits] online.git: tools/map.cpp

Michael Meeks michael.meeks at collabora.com
Tue Nov 28 18:09:17 UTC 2017


 tools/map.cpp |   44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

New commits:
commit 2fb4521a9cd296163c87c7f24e3b3d9bd9966dd8
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Nov 28 18:08:26 2017 +0000

    Dump unshared heap memory ascii-art map by page..
    
    Change-Id: I21ef386958e651b53b4d8eef434958a20adcbe68

diff --git a/tools/map.cpp b/tools/map.cpp
index 7bab3f17..cd7fd788 100644
--- a/tools/map.cpp
+++ b/tools/map.cpp
@@ -23,6 +23,7 @@
 #include <dirent.h>
 #include <locale.h>
 
+typedef unsigned long long addr_t;
 
 #define MAP_SIZE 20
 #define PATH_SIZE 1000 // No harm in having it much larger than strictly necessary. Avoids compiler warning.
@@ -79,12 +80,52 @@ static int read_buffer(char *buffer, unsigned size,
     return total_bytes;
 }
 
+
+static void dump_unshared(unsigned proc_id, const std::vector<addr_t> &heapVAddresses)
+{
+    char path_proc[PATH_SIZE];
+    snprintf(path_proc, sizeof(path_proc), "/proc/%d/pagemap", proc_id);
+    int fd = open(path_proc, 0);
+    if (fd < 0)
+        error(EXIT_FAILURE, errno, "Failed to open %s", path_proc);
+
+    printf("Sharing map:\n");
+    addr_t numShared = 0, numOwn = 0;
+    for (auto p : heapVAddresses)
+    {
+        if (lseek(fd, (p / 0x1000 * 8), SEEK_SET) < 0)
+            error(EXIT_FAILURE, errno, "Failed to seek in pagemap");
+        addr_t vaddrData;
+        if (read(fd, &vaddrData, 8) < 0)
+            error(EXIT_FAILURE, errno, "Failed to read vaddrdata");
+        {
+            // https://patchwork.kernel.org/patch/6787921/
+//            fprintf(stderr, "addr: 0x%8llx bits: 0x%8llx : %s\n", p, vaddrData,
+//                    (vaddrData & ((addr_t)1 << 56)) ? "unshared" : "shared");
+            if (vaddrData & ((addr_t)1 << 56))
+            {
+                numOwn++;
+                printf("*");
+            }
+            else
+            {
+                numShared++;
+                printf(".");
+            }
+        }
+        if (!((numShared + numOwn) % 128))
+            printf("\n");
+    }
+    printf ("\nTotals:\n");
+    printf ("\tshared   %5lld (%lldkB)\n", numShared, numShared * 4);
+    printf ("\tunshared %5lld (%lldkB)\n", numOwn, numOwn * 4);
+}
+
 static void total_smaps(unsigned proc_id, const char *file, const char *cmdline)
 {
     FILE *file_pointer;
     char buffer[BUFFER_SIZE];
 
-    typedef unsigned long long addr_t;
     addr_t total_private_dirty = 0ull;
     addr_t total_private_clean = 0ull;
     addr_t total_shared_dirty = 0ull;
@@ -154,6 +195,7 @@ static void total_smaps(unsigned proc_id, const char *file, const char *cmdline)
     printf("--------------------------------------\n");
     printf("Heap page cnt :%20lld\n", (addr_t)heapVAddresses.size());
     printf("\n");
+    dump_unshared(proc_id, heapVAddresses);
 }
 
 int main(int argc, char **argv)


More information about the Libreoffice-commits mailing list