Commit 329b2bbd authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Add trace event for sampling profiler record stack

This CL is adding events to help investigate crbug 882982.
We are observing strange interaction with the SamplerThread and the
Browser main thread.

We suspect the thread to be suspended for a longer period than expected.

This code is temporary to investigate sampler profiling issues.
Should be reverted in a few weeks.

R=wittman@chromium.org, ssid@chromium.org

Bug: 882982
Change-Id: I4aa1d733ea06100c64e884e014222b04d97b3492
Reviewed-on: https://chromium-review.googlesource.com/1220174Reviewed-by: default avatarSiddhartha S <ssid@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590518}
parent 7650e6e1
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "base/sampling_heap_profiler/module_cache.h" #include "base/sampling_heap_profiler/module_cache.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h"
namespace base { namespace base {
...@@ -308,6 +309,8 @@ void SuspendThreadAndRecordStack( ...@@ -308,6 +309,8 @@ void SuspendThreadAndRecordStack(
const auto top = reinterpret_cast<uintptr_t>(base_address); const auto top = reinterpret_cast<uintptr_t>(base_address);
uintptr_t bottom = 0u; uintptr_t bottom = 0u;
{
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), "SuspendThread");
{ {
ScopedSuspendThread suspend_thread(thread_handle); ScopedSuspendThread suspend_thread(thread_handle);
...@@ -316,6 +319,7 @@ void SuspendThreadAndRecordStack( ...@@ -316,6 +319,7 @@ void SuspendThreadAndRecordStack(
if (!::GetThreadContext(thread_handle, &thread_context)) if (!::GetThreadContext(thread_handle, &thread_context))
return; return;
#if defined(_WIN64) #if defined(_WIN64)
bottom = thread_context.Rsp; bottom = thread_context.Rsp;
#else #else
...@@ -326,8 +330,8 @@ void SuspendThreadAndRecordStack( ...@@ -326,8 +330,8 @@ void SuspendThreadAndRecordStack(
return; return;
// Dereferencing a pointer in the guard page in a thread that doesn't own // Dereferencing a pointer in the guard page in a thread that doesn't own
// the stack results in a STATUS_GUARD_PAGE_VIOLATION exception and a crash. // the stack results in a STATUS_GUARD_PAGE_VIOLATION exception and a
// This occurs very rarely, but reliably over the population. // crash. This occurs very rarely, but reliably over the population.
if (PointsToGuardPage(bottom)) if (PointsToGuardPage(bottom))
return; return;
...@@ -336,13 +340,19 @@ void SuspendThreadAndRecordStack( ...@@ -336,13 +340,19 @@ void SuspendThreadAndRecordStack(
CopyMemoryFromStack(stack_copy_buffer, CopyMemoryFromStack(stack_copy_buffer,
reinterpret_cast<const void*>(bottom), top - bottom); reinterpret_cast<const void*>(bottom), top - bottom);
} }
}
if (test_delegate) if (test_delegate)
test_delegate->OnPreStackWalk(); test_delegate->OnPreStackWalk();
RewritePointersToStackMemory(top, bottom, &thread_context, stack_copy_buffer); {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), "RecordStack");
RewritePointersToStackMemory(top, bottom, &thread_context,
stack_copy_buffer);
RecordStack(&thread_context, stack); RecordStack(&thread_context, stack);
}
} }
} // namespace } // namespace
...@@ -395,6 +405,8 @@ void NativeStackSamplerWin::ProfileRecordingStarting() { ...@@ -395,6 +405,8 @@ void NativeStackSamplerWin::ProfileRecordingStarting() {
std::vector<Frame> NativeStackSamplerWin::RecordStackFrames( std::vector<Frame> NativeStackSamplerWin::RecordStackFrames(
StackBuffer* stack_buffer, StackBuffer* stack_buffer,
ProfileBuilder* profile_builder) { ProfileBuilder* profile_builder) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"NativeStackSamplerWin::RecordStackFrames");
DCHECK(stack_buffer); DCHECK(stack_buffer);
std::vector<RecordedFrame> stack; std::vector<RecordedFrame> stack;
...@@ -407,6 +419,9 @@ std::vector<Frame> NativeStackSamplerWin::RecordStackFrames( ...@@ -407,6 +419,9 @@ std::vector<Frame> NativeStackSamplerWin::RecordStackFrames(
std::vector<Frame> NativeStackSamplerWin::CreateFrames( std::vector<Frame> NativeStackSamplerWin::CreateFrames(
const std::vector<RecordedFrame>& stack) { const std::vector<RecordedFrame>& stack) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"NativeStackSamplerWin::CreateFrames");
std::vector<Frame> frames; std::vector<Frame> frames;
frames.reserve(stack.size()); frames.reserve(stack.size());
......
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