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

Unified Diff: base/profiler/native_stack_sampler_win.cc

Issue 2444143002: Add process lifetime annotations to stack samples. (Closed)
Patch Set: addressed review comments by wittman Created 4 years, 2 months 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..1a3f2520d6be1d9986d932b923cca9ecf211f5de 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,7 @@ void SuspendThreadAndRecordStack(
void* stack_copy_buffer,
size_t stack_copy_buffer_size,
std::vector<RecordedFrame>* stack,
+ Closure annotator,
NativeStackSamplerTestDelegate* test_delegate) {
DCHECK(stack->empty());
@@ -353,6 +355,8 @@ void SuspendThreadAndRecordStack(
if (PointsToGuardPage(bottom))
return;
+ annotator.Run();
Mike Wittman 2016/10/26 16:28:17 Invoking Callback::Run while the thread is suspend
bcwhite 2016/10/26 18:30:43 Good point. We can document this code to say what
Mike Wittman 2016/10/26 19:41:14 That would work, but it would couple the implement
bcwhite 2016/10/26 20:02:10 It might be possible to just make it testable via
Mike Wittman 2016/10/26 20:20:36 That's reasonable, although I feel like this may b
+
std::memcpy(stack_copy_buffer, reinterpret_cast<const void*>(bottom),
top - bottom);
}
@@ -370,6 +374,7 @@ void SuspendThreadAndRecordStack(
class NativeStackSamplerWin : public NativeStackSampler {
public:
NativeStackSamplerWin(win::ScopedHandle thread_handle,
+ StackSamplingProfiler::AnnotateCallback annotator,
NativeStackSamplerTestDelegate* test_delegate);
~NativeStackSamplerWin() override;
@@ -408,6 +413,8 @@ class NativeStackSamplerWin : public NativeStackSampler {
win::ScopedHandle thread_handle_;
+ StackSamplingProfiler::AnnotateCallback annotator_;
+
NativeStackSamplerTestDelegate* const test_delegate_;
// The stack base address corresponding to |thread_handle_|.
@@ -430,8 +437,11 @@ class NativeStackSamplerWin : public NativeStackSampler {
NativeStackSamplerWin::NativeStackSamplerWin(
win::ScopedHandle thread_handle,
+ StackSamplingProfiler::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 +466,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, Bind(annotator_, sample), test_delegate_);
CopyToSample(stack, sample, current_modules_);
}
@@ -508,11 +518,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 +532,7 @@ void NativeStackSamplerWin::CopyToSample(
std::unique_ptr<NativeStackSampler> NativeStackSampler::Create(
PlatformThreadId thread_id,
+ StackSamplingProfiler::AnnotateCallback annotator,
NativeStackSamplerTestDelegate* test_delegate) {
#if _WIN64
// Get the thread's handle.
@@ -532,7 +543,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