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_STACK_SAMPLING_PROFILER_H_ | 5 #ifndef BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
6 #define BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 6 #define BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // profiler.Start(); | 44 // profiler.Start(); |
45 // // ... work being done on the target thread here ... | 45 // // ... work being done on the target thread here ... |
46 // profiler.Stop(); // optional, stops collection before complete per params | 46 // profiler.Stop(); // optional, stops collection before complete per params |
47 // | 47 // |
48 // The default SamplingParams causes stacks to be recorded in a single burst at | 48 // The default SamplingParams causes stacks to be recorded in a single burst at |
49 // a 10Hz interval for a total of 30 seconds. All of these parameters may be | 49 // a 10Hz interval for a total of 30 seconds. All of these parameters may be |
50 // altered as desired. | 50 // altered as desired. |
51 // | 51 // |
52 // When all call stack profiles are complete, or the profiler is stopped, the | 52 // When all call stack profiles are complete, or the profiler is stopped, the |
53 // completed callback is called from a thread created by the profiler with the | 53 // completed callback is called from a thread created by the profiler with the |
54 // completed profiles. A profile is considered complete if all requested samples | 54 // collected profiles. |
55 // were recorded for the profile (i.e. it was not stopped prematurely). | |
56 // | 55 // |
57 // The results of the profiling are passed to the completed callback and consist | 56 // The results of the profiling are passed to the completed callback and consist |
58 // of a vector of CallStackProfiles. Each CallStackProfile corresponds to a | 57 // of a vector of CallStackProfiles. Each CallStackProfile corresponds to a |
59 // burst as specified in SamplingParams and contains a set of Samples and | 58 // burst as specified in SamplingParams and contains a set of Samples and |
60 // Modules. One Sample corresponds to a single recorded stack, and the Modules | 59 // Modules. One Sample corresponds to a single recorded stack, and the Modules |
61 // record those modules associated with the recorded stack frames. | 60 // record those modules associated with the recorded stack frames. |
62 class BASE_EXPORT StackSamplingProfiler { | 61 class BASE_EXPORT StackSamplingProfiler { |
63 public: | 62 public: |
64 // Module represents the module (DLL or exe) corresponding to a stack frame. | 63 // Module represents the module (DLL or exe) corresponding to a stack frame. |
65 struct BASE_EXPORT Module { | 64 struct BASE_EXPORT Module { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 const SamplingParams& params, | 187 const SamplingParams& params, |
189 const CompletedCallback& completed_callback); | 188 const CompletedCallback& completed_callback); |
190 ~SamplingThread() override; | 189 ~SamplingThread() override; |
191 | 190 |
192 // PlatformThread::Delegate: | 191 // PlatformThread::Delegate: |
193 void ThreadMain() override; | 192 void ThreadMain() override; |
194 | 193 |
195 void Stop(); | 194 void Stop(); |
196 | 195 |
197 private: | 196 private: |
198 // Collects a call stack profile from a single burst. Returns true if the | 197 // Collects |profile| from a single burst. If the profiler was stopped |
199 // profile was collected, or false if collection was stopped before it | 198 // during collection, sets |was_stopped| and provides the set of samples |
200 // completed. | 199 // collected up to that point. |
201 bool CollectProfile(CallStackProfile* profile, TimeDelta* elapsed_time); | 200 void CollectProfile(CallStackProfile* profile, |
| 201 TimeDelta* elapsed_time, |
| 202 bool* was_stopped); |
202 | 203 |
203 // Collects call stack profiles from all bursts, or until the sampling is | 204 // Collects call stack profiles from all bursts, or until the sampling is |
204 // stopped. If stopped before complete, |call_stack_profiles| will contain | 205 // stopped. If stopped before complete, the last profile in |
205 // only full bursts. | 206 // |call_stack_profiles| may contain a partial burst. |
206 void CollectProfiles(CallStackProfiles* profiles); | 207 void CollectProfiles(CallStackProfiles* profiles); |
207 | 208 |
208 scoped_ptr<NativeStackSampler> native_sampler_; | 209 scoped_ptr<NativeStackSampler> native_sampler_; |
209 const SamplingParams params_; | 210 const SamplingParams params_; |
210 | 211 |
211 // If Stop() is called, it signals this event to force the sampling to | 212 // If Stop() is called, it signals this event to force the sampling to |
212 // terminate before all the samples specified in |params_| are collected. | 213 // terminate before all the samples specified in |params_| are collected. |
213 WaitableEvent stop_event_; | 214 WaitableEvent stop_event_; |
214 | 215 |
215 const CompletedCallback completed_callback_; | 216 const CompletedCallback completed_callback_; |
(...skipping 17 matching lines...) Expand all Loading... |
233 // The metrics provider code wants to put Samples in a map and compare them, | 234 // The metrics provider code wants to put Samples in a map and compare them, |
234 // which requires us to define a few operators. | 235 // which requires us to define a few operators. |
235 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, | 236 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
236 const StackSamplingProfiler::Frame& b); | 237 const StackSamplingProfiler::Frame& b); |
237 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, | 238 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |
238 const StackSamplingProfiler::Frame& b); | 239 const StackSamplingProfiler::Frame& b); |
239 | 240 |
240 } // namespace base | 241 } // namespace base |
241 | 242 |
242 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 243 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
OLD | NEW |