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

Unified Diff: base/trace_event/heap_profiler_allocation_context_tracker.cc

Issue 1891543003: [tracing] Turn StackFrame into struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add "the ones closer to main()" Created 4 years, 8 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 1fc8bc008a522419f7b1eb454c9b45a6d8c739b0..ab51d463e1d71b75ec37e79063e1e4e96e796cb5 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc
@@ -75,17 +75,18 @@ void AllocationContextTracker::SetCaptureEnabled(bool enabled) {
subtle::Release_Store(&capture_enabled_, enabled);
}
-void AllocationContextTracker::PushPseudoStackFrame(StackFrame frame) {
+void AllocationContextTracker::PushPseudoStackFrame(
+ const char* trace_event_name) {
// Impose a limit on the height to verify that every push is popped, because
// in practice the pseudo stack never grows higher than ~20 frames.
if (pseudo_stack_.size() < kMaxStackDepth)
- pseudo_stack_.push_back(frame);
+ pseudo_stack_.push_back(trace_event_name);
else
NOTREACHED();
}
-// static
-void AllocationContextTracker::PopPseudoStackFrame(StackFrame frame) {
+void AllocationContextTracker::PopPseudoStackFrame(
+ const char* trace_event_name) {
// Guard for stack underflow. If tracing was started with a TRACE_EVENT in
// scope, the frame was never pushed, so it is possible that pop is called
// on an empty stack.
@@ -95,7 +96,7 @@ void AllocationContextTracker::PopPseudoStackFrame(StackFrame frame) {
// Assert that pushes and pops are nested correctly. This DCHECK can be
// hit if some TRACE_EVENT macro is unbalanced (a TRACE_EVENT_END* call
// without a corresponding TRACE_EVENT_BEGIN).
- DCHECK_EQ(frame, pseudo_stack_.back())
+ DCHECK_EQ(trace_event_name, pseudo_stack_.back())
<< "Encountered an unmatched TRACE_EVENT_END";
pseudo_stack_.pop_back();
@@ -121,25 +122,22 @@ AllocationContext AllocationContextTracker::GetContextSnapshot() {
// Fill the backtrace.
{
- auto src = pseudo_stack_.begin();
- auto dst = std::begin(ctx.backtrace.frames);
- auto src_end = pseudo_stack_.end();
- auto dst_end = std::end(ctx.backtrace.frames);
+ auto backtrace = std::begin(ctx.backtrace.frames);
+ auto backtrace_end = std::end(ctx.backtrace.frames);
- // Add the thread name as the first enrty in the backtrace.
+ // Add the thread name as the first entry
if (thread_name_) {
- DCHECK(dst < dst_end);
- *dst = thread_name_;
- ++dst;
+ *backtrace++ = StackFrame::FromThreadName(thread_name_);
}
- // Copy as much of the bottom of the pseudo stack into the backtrace as
- // possible.
- for (; src != src_end && dst != dst_end; src++, dst++)
- *dst = *src;
+ for (const char* event_name: pseudo_stack_) {
+ if (backtrace == backtrace_end) {
+ break;
+ }
+ *backtrace++ = StackFrame::FromTraceEventName(event_name);
+ }
- // If there is room for more, fill the remaining slots with empty frames.
- std::fill(dst, dst_end, nullptr);
+ ctx.backtrace.frame_count = backtrace - std::begin(ctx.backtrace.frames);
}
// TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension

Powered by Google App Engine
This is Rietveld 408576698