Index: base/trace_event/heap_profiler_allocation_context_tracker.cc |
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc |
index b0e208eb6118b7eaa2e5b2d437c679e09358b54f..842441d6185b2e469d33707d8cf23c93ee1e1bc4 100644 |
--- a/base/trace_event/heap_profiler_allocation_context_tracker.cc |
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc |
@@ -8,6 +8,7 @@ |
#include <iterator> |
#include "base/atomicops.h" |
+#include "base/compiler_specific.h" |
#include "base/threading/thread_local_storage.h" |
#include "base/trace_event/heap_profiler_allocation_context.h" |
@@ -19,6 +20,7 @@ subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; |
namespace { |
const size_t kMaxStackDepth = 128u; |
+const size_t kMaxTaskDepth = 16u; |
AllocationContextTracker* const kInitializingSentinel = |
reinterpret_cast<AllocationContextTracker*>(-1); |
@@ -32,6 +34,24 @@ void DestructAllocationContextTracker(void* alloc_ctx_tracker) { |
} // namespace |
+AllocationContextTracker::ScopedTaskExecutionEvent::ScopedTaskExecutionEvent( |
+ const char* category_group, |
+ const char* posted_reason) |
+ : category_(category_group) { |
+ if (UNLIKELY(capture_enabled())) { |
+ AllocationContextTracker* tracker = GetInstanceForCurrentThread(); |
+ tracker->PushCurrentCategoryName(category_); |
+ } |
+} |
+ |
+AllocationContextTracker::ScopedTaskExecutionEvent:: |
+ ~ScopedTaskExecutionEvent() { |
+ if (UNLIKELY(capture_enabled())) { |
+ AllocationContextTracker* tracker = GetInstanceForCurrentThread(); |
+ tracker->PopCurrentCategoryName(category_); |
+ } |
+} |
+ |
// static |
AllocationContextTracker* |
AllocationContextTracker::GetInstanceForCurrentThread() { |
@@ -51,6 +71,7 @@ AllocationContextTracker::GetInstanceForCurrentThread() { |
AllocationContextTracker::AllocationContextTracker() { |
pseudo_stack_.reserve(kMaxStackDepth); |
+ categories_.reserve(kMaxTaskDepth); |
} |
AllocationContextTracker::~AllocationContextTracker() {} |
@@ -122,10 +143,27 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() { |
std::fill(dst, dst_end, nullptr); |
} |
- ctx.type_name = nullptr; |
+ // Set the default type name to file name where the task was posted from. |
+ // TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension |
+ // (component name) in the heap profiler and not piggy back on the type name. |
+ ctx.type_name = categories_.empty() ? nullptr : categories_.back(); |
return ctx; |
} |
+void AllocationContextTracker::PushCurrentCategoryName(const char* category) { |
+ DCHECK(category != nullptr); |
Primiano Tucci (use gerrit)
2016/03/25 01:56:31
I think as a general stylistic pattern we don't bo
ssid
2016/03/28 18:14:49
Done.
|
+ if (categories_.size() < kMaxTaskDepth) |
+ categories_.push_back(category); |
+ else |
+ NOTREACHED(); |
+} |
+ |
+void AllocationContextTracker::PopCurrentCategoryName(const char* category) { |
+ DCHECK_EQ(category, categories_.back()) |
+ << "Encountered an unmatched category end"; |
+ categories_.pop_back(); |
+} |
+ |
} // namespace trace_event |
} // namespace base |