Chromium Code Reviews| 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..9de4da3cbc45995e1b86a96298474755c95b62c1 100644 |
| --- a/base/profiler/native_stack_sampler_win.cc |
| +++ b/base/profiler/native_stack_sampler_win.cc |
| @@ -15,6 +15,7 @@ |
| #include <utility> |
| #include <vector> |
| +#include "base/bind.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| @@ -319,6 +320,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 +356,8 @@ void SuspendThreadAndRecordStack( |
| if (PointsToGuardPage(bottom)) |
| return; |
| + (*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_; |
| + AnnotateCallback annotator_; |
|
Mike Wittman
2016/11/02 17:14:38
const
bcwhite
2016/11/02 20:10:45
Done.
|
| + |
| NativeStackSamplerTestDelegate* const test_delegate_; |
| // The stack base address corresponding to |thread_handle_|. |
| @@ -430,8 +438,11 @@ 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]) { |
| @@ -456,7 +467,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 +519,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 +533,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 +544,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>(); |