[compiler-rt] r330857 - [scudo] Adding an interface function to print allocator stats

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 11:52:29 PDT 2018


Author: cryptoad
Date: Wed Apr 25 11:52:29 2018
New Revision: 330857

URL: http://llvm.org/viewvc/llvm-project?rev=330857&view=rev
Log:
[scudo] Adding an interface function to print allocator stats

Summary:
This adds `__scudo_print_stats` as an interface function to display the Primary
and Secondary allocator statistics for Scudo.

Reviewers: alekseyshl, flowerhack

Reviewed By: alekseyshl

Subscribers: delcypher, llvm-commits, #sanitizers

Differential Revision: https://reviews.llvm.org/D46016

Added:
    compiler-rt/trunk/test/scudo/stats.c
Modified:
    compiler-rt/trunk/include/sanitizer/scudo_interface.h
    compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
    compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h
    compiler-rt/trunk/lib/scudo/scudo_interface_internal.h

Modified: compiler-rt/trunk/include/sanitizer/scudo_interface.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/scudo_interface.h?rev=330857&r1=330856&r2=330857&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/scudo_interface.h (original)
+++ compiler-rt/trunk/include/sanitizer/scudo_interface.h Wed Apr 25 11:52:29 2018
@@ -27,6 +27,11 @@ extern "C" {
   // 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

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator.cpp?rev=330857&r1=330856&r2=330857&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator.cpp Wed Apr 25 11:52:29 2018
@@ -594,6 +594,11 @@ struct ScudoAllocator {
       SoftRssLimitMb = LimitMb;
     CheckRssLimit = HardRssLimitMb || SoftRssLimitMb;
   }
+
+  void printStats() {
+    initThreadMaybe();
+    BackendAllocator.printStats();
+  }
 };
 
 static ScudoAllocator Instance(LINKER_INITIALIZED);
@@ -743,3 +748,7 @@ void __scudo_set_rss_limit(uptr LimitMb,
     return;
   Instance.setRssLimit(LimitMb, !!HardLimit);
 }
+
+void __scudo_print_stats() {
+  Instance.printStats();
+}

Modified: compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h?rev=330857&r1=330856&r2=330857&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator_combined.h Wed Apr 25 11:52:29 2018
@@ -61,6 +61,11 @@ class ScudoCombinedAllocator {
     Stats.Get(StatType);
   }
 
+  void printStats() {
+    Primary.PrintStats();
+    Secondary.PrintStats();
+  }
+
  private:
   PrimaryAllocator Primary;
   SecondaryAllocator Secondary;

Modified: compiler-rt/trunk/lib/scudo/scudo_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_interface_internal.h?rev=330857&r1=330856&r2=330857&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_interface_internal.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_interface_internal.h Wed Apr 25 11:52:29 2018
@@ -25,6 +25,9 @@ const char* __scudo_default_options();
 
 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_

Added: compiler-rt/trunk/test/scudo/stats.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/stats.c?rev=330857&view=auto
==============================================================================
--- compiler-rt/trunk/test/scudo/stats.c (added)
+++ compiler-rt/trunk/test/scudo/stats.c Wed Apr 25 11:52:29 2018
@@ -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:




More information about the llvm-commits mailing list