diff options
author | Kostya Kortchinsky <kostyak@google.com> | 2018-04-25 18:52:29 +0000 |
---|---|---|
committer | Kostya Kortchinsky <kostyak@google.com> | 2018-04-25 18:52:29 +0000 |
commit | bc4072ffad7ecb03530b4bdf2da27fd49d29e607 (patch) | |
tree | 0061f6ff3b381134a4342259bea065fdcf442c65 | |
parent | 77cb99480a98ca2b2c30de28dc736d5b13ae67d6 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@330857 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/sanitizer/scudo_interface.h | 5 | ||||
-rw-r--r-- | lib/scudo/scudo_allocator.cpp | 9 | ||||
-rw-r--r-- | lib/scudo/scudo_allocator_combined.h | 5 | ||||
-rw-r--r-- | lib/scudo/scudo_interface_internal.h | 3 | ||||
-rw-r--r-- | test/scudo/stats.c | 21 |
5 files changed, 43 insertions, 0 deletions
diff --git a/include/sanitizer/scudo_interface.h b/include/sanitizer/scudo_interface.h index 25979fb23..be605f1d7 100644 --- a/include/sanitizer/scudo_interface.h +++ b/include/sanitizer/scudo_interface.h @@ -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 diff --git a/lib/scudo/scudo_allocator.cpp b/lib/scudo/scudo_allocator.cpp index e0f78a015..c72ac8601 100644 --- a/lib/scudo/scudo_allocator.cpp +++ b/lib/scudo/scudo_allocator.cpp @@ -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, s32 HardLimit) { return; Instance.setRssLimit(LimitMb, !!HardLimit); } + +void __scudo_print_stats() { + Instance.printStats(); +} diff --git a/lib/scudo/scudo_allocator_combined.h b/lib/scudo/scudo_allocator_combined.h index 1c8bb3f11..d22f2a377 100644 --- a/lib/scudo/scudo_allocator_combined.h +++ b/lib/scudo/scudo_allocator_combined.h @@ -61,6 +61,11 @@ class ScudoCombinedAllocator { Stats.Get(StatType); } + void printStats() { + Primary.PrintStats(); + Secondary.PrintStats(); + } + private: PrimaryAllocator Primary; SecondaryAllocator Secondary; diff --git a/lib/scudo/scudo_interface_internal.h b/lib/scudo/scudo_interface_internal.h index e2c63db23..3e520a50c 100644 --- a/lib/scudo/scudo_interface_internal.h +++ b/lib/scudo/scudo_interface_internal.h @@ -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_ diff --git a/test/scudo/stats.c b/test/scudo/stats.c new file mode 100644 index 000000000..e7cc78ff0 --- /dev/null +++ b/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: |