Commit 3e6c0cd8 authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

memlog: Add task contexts from allocation context to native mode

The task context is useful to debug mojo memory leaks since IPC messages
are tagged with contexts

BUG=874530

Change-Id: Id59d016f963f41fdeda6af69b3c470f0101dbfe7
Reviewed-on: https://chromium-review.googlesource.com/1232683Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: Siddhartha S <ssid@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593458}
parent 70b8caba
...@@ -259,13 +259,7 @@ bool AllocationContextTracker::GetContextSnapshot(AllocationContext* ctx) { ...@@ -259,13 +259,7 @@ bool AllocationContextTracker::GetContextSnapshot(AllocationContext* ctx) {
ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames); ctx->backtrace.frame_count = backtrace - std::begin(ctx->backtrace.frames);
// TODO(ssid): Fix crbug.com/594803 to add file name as 3rd dimension ctx->type_name = TaskContext();
// (component name) in the heap profiler and not piggy back on the type name.
if (!task_contexts_.empty()) {
ctx->type_name = task_contexts_.back();
} else {
ctx->type_name = nullptr;
}
return true; return true;
} }
......
...@@ -108,6 +108,11 @@ class BASE_EXPORT AllocationContextTracker { ...@@ -108,6 +108,11 @@ class BASE_EXPORT AllocationContextTracker {
void PushCurrentTaskContext(const char* context); void PushCurrentTaskContext(const char* context);
void PopCurrentTaskContext(const char* context); void PopCurrentTaskContext(const char* context);
// Returns most recent task context added by ScopedTaskExecutionTracker.
const char* TaskContext() const {
return task_contexts_.empty() ? nullptr : task_contexts_.back();
}
// Fills a snapshot of the current thread-local context. Doesn't fill and // Fills a snapshot of the current thread-local context. Doesn't fill and
// returns false if allocations are being ignored. // returns false if allocations are being ignored.
bool GetContextSnapshot(AllocationContext* snapshot); bool GetContextSnapshot(AllocationContext* snapshot);
......
...@@ -901,8 +901,7 @@ bool TestDriver::ValidateBrowserAllocations(base::Value* dump_json) { ...@@ -901,8 +901,7 @@ bool TestDriver::ValidateBrowserAllocations(base::Value* dump_json) {
if (IsRecordingAllAllocations()) { if (IsRecordingAllAllocations()) {
if (should_validate_dumps) { if (should_validate_dumps) {
result = ValidateDump(heaps_v2, kMallocAllocSize * kMallocAllocCount, result = ValidateDump(heaps_v2, kMallocAllocSize * kMallocAllocCount,
kMallocAllocCount, "malloc", kMallocAllocCount, "malloc", kMallocTypeTag,
HasPseudoFrames() ? kMallocTypeTag : nullptr,
HasPseudoFrames() ? kMallocEvent : "", thread_name); HasPseudoFrames() ? kMallocEvent : "", thread_name);
if (!result) { if (!result) {
LOG(ERROR) << "Failed to validate malloc fixed allocations"; LOG(ERROR) << "Failed to validate malloc fixed allocations";
......
...@@ -735,7 +735,8 @@ void InitAllocationRecorder(SenderPipe* sender_pipe, ...@@ -735,7 +735,8 @@ void InitAllocationRecorder(SenderPipe* sender_pipe,
break; break;
case mojom::StackMode::NATIVE_WITH_THREAD_NAMES: case mojom::StackMode::NATIVE_WITH_THREAD_NAMES:
case mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES: case mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES:
AllocationContextTracker::SetCaptureMode(CaptureMode::DISABLED); // This would track task contexts only.
AllocationContextTracker::SetCaptureMode(CaptureMode::NATIVE_STACK);
break; break;
} }
...@@ -791,7 +792,8 @@ void SerializeFramesFromAllocationContext(FrameSerializer* serializer, ...@@ -791,7 +792,8 @@ void SerializeFramesFromAllocationContext(FrameSerializer* serializer,
*context = allocation_context.type_name; *context = allocation_context.type_name;
} }
void SerializeFramesFromBacktrace(FrameSerializer* serializer) { void SerializeFramesFromBacktrace(FrameSerializer* serializer,
const char** context) {
// Skip 3 top frames related to the profiler itself, e.g.: // Skip 3 top frames related to the profiler itself, e.g.:
// base::debug::StackTrace::StackTrace // base::debug::StackTrace::StackTrace
// heap_profiling::RecordAndSendAlloc // heap_profiling::RecordAndSendAlloc
...@@ -824,6 +826,13 @@ void SerializeFramesFromBacktrace(FrameSerializer* serializer) { ...@@ -824,6 +826,13 @@ void SerializeFramesFromBacktrace(FrameSerializer* serializer) {
const char* thread_name = GetOrSetThreadName(); const char* thread_name = GetOrSetThreadName();
serializer->AddCString(thread_name); serializer->AddCString(thread_name);
} }
if (!*context) {
const auto* tracker =
AllocationContextTracker::GetInstanceForCurrentThread();
if (tracker)
*context = tracker->TaskContext();
}
} }
void AllocatorShimLogAlloc(AllocatorType type, void AllocatorShimLogAlloc(AllocatorType type,
...@@ -895,7 +904,7 @@ void RecordAndSendAlloc(AllocatorType type, ...@@ -895,7 +904,7 @@ void RecordAndSendAlloc(AllocatorType type,
capture_mode == CaptureMode::MIXED_STACK) { capture_mode == CaptureMode::MIXED_STACK) {
SerializeFramesFromAllocationContext(&serializer, &context); SerializeFramesFromAllocationContext(&serializer, &context);
} else { } else {
SerializeFramesFromBacktrace(&serializer); SerializeFramesFromBacktrace(&serializer, &context);
} }
size_t context_len = context ? strnlen(context, kMaxContextLen) : 0; size_t context_len = context ? strnlen(context, kMaxContextLen) : 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment