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

Unified Diff: base/trace_event/heap_profiler_allocation_context_tracker.cc

Issue 1814083002: [tracing] Add thread name to the pseudo stack of heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profiler
Patch Set: Add comment. Created 4 years, 9 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/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 2877d2af91b27ace28839ebaac7468322cf4823f..2dfe79fb34af0985b835709661a315a56a355b52 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc
@@ -49,12 +49,19 @@ AllocationContextTracker::GetInstanceForCurrentThread() {
return tracker;
}
-AllocationContextTracker::AllocationContextTracker() {
+AllocationContextTracker::AllocationContextTracker() : thread_name_(nullptr) {
pseudo_stack_.reserve(kMaxStackDepth);
}
AllocationContextTracker::~AllocationContextTracker() {}
// static
+void AllocationContextTracker::SetCurrentThreadName(const char* name) {
+ if (name && capture_enabled()) {
+ GetInstanceForCurrentThread()->thread_name_ = name;
+ }
+}
+
+// static
void AllocationContextTracker::SetCaptureEnabled(bool enabled) {
// When enabling capturing, also initialize the TLS slot. This does not create
// a TLS instance yet.
@@ -103,6 +110,13 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() {
auto src_end = pseudo_stack_.end();
auto dst_end = std::end(ctx.backtrace.frames);
+ // Add the thread name as the first enrty in the backtrace.
+ if (thread_name_) {
+ DCHECK(dst < dst_end);
+ *dst = thread_name_;
+ ++dst;
+ }
+
// Copy as much of the bottom of the pseudo stack into the backtrace as
// possible.
for (; src != src_end && dst != dst_end; src++, dst++)

Powered by Google App Engine
This is Rietveld 408576698