OLD | NEW |
---|---|
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 // This class contains data structures that can be shared across multiple | |
25 // instances of NativeStackSampler so long as they do not run concurrently. | |
26 // This supports having a single instance of large structures such as copy | |
27 // buffers. | |
28 class StackBuffer { | |
Mike Wittman
2017/05/01 20:28:03
Following from the comment below, this can be simp
bcwhite
2017/05/08 14:00:59
If you want the generic base class header file to
Mike Wittman
2017/05/09 01:48:05
The abstraction should cover exactly the known sub
bcwhite
2017/05/09 18:33:33
Done.
| |
29 public: | |
30 virtual ~StackBuffer() {} | |
31 | |
32 protected: | |
33 StackBuffer() {} | |
34 | |
35 private: | |
36 DISALLOW_COPY_AND_ASSIGN(StackBuffer); | |
37 }; | |
38 | |
24 // The callback type used to add annotations to a sample during collection. | 39 // 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 | 40 // 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 | 41 // 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 | 42 // completely predictable and do nothing that could acquire a mutex; a |
28 // Callback object is code outside the control of this object and could, | 43 // 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 | 44 // for example, acquire a mutex as part of allocating memory for a LOG |
30 // message. | 45 // message. |
31 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*); | 46 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*); |
32 | 47 |
33 virtual ~NativeStackSampler(); | 48 virtual ~NativeStackSampler(); |
34 | 49 |
35 // Creates a stack sampler that records samples for |thread_handle|. Returns | 50 // Creates a stack sampler that records samples for |thread_handle|. Returns |
36 // null if this platform does not support stack sampling. | 51 // null if this platform does not support stack sampling. |
37 static std::unique_ptr<NativeStackSampler> Create( | 52 static std::unique_ptr<NativeStackSampler> Create( |
38 PlatformThreadId thread_id, | 53 PlatformThreadId thread_id, |
39 AnnotateCallback annotator, | 54 AnnotateCallback annotator, |
40 NativeStackSamplerTestDelegate* test_delegate); | 55 NativeStackSamplerTestDelegate* test_delegate); |
41 | 56 |
57 // Creates an instance of the necessary stack buffer. | |
58 static std::unique_ptr<StackBuffer> CreateStackBuffer(); | |
Mike Wittman
2017/05/01 20:28:03
From https://codereview.chromium.org/2848683006/di
Mike Wittman
2017/05/10 01:29:56
Please address this comment also.
bcwhite
2017/05/10 13:50:37
Done.
Mike Wittman
2017/05/10 17:17:21
I don't see this change in patch set 10.
bcwhite
2017/05/11 16:56:31
Done.
| |
59 | |
42 // The following functions are all called on the SamplingThread (not the | 60 // The following functions are all called on the SamplingThread (not the |
43 // thread being sampled). | 61 // thread being sampled). |
44 | 62 |
45 // Notifies the sampler that we're starting to record a new profile. Modules | 63 // Notifies the sampler that we're starting to record a new profile. Modules |
46 // shared across samples in the profile should be recorded in |modules|. | 64 // shared across samples in the profile should be recorded in |modules|. |
47 virtual void ProfileRecordingStarting( | 65 virtual void ProfileRecordingStarting( |
48 std::vector<StackSamplingProfiler::Module>* modules) = 0; | 66 std::vector<StackSamplingProfiler::Module>* modules) = 0; |
49 | 67 |
50 // Records a stack sample to |sample|. | 68 // Records a stack sample to |sample|. |
51 virtual void RecordStackSample(StackSamplingProfiler::Sample* sample) = 0; | 69 virtual void RecordStackSample(StackBuffer* stackbuffer, |
70 StackSamplingProfiler::Sample* sample) = 0; | |
52 | 71 |
53 // Notifies the sampler that we've stopped recording the current | 72 // Notifies the sampler that we've stopped recording the current |
54 // profile. | 73 // profile. |
55 virtual void ProfileRecordingStopped() = 0; | 74 virtual void ProfileRecordingStopped(StackBuffer* stackbuffer) = 0; |
56 | 75 |
57 protected: | 76 protected: |
58 NativeStackSampler(); | 77 NativeStackSampler(); |
59 | 78 |
60 private: | 79 private: |
61 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); | 80 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); |
62 }; | 81 }; |
63 | 82 |
64 // NativeStackSamplerTestDelegate provides seams for test code to execute during | 83 // NativeStackSamplerTestDelegate provides seams for test code to execute during |
65 // stack collection. | 84 // stack collection. |
66 class BASE_EXPORT NativeStackSamplerTestDelegate { | 85 class BASE_EXPORT NativeStackSamplerTestDelegate { |
67 public: | 86 public: |
68 virtual ~NativeStackSamplerTestDelegate(); | 87 virtual ~NativeStackSamplerTestDelegate(); |
69 | 88 |
70 // Called after copying the stack and resuming the target thread, but prior to | 89 // Called after copying the stack and resuming the target thread, but prior to |
71 // walking the stack. Invoked on the SamplingThread. | 90 // walking the stack. Invoked on the SamplingThread. |
72 virtual void OnPreStackWalk() = 0; | 91 virtual void OnPreStackWalk() = 0; |
73 | 92 |
74 protected: | 93 protected: |
75 NativeStackSamplerTestDelegate(); | 94 NativeStackSamplerTestDelegate(); |
76 | 95 |
77 private: | 96 private: |
78 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); | 97 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); |
79 }; | 98 }; |
80 | 99 |
81 } // namespace base | 100 } // namespace base |
82 | 101 |
83 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ | 102 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ |
84 | 103 |
OLD | NEW |