Chromium Code Reviews| Index: base/trace_event/memory_profiler_allocation_context.cc |
| diff --git a/base/trace_event/memory_profiler_allocation_context.cc b/base/trace_event/memory_profiler_allocation_context.cc |
| index 1f3ea06c857f501630539a446e666acd53f426ff..408617a9450aa0d6e8ecdf3133f0947c64601fc1 100644 |
| --- a/base/trace_event/memory_profiler_allocation_context.cc |
| +++ b/base/trace_event/memory_profiler_allocation_context.cc |
| @@ -5,7 +5,9 @@ |
| #include "base/trace_event/memory_profiler_allocation_context.h" |
| #include <algorithm> |
| +#include <cstring> |
| +#include "base/hash.h" |
| #include "base/threading/thread_local_storage.h" |
| namespace base { |
| @@ -20,22 +22,15 @@ ThreadLocalStorage::StaticSlot g_tls_alloc_ctx_tracker = TLS_INITIALIZER; |
| AllocationStack::AllocationStack() {} |
| AllocationStack::~AllocationStack() {} |
| -// This function is added to the TLS slot to clean up the instance when the |
| -// thread exits. |
| -void DestructAllocationContextTracker(void* alloc_ctx_tracker) { |
| - delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); |
| +bool operator==(const Backtrace& lhs, const Backtrace& rhs) { |
| + // Pointer equality of the stack frames is assumed, so instead of doing a deep |
| + // string comparison on all of the frames, a |memcmp| suffices. |
| + return std::memcmp(lhs.frames, rhs.frames, sizeof(lhs.frames)) == 0; |
| } |
| -AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() { |
| - auto tracker = |
| - static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); |
| - |
| - if (!tracker) { |
| - tracker = new AllocationContextTracker(); |
| - g_tls_alloc_ctx_tracker.Set(tracker); |
| - } |
| - |
| - return tracker; |
| +uint32_t BacktraceHash::operator()(const Backtrace& backtrace) const { |
| + return SuperFastHash(reinterpret_cast<const char*>(backtrace.frames), |
|
Primiano Tucci (use gerrit)
2015/10/26 11:52:06
be really careful with SuperFastHash. I got bitten
Ruud van Asseldonk
2015/10/26 14:51:26
I saw that discussion. Insertion in the hash table
Primiano Tucci (use gerrit)
2015/10/26 20:57:57
Ok, didn't realize that after all, if you end up h
|
| + sizeof(backtrace.frames)); |
| } |
| StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame, |
| @@ -46,7 +41,7 @@ StackFrameDeduplicator::FrameNode::~FrameNode() {} |
| StackFrameDeduplicator::StackFrameDeduplicator() {} |
| StackFrameDeduplicator::~StackFrameDeduplicator() {} |
| -int StackFrameDeduplicator::Insert(const AllocationContext::Backtrace& bt) { |
| +int StackFrameDeduplicator::Insert(const Backtrace& bt) { |
| int frame_index = -1; |
| std::map<StackFrame, int>* nodes = &roots_; |
| @@ -81,6 +76,24 @@ int StackFrameDeduplicator::Insert(const AllocationContext::Backtrace& bt) { |
| return frame_index; |
| } |
| +// This function is added to the TLS slot to clean up the instance when the |
| +// thread exits. |
| +void DestructAllocationContextTracker(void* alloc_ctx_tracker) { |
| + delete static_cast<AllocationContextTracker*>(alloc_ctx_tracker); |
| +} |
| + |
| +AllocationContextTracker* AllocationContextTracker::GetThreadLocalTracker() { |
| + auto tracker = |
| + static_cast<AllocationContextTracker*>(g_tls_alloc_ctx_tracker.Get()); |
| + |
| + if (!tracker) { |
| + tracker = new AllocationContextTracker(); |
| + g_tls_alloc_ctx_tracker.Set(tracker); |
| + } |
| + |
| + return tracker; |
| +} |
| + |
| AllocationContextTracker::AllocationContextTracker() {} |
| AllocationContextTracker::~AllocationContextTracker() {} |