Index: base/profiler/native_stack_sampler_mac.cc |
diff --git a/base/profiler/native_stack_sampler_mac.cc b/base/profiler/native_stack_sampler_mac.cc |
index dcaaa6febcaad06b9a292d81c2c0e592fe21d591..55a8199ec5b1df5e2192d47ca837c436410b699a 100644 |
--- a/base/profiler/native_stack_sampler_mac.cc |
+++ b/base/profiler/native_stack_sampler_mac.cc |
@@ -323,13 +323,15 @@ class NativeStackSamplerMac : 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: |
// Suspends the thread with |thread_port_|, copies its stack and resumes the |
// thread, then records the stack frames and associated modules into |sample|. |
- void SuspendThreadAndRecordStack(StackSamplingProfiler::Sample* sample); |
+ void SuspendThreadAndRecordStack(StackBuffer* stack_buffer, |
+ StackSamplingProfiler::Sample* sample); |
// Weak reference: Mach port for thread being profiled. |
mach_port_t thread_port_; |
@@ -341,13 +343,6 @@ class NativeStackSamplerMac : public NativeStackSampler { |
// The stack base address corresponding to |thread_handle_|. |
const void* const thread_stack_base_address_; |
- // The size of the |stack_copy_buffer_|. |
- const size_t stack_copy_buffer_size_; |
- |
- // 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_ = nullptr; |
@@ -367,9 +362,7 @@ NativeStackSamplerMac::NativeStackSamplerMac( |
annotator_(annotator), |
test_delegate_(test_delegate), |
thread_stack_base_address_( |
- pthread_get_stackaddr_np(pthread_from_mach_thread_np(thread_port))), |
- stack_copy_buffer_size_(StackCopyBufferSize()), |
- stack_copy_buffer_(new unsigned char[stack_copy_buffer_size_]) { |
+ pthread_get_stackaddr_np(pthread_from_mach_thread_np(thread_port))) { |
DCHECK(annotator_); |
// This class suspends threads, and those threads might be suspended in dyld. |
@@ -389,17 +382,19 @@ void NativeStackSamplerMac::ProfileRecordingStarting( |
} |
void NativeStackSamplerMac::RecordStackSample( |
+ StackBuffer* stack_buffer, |
StackSamplingProfiler::Sample* sample) { |
DCHECK(current_modules_); |
- SuspendThreadAndRecordStack(sample); |
+ SuspendThreadAndRecordStack(stack_buffer, sample); |
} |
-void NativeStackSamplerMac::ProfileRecordingStopped() { |
+void NativeStackSamplerMac::ProfileRecordingStopped(StackBuffer* stack_buffer) { |
current_modules_ = nullptr; |
} |
void NativeStackSamplerMac::SuspendThreadAndRecordStack( |
+ StackBuffer* stack_buffer, |
StackSamplingProfiler::Sample* sample) { |
x86_thread_state64_t thread_state; |
@@ -424,18 +419,18 @@ void NativeStackSamplerMac::SuspendThreadAndRecordStack( |
return; |
uintptr_t stack_size = stack_top - stack_bottom; |
- if (stack_size > stack_copy_buffer_size_) |
+ if (stack_size > stack_buffer->size()) |
return; |
(*annotator_)(sample); |
CopyStackAndRewritePointers( |
- reinterpret_cast<uintptr_t*>(stack_copy_buffer_.get()), |
+ reinterpret_cast<uintptr_t*>(stack_buffer->buffer()), |
reinterpret_cast<uintptr_t*>(stack_bottom), |
reinterpret_cast<uintptr_t*>(stack_top), &thread_state); |
new_stack_top = |
- reinterpret_cast<uintptr_t>(stack_copy_buffer_.get()) + stack_size; |
+ reinterpret_cast<uintptr_t>(stack_buffer->buffer()) + stack_size; |
} // ScopedSuspendThread |
if (test_delegate_) |
@@ -468,4 +463,9 @@ std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( |
test_delegate); |
} |
+std::unique_ptr<NativeStackSampler::StackBuffer> |
+NativeStackSampler::CreateStackBuffer() { |
+ return MakeUnique<StackBuffer>(StackCopyBufferSize()); |
+} |
+ |
} // namespace base |