Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: base/trace_event/memory_profiler_allocation_context.cc

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove WriteStackFrames, DISALLOW_COPY_AND_ASSIGN Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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() {}

Powered by Google App Engine
This is Rietveld 408576698