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

Unified Diff: base/profiler/native_stack_sampler_win.cc

Issue 2444143002: Add process lifetime annotations to stack samples. (Closed)
Patch Set: addressed review comments and finished converting tests Created 4 years, 1 month 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/profiler/native_stack_sampler_win.cc
diff --git a/base/profiler/native_stack_sampler_win.cc b/base/profiler/native_stack_sampler_win.cc
index 063374f19d5b1edfd7d758d98e4047a1b8d67bd6..43e13fe28daa63e26eed73d50ee04a8bce899e60 100644
--- a/base/profiler/native_stack_sampler_win.cc
+++ b/base/profiler/native_stack_sampler_win.cc
@@ -319,6 +319,8 @@ void SuspendThreadAndRecordStack(
void* stack_copy_buffer,
size_t stack_copy_buffer_size,
std::vector<RecordedFrame>* stack,
+ NativeStackSampler::AnnotateCallback annotator,
+ StackSamplingProfiler::Sample* sample,
NativeStackSamplerTestDelegate* test_delegate) {
DCHECK(stack->empty());
@@ -353,6 +355,9 @@ void SuspendThreadAndRecordStack(
if (PointsToGuardPage(bottom))
return;
+ DCHECK(annotator);
+ (*annotator)(sample);
+
std::memcpy(stack_copy_buffer, reinterpret_cast<const void*>(bottom),
top - bottom);
}
@@ -370,6 +375,7 @@ void SuspendThreadAndRecordStack(
class NativeStackSamplerWin : public NativeStackSampler {
public:
NativeStackSamplerWin(win::ScopedHandle thread_handle,
+ AnnotateCallback annotator,
NativeStackSamplerTestDelegate* test_delegate);
~NativeStackSamplerWin() override;
@@ -408,6 +414,8 @@ class NativeStackSamplerWin : public NativeStackSampler {
win::ScopedHandle thread_handle_;
+ const AnnotateCallback annotator_;
+
NativeStackSamplerTestDelegate* const test_delegate_;
// The stack base address corresponding to |thread_handle_|.
@@ -430,11 +438,15 @@ class NativeStackSamplerWin : public NativeStackSampler {
NativeStackSamplerWin::NativeStackSamplerWin(
win::ScopedHandle thread_handle,
+ AnnotateCallback annotator,
NativeStackSamplerTestDelegate* test_delegate)
- : thread_handle_(thread_handle.Take()), test_delegate_(test_delegate),
+ : thread_handle_(thread_handle.Take()),
+ annotator_(annotator),
+ test_delegate_(test_delegate),
thread_stack_base_address_(
GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase),
stack_copy_buffer_(new unsigned char[kStackCopyBufferSize]) {
+ DCHECK(annotator_);
}
NativeStackSamplerWin::~NativeStackSamplerWin() {
@@ -456,7 +468,7 @@ void NativeStackSamplerWin::RecordStackSample(
std::vector<RecordedFrame> stack;
SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_,
stack_copy_buffer_.get(), kStackCopyBufferSize,
- &stack, test_delegate_);
+ &stack, annotator_, sample, test_delegate_);
CopyToSample(stack, sample, current_modules_);
}
@@ -508,11 +520,11 @@ void NativeStackSamplerWin::CopyToSample(
const std::vector<RecordedFrame>& stack,
StackSamplingProfiler::Sample* sample,
std::vector<StackSamplingProfiler::Module>* modules) {
- sample->clear();
- sample->reserve(stack.size());
+ sample->frames.clear();
+ sample->frames.reserve(stack.size());
for (const RecordedFrame& frame : stack) {
- sample->push_back(StackSamplingProfiler::Frame(
+ sample->frames.push_back(StackSamplingProfiler::Frame(
reinterpret_cast<uintptr_t>(frame.instruction_pointer),
GetModuleIndex(frame.module.Get(), modules)));
}
@@ -522,6 +534,7 @@ void NativeStackSamplerWin::CopyToSample(
std::unique_ptr<NativeStackSampler> NativeStackSampler::Create(
PlatformThreadId thread_id,
+ AnnotateCallback annotator,
NativeStackSamplerTestDelegate* test_delegate) {
#if _WIN64
// Get the thread's handle.
@@ -532,7 +545,7 @@ std::unique_ptr<NativeStackSampler> NativeStackSampler::Create(
if (thread_handle) {
return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin(
- win::ScopedHandle(thread_handle), test_delegate));
+ win::ScopedHandle(thread_handle), annotator, test_delegate));
}
#endif
return std::unique_ptr<NativeStackSampler>();

Powered by Google App Engine
This is Rietveld 408576698