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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/base_export.h" | 14 #include "base/base_export.h" |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 | 24 |
25 class NativeStackSampler; | 25 class NativeStackSampler; |
26 class NativeStackSamplerTestDelegate; | 26 class NativeStackSamplerTestDelegate; |
27 | 27 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void Stop(); | 190 void Stop(); |
191 | 191 |
192 private: | 192 private: |
193 // SamplingThread is a separate thread used to suspend and sample stacks from | 193 // SamplingThread is a separate thread used to suspend and sample stacks from |
194 // the target thread. | 194 // the target thread. |
195 class SamplingThread : public PlatformThread::Delegate { | 195 class SamplingThread : public PlatformThread::Delegate { |
196 public: | 196 public: |
197 // Samples stacks using |native_sampler|. When complete, invokes | 197 // Samples stacks using |native_sampler|. When complete, invokes |
198 // |completed_callback| with the collected call stack profiles. | 198 // |completed_callback| with the collected call stack profiles. |
199 // |completed_callback| must be callable on any thread. | 199 // |completed_callback| must be callable on any thread. |
200 SamplingThread(scoped_ptr<NativeStackSampler> native_sampler, | 200 SamplingThread(std::unique_ptr<NativeStackSampler> native_sampler, |
201 const SamplingParams& params, | 201 const SamplingParams& params, |
202 const CompletedCallback& completed_callback); | 202 const CompletedCallback& completed_callback); |
203 ~SamplingThread() override; | 203 ~SamplingThread() override; |
204 | 204 |
205 // PlatformThread::Delegate: | 205 // PlatformThread::Delegate: |
206 void ThreadMain() override; | 206 void ThreadMain() override; |
207 | 207 |
208 void Stop(); | 208 void Stop(); |
209 | 209 |
210 private: | 210 private: |
211 // Collects |profile| from a single burst. If the profiler was stopped | 211 // Collects |profile| from a single burst. If the profiler was stopped |
212 // during collection, sets |was_stopped| and provides the set of samples | 212 // during collection, sets |was_stopped| and provides the set of samples |
213 // collected up to that point. | 213 // collected up to that point. |
214 void CollectProfile(CallStackProfile* profile, TimeDelta* elapsed_time, | 214 void CollectProfile(CallStackProfile* profile, TimeDelta* elapsed_time, |
215 bool* was_stopped); | 215 bool* was_stopped); |
216 | 216 |
217 // Collects call stack profiles from all bursts, or until the sampling is | 217 // Collects call stack profiles from all bursts, or until the sampling is |
218 // stopped. If stopped before complete, the last profile in | 218 // stopped. If stopped before complete, the last profile in |
219 // |call_stack_profiles| may contain a partial burst. | 219 // |call_stack_profiles| may contain a partial burst. |
220 void CollectProfiles(CallStackProfiles* profiles); | 220 void CollectProfiles(CallStackProfiles* profiles); |
221 | 221 |
222 scoped_ptr<NativeStackSampler> native_sampler_; | 222 std::unique_ptr<NativeStackSampler> native_sampler_; |
223 const SamplingParams params_; | 223 const SamplingParams params_; |
224 | 224 |
225 // If Stop() is called, it signals this event to force the sampling to | 225 // If Stop() is called, it signals this event to force the sampling to |
226 // terminate before all the samples specified in |params_| are collected. | 226 // terminate before all the samples specified in |params_| are collected. |
227 WaitableEvent stop_event_; | 227 WaitableEvent stop_event_; |
228 | 228 |
229 const CompletedCallback completed_callback_; | 229 const CompletedCallback completed_callback_; |
230 | 230 |
231 DISALLOW_COPY_AND_ASSIGN(SamplingThread); | 231 DISALLOW_COPY_AND_ASSIGN(SamplingThread); |
232 }; | 232 }; |
233 | 233 |
234 // The thread whose stack will be sampled. | 234 // The thread whose stack will be sampled. |
235 PlatformThreadId thread_id_; | 235 PlatformThreadId thread_id_; |
236 | 236 |
237 const SamplingParams params_; | 237 const SamplingParams params_; |
238 | 238 |
239 scoped_ptr<SamplingThread> sampling_thread_; | 239 std::unique_ptr<SamplingThread> sampling_thread_; |
240 PlatformThreadHandle sampling_thread_handle_; | 240 PlatformThreadHandle sampling_thread_handle_; |
241 | 241 |
242 const CompletedCallback completed_callback_; | 242 const CompletedCallback completed_callback_; |
243 | 243 |
244 // Stored until it can be passed to the NativeStackSampler created in Start(). | 244 // Stored until it can be passed to the NativeStackSampler created in Start(). |
245 NativeStackSamplerTestDelegate* const test_delegate_; | 245 NativeStackSamplerTestDelegate* const test_delegate_; |
246 | 246 |
247 DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); | 247 DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); |
248 }; | 248 }; |
249 | 249 |
250 // The metrics provider code wants to put Samples in a map and compare them, | 250 // The metrics provider code wants to put Samples in a map and compare them, |
251 // which requires us to define a few operators. | 251 // which requires us to define a few operators. |
252 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, | 252 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
253 const StackSamplingProfiler::Frame& b); | 253 const StackSamplingProfiler::Frame& b); |
254 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, | 254 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |
255 const StackSamplingProfiler::Frame& b); | 255 const StackSamplingProfiler::Frame& b); |
256 | 256 |
257 } // namespace base | 257 } // namespace base |
258 | 258 |
259 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 259 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
OLD | NEW |