Index: base/profiler/stack_sampling_profiler.h |
diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h |
index 44387868310f87ca3a6fde6b3914130f1c3af025..8594ca404d9d11933326dbcf8ec729cef9f56f97 100644 |
--- a/base/profiler/stack_sampling_profiler.h |
+++ b/base/profiler/stack_sampling_profiler.h |
@@ -31,11 +31,12 @@ namespace base { |
// base::StackSamplingProfiler profiler(base::PlatformThread::CurrentId()), |
// params); |
// |
-// // To process the profiles within Chrome rather than via UMA, set a custom |
-// // completed callback: |
+// // Or, to process the profiles within Chrome rather than via UMA, use a |
+// // custom completed callback: |
// base::Callback<void(const std::vector<Profile>&)> |
// thread_safe_callback = ...; |
-// profiler.SetCustomCompletedCallback(thread_safe_callback); |
+// base::StackSamplingProfiler profiler(base::PlatformThread::CurrentId()), |
+// params, thread_safe_callback); |
// |
// profiler.Start(); |
// // ... work being done on the target thread here ... |
@@ -43,11 +44,10 @@ namespace base { |
// |
// When all profiles are complete or the profiler is stopped, if the custom |
// completed callback was set it will be called from the profiler thread with |
-// the completed profiles. If no callback was set, the profiles are stored |
-// internally and retrieved for UMA through |
-// GetPendingProfiles(). GetPendingProfiles() should never be called by other |
-// code; to retrieve profiles for in-process processing, set a completed |
-// callback. |
+// the completed profiles. Otherwise, the default completed callback will be |
+// called with the profiles. It is expected that the the default completed |
+// callback is set by the metrics system to allow profiles to be provided via |
+// UMA. |
class BASE_EXPORT StackSamplingProfiler { |
public: |
// Module represents the module (DLL or exe) corresponding to a stack frame. |
@@ -153,8 +153,17 @@ class BASE_EXPORT StackSamplingProfiler { |
bool preserve_sample_ordering; |
}; |
+ // Callback function that accepts completed profiles. |
+ using CompletedCallback = Callback<void(const std::vector<Profile>&)>; |
+ |
+ // Creates a profiler that sends completed profiles to the default completed |
+ // callback. |
StackSamplingProfiler(PlatformThreadId thread_id, |
const SamplingParams& params); |
+ // Creates a profiler that sends completed profiles to |completed_callback|. |
+ StackSamplingProfiler(PlatformThreadId thread_id, |
+ const SamplingParams& params, |
+ CompletedCallback callback); |
~StackSamplingProfiler(); |
// Initializes the profiler and starts sampling. |
@@ -164,19 +173,14 @@ class BASE_EXPORT StackSamplingProfiler { |
// bursts specified in the SamplingParams are completed. |
void Stop(); |
- // Gets the pending profiles into *|profiles| and clears the internal |
- // storage. This function is thread safe. |
+ // Sets a callback to process profiles collected by profiler instances without |
+ // a completed callback. Profiles are queued internally until a non-null |
+ // callback is provided to this function, |
// |
- // ***This is intended for use only by UMA.*** Callers who want to process the |
- // collected profiles should use SetCustomCompletedCallback. |
- static void GetPendingProfiles(std::vector<Profile>* profiles); |
- |
- // By default, collected profiles are stored internally and can be retrieved |
- // by GetPendingProfiles. If a callback is provided via this function, |
- // however, it will be called with the collected profiles instead. Note that |
- // this call to the callback occurs *on the profiler thread*. |
- void SetCustomCompletedCallback( |
- Callback<void(const std::vector<Profile>&)> callback); |
+ // The callback is typically called on a separate thread, so must be thread |
+ // safe. If completed profiles are queued when set, it will also be called |
+ // immediately on the calling thread. |
+ static void SetDefaultCompletedCallback(CompletedCallback callback); |
private: |
class SamplingThread; |
@@ -190,9 +194,8 @@ class BASE_EXPORT StackSamplingProfiler { |
const SamplingParams params_; |
scoped_ptr<SamplingThread, SamplingThreadDeleter> sampling_thread_; |
- scoped_ptr<NativeStackSampler> native_sampler_; |
- Callback<void(const std::vector<Profile>&)> custom_completed_callback_; |
+ const CompletedCallback completed_callback_; |
DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); |
}; |