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 d320fea98a1cc778fe69d6d519d056a00d308820..69bbefb3047c45e58f01cabfc7a32891cc1229da 100644 |
--- a/base/profiler/native_stack_sampler_win.cc |
+++ b/base/profiler/native_stack_sampler_win.cc |
@@ -18,6 +18,7 @@ |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/memory/ptr_util.h" |
#include "base/profiler/win32_stack_frame_unwinder.h" |
#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
@@ -386,6 +387,13 @@ void SuspendThreadAndRecordStack( |
class NativeStackSamplerWin : public NativeStackSampler { |
public: |
+ // Intended to hold the largest stack used by Chrome. The default Win32 |
+ // reserved stack size is 1 MB and Chrome Windows threads currently always |
+ // use the default, but this allows for expansion if it occurs. The size |
+ // beyond the actual stack size consists of unallocated virtual memory pages |
+ // so carries little cost (just a bit of wasted address space). |
+ static constexpr size_t kStackCopyBufferSize = 2 * 1024 * 1024; |
Mike Wittman
2017/05/10 17:17:21
This can be moved back into the private section.
bcwhite
2017/05/11 16:56:31
It has to be public to be accessible to NativeStac
Mike Wittman
2017/05/11 21:07:02
Ah, right.
Since it's only used by NativeStackSam
bcwhite
2017/05/12 13:11:29
Done.
|
+ |
NativeStackSamplerWin(win::ScopedHandle thread_handle, |
AnnotateCallback annotator, |
NativeStackSamplerTestDelegate* test_delegate); |
@@ -394,17 +402,11 @@ class NativeStackSamplerWin : public NativeStackSampler { |
// StackSamplingProfiler::NativeStackSampler: |
void ProfileRecordingStarting( |
std::vector<StackSamplingProfiler::Module>* modules) override; |
- void RecordStackSample(StackSamplingProfiler::Sample* sample) override; |
- void ProfileRecordingStopped() override; |
+ void RecordStackSample(StackBuffer* stack_buffer, |
+ StackSamplingProfiler::Sample* sample) override; |
+ void ProfileRecordingStopped(StackBuffer* stack_buffer) override; |
private: |
- // Intended to hold the largest stack used by Chrome. The default Win32 |
- // reserved stack size is 1 MB and Chrome Windows threads currently always |
- // use the default, but this allows for expansion if it occurs. The size |
- // beyond the actual stack size consists of unallocated virtual memory pages |
- // so carries little cost (just a bit of wasted address space). |
- static constexpr size_t kStackCopyBufferSize = 2 * 1024 * 1024; |
- |
// Attempts to query the module filename, base address, and id for |
// |module_handle|, and store them in |module|. Returns true if it succeeded. |
static bool GetModuleForHandle(HMODULE module_handle, |
@@ -431,10 +433,6 @@ class NativeStackSamplerWin : public NativeStackSampler { |
// The stack base address corresponding to |thread_handle_|. |
const void* const thread_stack_base_address_; |
- // Buffer to use for copies of the stack. We use the same buffer for all the |
- // samples to avoid the overhead of multiple allocations and frees. |
- const std::unique_ptr<unsigned char[]> stack_copy_buffer_; |
- |
// Weak. Points to the modules associated with the profile being recorded |
// between ProfileRecordingStarting() and ProfileRecordingStopped(). |
std::vector<StackSamplingProfiler::Module>* current_modules_; |
@@ -454,8 +452,7 @@ NativeStackSamplerWin::NativeStackSamplerWin( |
annotator_(annotator), |
test_delegate_(test_delegate), |
thread_stack_base_address_( |
- GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase), |
- stack_copy_buffer_(new unsigned char[kStackCopyBufferSize]) { |
+ GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase) { |
DCHECK(annotator_); |
} |
@@ -469,17 +466,19 @@ void NativeStackSamplerWin::ProfileRecordingStarting( |
} |
void NativeStackSamplerWin::RecordStackSample( |
+ StackBuffer* stack_buffer, |
StackSamplingProfiler::Sample* sample) { |
+ DCHECK(stack_buffer); |
DCHECK(current_modules_); |
std::vector<RecordedFrame> stack; |
SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_, |
- stack_copy_buffer_.get(), kStackCopyBufferSize, |
+ stack_buffer->buffer(), stack_buffer->size(), |
&stack, annotator_, sample, test_delegate_); |
CopyToSample(stack, sample, current_modules_); |
} |
-void NativeStackSamplerWin::ProfileRecordingStopped() { |
+void NativeStackSamplerWin::ProfileRecordingStopped(StackBuffer* stack_buffer) { |
current_modules_ = nullptr; |
} |
@@ -558,4 +557,9 @@ std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( |
return std::unique_ptr<NativeStackSampler>(); |
} |
+std::unique_ptr<NativeStackSampler::StackBuffer> |
+NativeStackSampler::CreateStackBuffer() { |
+ return MakeUnique<StackBuffer>(NativeStackSamplerWin::kStackCopyBufferSize); |
+} |
+ |
} // namespace base |