diff options
author | Kostya Serebryany <kcc@google.com> | 2018-09-06 22:08:41 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2018-09-06 22:08:41 +0000 |
commit | 6ec1600f21b1a4df7ce489766d78f6f3b665b832 (patch) | |
tree | bcb9156591601a7c29bf8af8ad6ef6e4c286e340 /lib/hwasan/hwasan_thread.cc | |
parent | 475f14d200d393eec4ce8e3a48ddd18594528018 (diff) | |
download | compiler-rt-6ec1600f21b1a4df7ce489766d78f6f3b665b832.tar.gz |
[hwasan] introduce __hwasan_print_memory_usage
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@341592 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan/hwasan_thread.cc')
-rw-r--r-- | lib/hwasan/hwasan_thread.cc | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/hwasan/hwasan_thread.cc b/lib/hwasan/hwasan_thread.cc index f77c37550..f3471e03b 100644 --- a/lib/hwasan/hwasan_thread.cc +++ b/lib/hwasan/hwasan_thread.cc @@ -26,14 +26,17 @@ static u32 RandomSeed() { Thread *Thread::main_thread; SpinMutex Thread::thread_list_mutex; +Thread::ThreadStats Thread::thread_stats; void Thread::InsertIntoThreadList(Thread *t) { CHECK(!t->next_); + SpinMutexLock l(&thread_list_mutex); + thread_stats.n_live_threads++; + thread_stats.total_stack_size += t->stack_size(); if (!main_thread) { main_thread = t; return; } - SpinMutexLock l(&thread_list_mutex); Thread *last = main_thread; while (last->next_) last = last->next_; @@ -43,6 +46,8 @@ void Thread::InsertIntoThreadList(Thread *t) { void Thread::RemoveFromThreadList(Thread *t) { CHECK_NE(t, main_thread); SpinMutexLock l(&thread_list_mutex); + thread_stats.n_live_threads--; + thread_stats.total_stack_size -= t->stack_size(); Thread *prev = main_thread; Thread *cur = prev->next_; CHECK(cur); @@ -67,10 +72,17 @@ void Thread::Create() { thread->random_state_ = flags()->random_tags ? RandomSeed() : thread->unique_id_; if (auto sz = flags()->heap_history_size) - thread->heap_allocations_ = RingBuffer<HeapAllocationRecord>::New(sz); - InsertIntoThreadList(thread); + thread->heap_allocations_ = HeapAllocationsRingBuffer::New(sz); SetCurrentThread(thread); thread->Init(); + InsertIntoThreadList(thread); +} + +uptr Thread::MemoryUsedPerThread() { + uptr res = sizeof(Thread); + if (auto sz = flags()->heap_history_size) + res += HeapAllocationsRingBuffer::SizeInBytes(sz); + return res; } void Thread::Init() { |