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

Side by Side Diff: base/profiler/native_stack_sampler.h

Issue 2554123002: Support parallel captures from the StackSamplingProfiler. (Closed)
Patch Set: merged synchronized-stop CL Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 5 #ifndef BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
6 #define BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 6 #define BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/profiler/stack_sampling_profiler.h" 12 #include "base/profiler/stack_sampling_profiler.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 class NativeStackSamplerTestDelegate; 17 class NativeStackSamplerTestDelegate;
18 18
19 // NativeStackSampler is an implementation detail of StackSamplingProfiler. It 19 // NativeStackSampler is an implementation detail of StackSamplingProfiler. It
20 // abstracts the native implementation required to record a stack sample for a 20 // abstracts the native implementation required to record a stack sample for a
21 // given thread. 21 // given thread.
22 class NativeStackSampler { 22 class NativeStackSampler {
23 public: 23 public:
24 // The thread state as determined by the sampler during it's last attempt.
Mike Wittman 2017/02/13 22:35:57 All changes in this file and native_stack_sampler_
bcwhite 2017/02/14 14:33:01 Done.
25 enum ThreadState {
26 THREAD_UNCHECKED,
27 THREAD_RUNNING,
28 THREAD_EXITED,
29 THREAD_UNSUSPENDABLE,
30 THREAD_NO_INFO,
31 THREAD_STACK_TOO_BIG,
32 THREAD_INACCESSIBLE,
33 };
34
24 // The callback type used to add annotations to a sample during collection. 35 // The callback type used to add annotations to a sample during collection.
25 // This is passed to the native sampler to be applied at the most appropriate 36 // This is passed to the native sampler to be applied at the most appropriate
26 // time. It is a simple function-pointer because the generated code must be 37 // time. It is a simple function-pointer because the generated code must be
27 // completely predictable and do nothing that could acquire a mutex; a 38 // completely predictable and do nothing that could acquire a mutex; a
28 // Callback object is code outside the control of this object and could, 39 // Callback object is code outside the control of this object and could,
29 // for example, acquire a mutex as part of allocating memory for a LOG 40 // for example, acquire a mutex as part of allocating memory for a LOG
30 // message. 41 // message.
31 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*); 42 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*);
32 43
33 virtual ~NativeStackSampler(); 44 virtual ~NativeStackSampler();
(...skipping 13 matching lines...) Expand all
47 virtual void ProfileRecordingStarting( 58 virtual void ProfileRecordingStarting(
48 std::vector<StackSamplingProfiler::Module>* modules) = 0; 59 std::vector<StackSamplingProfiler::Module>* modules) = 0;
49 60
50 // Records a stack sample to |sample|. 61 // Records a stack sample to |sample|.
51 virtual void RecordStackSample(StackSamplingProfiler::Sample* sample) = 0; 62 virtual void RecordStackSample(StackSamplingProfiler::Sample* sample) = 0;
52 63
53 // Notifies the sampler that we've stopped recording the current 64 // Notifies the sampler that we've stopped recording the current
54 // profile. 65 // profile.
55 virtual void ProfileRecordingStopped() = 0; 66 virtual void ProfileRecordingStopped() = 0;
56 67
68 // Gets the last-known thread state.
69 ThreadState thread_state() { return thread_state_; }
70
57 protected: 71 protected:
58 NativeStackSampler(); 72 NativeStackSampler();
59 73
74 void set_thread_state(ThreadState state) { thread_state_ = state; }
75
60 private: 76 private:
77 ThreadState thread_state_ = THREAD_UNCHECKED;
78
61 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); 79 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler);
62 }; 80 };
63 81
64 // NativeStackSamplerTestDelegate provides seams for test code to execute during 82 // NativeStackSamplerTestDelegate provides seams for test code to execute during
65 // stack collection. 83 // stack collection.
66 class BASE_EXPORT NativeStackSamplerTestDelegate { 84 class BASE_EXPORT NativeStackSamplerTestDelegate {
67 public: 85 public:
68 virtual ~NativeStackSamplerTestDelegate(); 86 virtual ~NativeStackSamplerTestDelegate();
69 87
70 // Called after copying the stack and resuming the target thread, but prior to 88 // Called after copying the stack and resuming the target thread, but prior to
71 // walking the stack. Invoked on the SamplingThread. 89 // walking the stack. Invoked on the SamplingThread.
72 virtual void OnPreStackWalk() = 0; 90 virtual void OnPreStackWalk(){};
91
92 // Called after the sampling is complete.
93 virtual void OnPostRecordSample(NativeStackSampler::ThreadState state){};
73 94
74 protected: 95 protected:
75 NativeStackSamplerTestDelegate(); 96 NativeStackSamplerTestDelegate();
76 97
77 private: 98 private:
78 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); 99 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate);
79 }; 100 };
80 101
81 } // namespace base 102 } // namespace base
82 103
83 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 104 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
84 105
OLDNEW
« no previous file with comments | « no previous file | base/profiler/native_stack_sampler_win.cc » ('j') | base/profiler/stack_sampling_profiler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698