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 <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/atomicops.h" | 14 #include "base/atomicops.h" |
15 #include "base/base_export.h" | 15 #include "base/base_export.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/optional.h" |
19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
20 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 | 26 |
26 class NativeStackSampler; | 27 class NativeStackSampler; |
27 class NativeStackSamplerTestDelegate; | 28 class NativeStackSamplerTestDelegate; |
28 | 29 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // was started between when the idle-shutdown was initiated and when it | 209 // was started between when the idle-shutdown was initiated and when it |
209 // runs. | 210 // runs. |
210 static void PerformSamplingThreadIdleShutdown( | 211 static void PerformSamplingThreadIdleShutdown( |
211 bool simulate_intervening_start); | 212 bool simulate_intervening_start); |
212 }; | 213 }; |
213 | 214 |
214 // The callback type used to collect completed profiles. The passed |profiles| | 215 // The callback type used to collect completed profiles. The passed |profiles| |
215 // are move-only. Other threads, including the UI thread, may block on | 216 // are move-only. Other threads, including the UI thread, may block on |
216 // callback completion so this should run as quickly as possible. | 217 // callback completion so this should run as quickly as possible. |
217 // | 218 // |
| 219 // After collection completion, the callback may instruct the profiler to do |
| 220 // additional collection(s) by returning a SamplingParams object to indicate |
| 221 // collection should be started again. |
| 222 // |
218 // IMPORTANT NOTE: The callback is invoked on a thread the profiler | 223 // IMPORTANT NOTE: The callback is invoked on a thread the profiler |
219 // constructs, rather than on the thread used to construct the profiler and | 224 // constructs, rather than on the thread used to construct the profiler and |
220 // set the callback, and thus the callback must be callable on any thread. For | 225 // set the callback, and thus the callback must be callable on any thread. For |
221 // threads with message loops that create StackSamplingProfilers, posting a | 226 // threads with message loops that create StackSamplingProfilers, posting a |
222 // task to the message loop with the moved (i.e. std::move) profiles is the | 227 // task to the message loop with the moved (i.e. std::move) profiles is the |
223 // thread-safe callback implementation. | 228 // thread-safe callback implementation. |
224 using CompletedCallback = Callback<void(CallStackProfiles)>; | 229 using CompletedCallback = |
| 230 Callback<Optional<SamplingParams>(CallStackProfiles)>; |
225 | 231 |
226 // Creates a profiler for the CURRENT thread that sends completed profiles | 232 // Creates a profiler for the CURRENT thread that sends completed profiles |
227 // to |callback|. An optional |test_delegate| can be supplied by tests. | 233 // to |callback|. An optional |test_delegate| can be supplied by tests. |
228 // The caller must ensure that this object gets destroyed before the current | 234 // The caller must ensure that this object gets destroyed before the current |
229 // thread exits. | 235 // thread exits. |
230 StackSamplingProfiler( | 236 StackSamplingProfiler( |
231 const SamplingParams& params, | 237 const SamplingParams& params, |
232 const CompletedCallback& callback, | 238 const CompletedCallback& callback, |
233 NativeStackSamplerTestDelegate* test_delegate = nullptr); | 239 NativeStackSamplerTestDelegate* test_delegate = nullptr); |
234 | 240 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 const CompletedCallback completed_callback_; | 298 const CompletedCallback completed_callback_; |
293 | 299 |
294 // This starts "signaled", is reset when sampling begins, and is signaled | 300 // This starts "signaled", is reset when sampling begins, and is signaled |
295 // when that sampling is complete and the callback done. | 301 // when that sampling is complete and the callback done. |
296 WaitableEvent profiling_inactive_; | 302 WaitableEvent profiling_inactive_; |
297 | 303 |
298 // Object that does the native sampling. This is created during construction | 304 // Object that does the native sampling. This is created during construction |
299 // and later passed to the sampling thread when profiling is started. | 305 // and later passed to the sampling thread when profiling is started. |
300 std::unique_ptr<NativeStackSampler> native_sampler_; | 306 std::unique_ptr<NativeStackSampler> native_sampler_; |
301 | 307 |
302 // An ID uniquely identifying this collection to the sampling thread. This | 308 // An ID uniquely identifying this profiler to the sampling thread. This |
303 // will be an internal "null" value when no collection has been started. | 309 // will be an internal "null" value when no collection has been started. |
304 int collection_id_; | 310 int profiler_id_; |
305 | 311 |
306 // Stored until it can be passed to the NativeStackSampler created in Start(). | 312 // Stored until it can be passed to the NativeStackSampler created in Start(). |
307 NativeStackSamplerTestDelegate* const test_delegate_; | 313 NativeStackSamplerTestDelegate* const test_delegate_; |
308 | 314 |
309 DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); | 315 DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); |
310 }; | 316 }; |
311 | 317 |
312 // These operators permit types to be compared and used in a map of Samples, as | 318 // These operators permit types to be compared and used in a map of Samples, as |
313 // done in tests and by the metrics provider code. | 319 // done in tests and by the metrics provider code. |
314 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, | 320 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, |
315 const StackSamplingProfiler::Module& b); | 321 const StackSamplingProfiler::Module& b); |
316 BASE_EXPORT bool operator==(const StackSamplingProfiler::Sample& a, | 322 BASE_EXPORT bool operator==(const StackSamplingProfiler::Sample& a, |
317 const StackSamplingProfiler::Sample& b); | 323 const StackSamplingProfiler::Sample& b); |
318 BASE_EXPORT bool operator!=(const StackSamplingProfiler::Sample& a, | 324 BASE_EXPORT bool operator!=(const StackSamplingProfiler::Sample& a, |
319 const StackSamplingProfiler::Sample& b); | 325 const StackSamplingProfiler::Sample& b); |
320 BASE_EXPORT bool operator<(const StackSamplingProfiler::Sample& a, | 326 BASE_EXPORT bool operator<(const StackSamplingProfiler::Sample& a, |
321 const StackSamplingProfiler::Sample& b); | 327 const StackSamplingProfiler::Sample& b); |
322 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, | 328 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
323 const StackSamplingProfiler::Frame& b); | 329 const StackSamplingProfiler::Frame& b); |
324 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, | 330 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |
325 const StackSamplingProfiler::Frame& b); | 331 const StackSamplingProfiler::Frame& b); |
326 | 332 |
327 } // namespace base | 333 } // namespace base |
328 | 334 |
329 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 335 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
OLD | NEW |