Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1039)

Unified Diff: base/profiler/stack_sampling_profiler.h

Issue 1029653002: Enable startup profiling by Win x64 stack sampling profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@statprof-metrics-provider
Patch Set: restore AVeryLongTimeDelta Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/profiler/stack_sampling_profiler.cc » ('j') | chrome/browser/chrome_browser_main.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/profiler/stack_sampling_profiler.h
diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h
index 69c1c9a436cf1ae69c803b1cb9cf2a8ad8c1c579..279e132e9106dd65b72c98dc3ceb641503be30d5 100644
--- a/base/profiler/stack_sampling_profiler.h
+++ b/base/profiler/stack_sampling_profiler.h
@@ -34,11 +34,12 @@ class NativeStackSampler;
// base::StackSamplingProfiler profiler(base::PlatformThread::CurrentId()),
// params);
//
-// // To process the call stack 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::StackStackSamplingProfiler::CompletedCallback
// 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 ...
@@ -49,13 +50,13 @@ class NativeStackSampler;
// altered as desired.
//
// When all call stack profiles are complete or the profiler is stopped, if the
-// custom completed callback was set it is called from the profiler thread with
-// the completed profiles. A profile is considered complete if all requested
-// samples were recorded for the profile (i.e. it was not stopped
-// prematurely). If no callback was set, the completed 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.
+// custom completed callback was set it is called from a thread created by the
+// profiler with the completed profiles. A profile is considered complete if all
+// requested samples were recorded for the profile (i.e. it was not stopped
+// prematurely). If no callback was set, 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.
//
// The results of the profiling are passed to the completed callback and consist
// of a vector of CallStackProfiles. Each CallStackProfile corresponds to a
@@ -161,8 +162,14 @@ class BASE_EXPORT StackSamplingProfiler {
// set the callback, and thus the callback must be callable on any thread.
using CompletedCallback = Callback<void(const CallStackProfiles&)>;
+ // 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.
@@ -173,19 +180,14 @@ class BASE_EXPORT StackSamplingProfiler {
// specified in the SamplingParams are completed.
void Stop();
- // Moves all pending call stack profiles from internal storage to
- // |profiles|. 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(CallStackProfiles* call_stack_profiles);
-
- // By default, collected call stack profiles are stored internally and can be
- // retrieved by GetPendingProfiles. If a callback is provided via this
- // function, however, it is called with the collected profiles instead.
- void set_custom_completed_callback(CompletedCallback callback) {
- custom_completed_callback_ = callback;
- }
+ // The callback is typically called on a thread created by the profiler. If
+ // completed profiles are queued when set, however, it will also be called
+ // immediately on the calling thread.
+ static void SetDefaultCompletedCallback(CompletedCallback callback);
private:
// SamplingThread is a separate thread used to suspend and sample stacks from
@@ -223,7 +225,7 @@ class BASE_EXPORT StackSamplingProfiler {
// terminate before all the samples specified in |params_| are collected.
WaitableEvent stop_event_;
- CompletedCallback completed_callback_;
+ const CompletedCallback completed_callback_;
DISALLOW_COPY_AND_ASSIGN(SamplingThread);
};
@@ -234,8 +236,9 @@ class BASE_EXPORT StackSamplingProfiler {
const SamplingParams params_;
scoped_ptr<SamplingThread> sampling_thread_;
+ PlatformThreadHandle sampling_thread_handle_;
- CompletedCallback custom_completed_callback_;
+ const CompletedCallback completed_callback_;
DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler);
};
« no previous file with comments | « no previous file | base/profiler/stack_sampling_profiler.cc » ('j') | chrome/browser/chrome_browser_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698