[PATCH] D46016: [scudo] Adding an interface function to print allocator stats

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 08:53:07 PDT 2018


cryptoad updated this revision to Diff 143947.
cryptoad marked an inline comment as done.
cryptoad added a comment.

Add description of the function in the interface header.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D46016

Files:
  include/sanitizer/scudo_interface.h
  lib/scudo/scudo_allocator.cpp
  lib/scudo/scudo_allocator_combined.h
  lib/scudo/scudo_interface_internal.h
  test/scudo/stats.c


Index: test/scudo/stats.c
===================================================================
--- /dev/null
+++ test/scudo/stats.c
@@ -0,0 +1,21 @@
+// RUN: %clang_scudo %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// Tests that the allocator stats printing function exists and outputs
+// "something". Currently that "something" is fairly nebulous, as the 32-bit
+// primary doesn't output anything, and for the 64-bit one it's highly dependent
+// on the size class map and potential library allocations. So keep it very
+// generic for now.
+
+#include <stdlib.h>
+
+#include <sanitizer/scudo_interface.h>
+
+int main(int argc, char **argv)
+{
+  free(malloc(1U));
+  __scudo_print_stats();
+  return 0;
+}
+
+// CHECK: Stats:
Index: lib/scudo/scudo_interface_internal.h
===================================================================
--- lib/scudo/scudo_interface_internal.h
+++ lib/scudo/scudo_interface_internal.h
@@ -25,6 +25,9 @@
 
 SANITIZER_INTERFACE_ATTRIBUTE
 void __scudo_set_rss_limit(uptr LimitMb, s32 HardLimit);
+
+SANITIZER_INTERFACE_ATTRIBUTE
+void __scudo_print_stats();
 }  // extern "C"
 
 #endif  // SCUDO_INTERFACE_INTERNAL_H_
Index: lib/scudo/scudo_allocator_combined.h
===================================================================
--- lib/scudo/scudo_allocator_combined.h
+++ lib/scudo/scudo_allocator_combined.h
@@ -61,6 +61,11 @@
     Stats.Get(StatType);
   }
 
+  void printStats() {
+    Primary.PrintStats();
+    Secondary.PrintStats();
+  }
+
  private:
   PrimaryAllocator Primary;
   SecondaryAllocator Secondary;
Index: lib/scudo/scudo_allocator.cpp
===================================================================
--- lib/scudo/scudo_allocator.cpp
+++ lib/scudo/scudo_allocator.cpp
@@ -594,6 +594,11 @@
       SoftRssLimitMb = LimitMb;
     CheckRssLimit = HardRssLimitMb || SoftRssLimitMb;
   }
+
+  void printStats() {
+    initThreadMaybe();
+    BackendAllocator.printStats();
+  }
 };
 
 static ScudoAllocator Instance(LINKER_INITIALIZED);
@@ -743,3 +748,7 @@
     return;
   Instance.setRssLimit(LimitMb, !!HardLimit);
 }
+
+void __scudo_print_stats() {
+  Instance.printStats();
+}
Index: include/sanitizer/scudo_interface.h
===================================================================
--- include/sanitizer/scudo_interface.h
+++ include/sanitizer/scudo_interface.h
@@ -27,6 +27,11 @@
   // can be removed by setting LimitMb to 0. This function's parameters should
   // be fully trusted to avoid security mishaps.
   void __scudo_set_rss_limit(size_t LimitMb, int HardLimit);
+
+  // This function outputs various allocator statistics for both the Primary
+  // and Secondary allocators, including memory usage, number of allocations
+  // and deallocations.
+  void __scudo_print_stats(void);
 #ifdef __cplusplus
 }  // extern "C"
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46016.143947.patch
Type: text/x-patch
Size: 2810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180425/a09b57fc/attachment.bin>


More information about the llvm-commits mailing list