Chromium Code Reviews| 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 f27ab20e836bb78953527b1e49dcf4740c30a55d..a2b09c0d67dc3c018f8bb55a25efae24a4e6d686 100644 |
| --- a/base/trace_event/heap_profiler_allocation_context_tracker.cc |
| +++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc |
| @@ -7,6 +7,7 @@ |
| #include <algorithm> |
| #include <iterator> |
| +#include "base/allocator/features.h" |
| #include "base/atomicops.h" |
| #include "base/threading/thread_local_storage.h" |
| #include "base/trace_event/heap_profiler_allocation_context.h" |
| @@ -14,7 +15,8 @@ |
| namespace base { |
| namespace trace_event { |
| -subtle::Atomic32 AllocationContextTracker::capture_enabled_ = 0; |
| +subtle::Atomic32 AllocationContextTracker::capture_mode_ = |
| + static_cast<int32_t>(AllocationContextTracker::CaptureMode::DISABLED); |
| namespace { |
| @@ -58,21 +60,21 @@ AllocationContextTracker::~AllocationContextTracker() {} |
| // static |
| void AllocationContextTracker::SetCurrentThreadName(const char* name) { |
| - if (name && capture_enabled()) { |
| + if (name && capture_mode() != CaptureMode::DISABLED) { |
| GetInstanceForCurrentThread()->thread_name_ = name; |
| } |
| } |
| // static |
| -void AllocationContextTracker::SetCaptureEnabled(bool enabled) { |
| +void AllocationContextTracker::SetCaptureMode(CaptureMode mode) { |
| // When enabling capturing, also initialize the TLS slot. This does not create |
| // a TLS instance yet. |
| - if (enabled && !g_tls_alloc_ctx_tracker.initialized()) |
| + if (mode != CaptureMode::DISABLED && !g_tls_alloc_ctx_tracker.initialized()) |
| g_tls_alloc_ctx_tracker.Initialize(DestructAllocationContextTracker); |
| - // Release ordering ensures that when a thread observes |capture_enabled_| to |
| + // Release ordering ensures that when a thread observes |capture_mode_| to |
| // be true through an acquire load, the TLS slot has been initialized. |
| - subtle::Release_Store(&capture_enabled_, enabled); |
| + subtle::Release_Store(&capture_mode_, static_cast<int32_t>(mode)); |
| } |
| void AllocationContextTracker::PushPseudoStackFrame( |
| @@ -116,30 +118,59 @@ void AllocationContextTracker::PopCurrentTaskContext(const char* context) { |
| task_contexts_.pop_back(); |
| } |
| -// static |
| AllocationContext AllocationContextTracker::GetContextSnapshot() { |
| AllocationContext ctx; |
| - // Fill the backtrace. |
| - { |
| - auto backtrace = std::begin(ctx.backtrace.frames); |
| - auto backtrace_end = std::end(ctx.backtrace.frames); |
| + CaptureMode mode = static_cast<CaptureMode>( |
| + subtle::NoBarrier_Load(&capture_mode_)); |
| + |
| + auto backtrace = std::begin(ctx.backtrace.frames); |
| + auto backtrace_end = std::end(ctx.backtrace.frames); |
| - // Add the thread name as the first entry |
| - if (thread_name_) { |
| - *backtrace++ = StackFrame::FromThreadName(thread_name_); |
| - } |
| + // Add the thread name as the first entry |
| + if (thread_name_) { |
| + *backtrace++ = StackFrame::FromThreadName(thread_name_); |
| + } |
| - for (const auto& event_name: pseudo_stack_) { |
| - if (backtrace == backtrace_end) { |
| + switch (mode) { |
| + case CaptureMode::DISABLED: |
| + { |
| break; |
| } |
| - *backtrace++ = StackFrame::FromTraceEventName(event_name); |
| - } |
| - |
| - ctx.backtrace.frame_count = backtrace - std::begin(ctx.backtrace.frames); |
| + case CaptureMode::PSEUDO_STACK: |
| + { |
| + for (const auto& event_name: pseudo_stack_) { |
| + if (backtrace == backtrace_end) { |
| + break; |
| + } |
| + *backtrace++ = StackFrame::FromTraceEventName(event_name); |
| + } |
| + break; |
| + } |
| +#if ENABLE_NATIVE_ALLOCATION_TRACES |
| + case CaptureMode::NATIVE_STACK: |
| + { |
| + // base::trace_event::AllocationContextTracker::GetContextSnapshot() |
| + const size_t kKnownFrameCount = 1; |
| + |
| + const void* frames[Backtrace::kMaxFrameCount]; |
| + size_t frame_count = debug::TraceStackFramePointers( |
| + frames, |
| + backtrace_end - backtrace, |
|
Primiano Tucci (use gerrit)
2016/04/21 20:08:21
this will still return only the stack frames close
Dmitry Skiba
2016/04/22 06:31:15
No, you are right, I'm returning N bottom frames,
Primiano Tucci (use gerrit)
2016/04/22 09:02:46
I understand this but I believe that all the clust
|
| + kKnownFrameCount); |
|
Primiano Tucci (use gerrit)
2016/04/21 20:08:21
you can just s|kKnownFrameCount|1 /* skip_initial
|
| + |
| + // Copy frames backwards |
| + for (ssize_t i = frame_count - 1; i >= 0; --i) { |
| + const void* frame = frames[i]; |
| + *backtrace++ = StackFrame::FromProgramCounter(frame); |
| + } |
| + break; |
| + } |
| +#endif // ENABLE_NATIVE_ALLOCATION_TRACES |
| } |
| + ctx.backtrace.frame_count = backtrace - std::begin(ctx.backtrace.frames); |
| + |
| // 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 = task_contexts_.empty() ? nullptr : task_contexts_.back(); |