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) {
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.
if (!task_contexts_.empty()) {
ctx->type_name = task_contexts_.back();
} else {
ctx->type_name = nullptr;
}
ctx->type_name = TaskContext();
return true;
}
......
......@@ -108,6 +108,11 @@ class BASE_EXPORT AllocationContextTracker {
void PushCurrentTaskContext(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
// returns false if allocations are being ignored.
bool GetContextSnapshot(AllocationContext* snapshot);
......
......@@ -901,8 +901,7 @@ bool TestDriver::ValidateBrowserAllocations(base::Value* dump_json) {
if (IsRecordingAllAllocations()) {
if (should_validate_dumps) {
result = ValidateDump(heaps_v2, kMallocAllocSize * kMallocAllocCount,
kMallocAllocCount, "malloc",
HasPseudoFrames() ? kMallocTypeTag : nullptr,
kMallocAllocCount, "malloc", kMallocTypeTag,
HasPseudoFrames() ? kMallocEvent : "", thread_name);
if (!result) {
LOG(ERROR) << "Failed to validate malloc fixed allocations";
......
......@@ -735,7 +735,8 @@ void InitAllocationRecorder(SenderPipe* sender_pipe,
break;
case mojom::StackMode::NATIVE_WITH_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;
}
......@@ -791,7 +792,8 @@ void SerializeFramesFromAllocationContext(FrameSerializer* serializer,
*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.:
// base::debug::StackTrace::StackTrace
// heap_profiling::RecordAndSendAlloc
......@@ -824,6 +826,13 @@ void SerializeFramesFromBacktrace(FrameSerializer* serializer) {
const char* thread_name = GetOrSetThreadName();
serializer->AddCString(thread_name);
}
if (!*context) {
const auto* tracker =
AllocationContextTracker::GetInstanceForCurrentThread();
if (tracker)
*context = tracker->TaskContext();
}
}
void AllocatorShimLogAlloc(AllocatorType type,
......@@ -895,7 +904,7 @@ void RecordAndSendAlloc(AllocatorType type,
capture_mode == CaptureMode::MIXED_STACK) {
SerializeFramesFromAllocationContext(&serializer, &context);
} else {
SerializeFramesFromBacktrace(&serializer);
SerializeFramesFromBacktrace(&serializer, &context);
}
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