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

Unified Diff: base/trace_event/heap_profiler_allocation_context_tracker.cc

Issue 1839503002: [tracing] Add native allocation tracing mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert whitespace change in malloc_dump_provider 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 f27ab20e836bb78953527b1e49dcf4740c30a55d..3180e39809726e0206b8c1b76a34022a1796924b 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<int>(AllocationContextTracker::CaptureMode::DISABLED);
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 s/int/int32_t/
Dmitry Skiba 2016/04/20 19:19:24 Done.
namespace {
@@ -64,15 +66,15 @@ void AllocationContextTracker::SetCurrentThreadName(const char* 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<int>(mode));
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 int32_t
Dmitry Skiba 2016/04/20 19:19:24 Done.
}
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,
+ kKnownFrameCount);
+
+ // Copy frames backwards
+ for (size_t i = 0; i != frame_count; ++i) {
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 super slight optimization: if you make this a for
Dmitry Skiba 2016/04/20 19:19:24 Done, but slightly differently.
+ const void* frame = frames[frame_count - 1 - 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();

Powered by Google App Engine
This is Rietveld 408576698