[sanitizer] better allocator stats (with rss)
authorKostya Serebryany <kcc@google.com>
Thu, 21 Jul 2016 21:38:40 +0000 (21:38 +0000)
committerKostya Serebryany <kcc@google.com>
Thu, 21 Jul 2016 21:38:40 +0000 (21:38 +0000)
llvm-svn: 276343

compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h
compiler-rt/lib/sanitizer_common/sanitizer_win.cc

index 6194669..da74350 100644 (file)
@@ -20,6 +20,7 @@
 #include "sanitizer_list.h"
 #include "sanitizer_mutex.h"
 #include "sanitizer_lfstack.h"
+#include "sanitizer_procmaps.h"
 
 namespace __sanitizer {
 
index 13f352a..cc37410 100644 (file)
@@ -144,6 +144,13 @@ class SizeClassAllocator64 {
     UnmapWithCallback(SpaceBeg(), kSpaceSize + AdditionalSize());
   }
 
+  static void FillMemoryProfile(uptr start, uptr rss, bool file, uptr *stats,
+                           uptr stats_size) {
+    for (uptr class_id = 0; class_id < stats_size; class_id++)
+      if (stats[class_id] == start)
+        stats[class_id] = rss;
+  }
+
   void PrintStats() {
     uptr total_mapped = 0;
     uptr n_allocated = 0;
@@ -157,15 +164,24 @@ class SizeClassAllocator64 {
     Printf("Stats: SizeClassAllocator64: %zdM mapped in %zd allocations; "
            "remains %zd\n",
            total_mapped >> 20, n_allocated, n_allocated - n_freed);
+    uptr rss_stats[kNumClasses];
+    for (uptr class_id = 0; class_id < kNumClasses; class_id++)
+      rss_stats[class_id] = SpaceBeg() + kRegionSize * class_id;
+    GetMemoryProfile(FillMemoryProfile, rss_stats, kNumClasses);
     for (uptr class_id = 1; class_id < kNumClasses; class_id++) {
       RegionInfo *region = GetRegionInfo(class_id);
       if (region->mapped_user == 0) continue;
-      Printf("  %02zd (%zd): total: %zd K allocs: %zd remains: %zd\n",
+      uptr in_use = region->n_allocated - region->n_freed;
+      uptr avail_chunks = region->allocated_user / SizeClassMap::Size(class_id);
+      Printf("  %02zd (%zd): mapped: %zdK allocs: %zd frees: %zd inuse: %zd"
+             " avail: %zd rss: %zdK\n",
              class_id,
              SizeClassMap::Size(class_id),
              region->mapped_user >> 10,
              region->n_allocated,
-             region->n_allocated - region->n_freed);
+             region->n_freed,
+             in_use, avail_chunks,
+             rss_stats[class_id] >> 10);
     }
   }
 
index 36d9204..cb4d7dd 100644 (file)
@@ -27,6 +27,7 @@
 #include "sanitizer_libc.h"
 #include "sanitizer_mutex.h"
 #include "sanitizer_placement_new.h"
+#include "sanitizer_procmaps.h"
 #include "sanitizer_stacktrace.h"
 #include "sanitizer_symbolizer.h"
 
@@ -884,6 +885,10 @@ bool IsProcessRunning(pid_t pid) {
 
 int WaitForProcess(pid_t pid) { return -1; }
 
+// FIXME implement on this platform.
+void GetMemoryProfile(fill_profile_f cb, uptr *stats, uptr stats_size) { }
+
+
 }  // namespace __sanitizer
 
 #endif  // _WIN32