diff options
author | Kostya Serebryany <kcc@google.com> | 2016-09-14 22:00:58 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-09-14 22:00:58 +0000 |
commit | a4985a8ab5cd1689365a50200dd8ab2441c6fae9 (patch) | |
tree | 9282c05f8cf2cabafbf51f3247f980edf1546630 /lib/sanitizer_common/sanitizer_common_libcdep.cc | |
parent | d89810afdc2862ea865f5c297ef4ea5839941d25 (diff) |
[asan] add heap_profile=1 to asan to periodically print the heap profile. So far this is a very basic heap-profile functionality
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281546 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_common_libcdep.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_libcdep.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_libcdep.cc b/lib/sanitizer_common/sanitizer_common_libcdep.cc index bed8faba7..1a4c49e5e 100644 --- a/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -13,6 +13,7 @@ #include "sanitizer_common.h" +#include "sanitizer_allocator_interface.h" #include "sanitizer_flags.h" #include "sanitizer_stackdepot.h" #include "sanitizer_stacktrace.h" @@ -78,10 +79,12 @@ void SetAllocatorReleaseToOSCallback(AllocatorReleaseToOSCallback Callback) { void BackgroundThread(void *arg) { uptr hard_rss_limit_mb = common_flags()->hard_rss_limit_mb; uptr soft_rss_limit_mb = common_flags()->soft_rss_limit_mb; + bool heap_profile = common_flags()->heap_profile; bool allocator_release_to_os = common_flags()->allocator_release_to_os; uptr prev_reported_rss = 0; uptr prev_reported_stack_depot_size = 0; bool reached_soft_rss_limit = false; + uptr rss_during_last_reported_profile = 0; while (true) { SleepForMillis(100); uptr current_rss_mb = GetRSS() >> 20; @@ -124,6 +127,12 @@ void BackgroundThread(void *arg) { } } if (allocator_release_to_os && ReleseCallback) ReleseCallback(); + if (heap_profile && + current_rss_mb > rss_during_last_reported_profile * 1.1) { + Printf("\n\nHEAP PROFILE at RSS %zdMb\n", current_rss_mb); + __sanitizer_print_memory_profile(90); + rss_during_last_reported_profile = current_rss_mb; + } } } @@ -151,7 +160,8 @@ void MaybeStartBackgroudThread() { // Start the background thread if one of the rss limits is given. if (!common_flags()->hard_rss_limit_mb && !common_flags()->soft_rss_limit_mb && - !common_flags()->allocator_release_to_os) return; + !common_flags()->allocator_release_to_os && + !common_flags()->heap_profile) return; if (!&real_pthread_create) return; // Can't spawn the thread anyway. internal_start_thread(BackgroundThread, nullptr); #endif |