1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_
6 #define CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_
11 #include "base/callback.h"
12 #include "content/common/content_export.h"
20 class TracingController
;
22 // TracingController is used on the browser processes to enable/disable
23 // trace status and collect trace data. Only the browser UI thread is allowed
24 // to interact with the TracingController object. All callbacks are called on
26 class TracingController
{
30 ENABLE_SYSTRACE
= 1 << 0,
31 ENABLE_SAMPLING
= 1 << 1,
32 RECORD_CONTINUOUSLY
= 1 << 2, // For EnableRecording() only.
35 CONTENT_EXPORT
static TracingController
* GetInstance();
37 // Get a set of category groups. The category groups can change as
38 // new code paths are reached.
40 // Once all child processes have acked to the GetCategories request,
41 // GetCategoriesDoneCallback is called back with a set of category
43 typedef base::Callback
<void(const std::set
<std::string
>&)>
44 GetCategoriesDoneCallback
;
45 virtual bool GetCategories(
46 const GetCategoriesDoneCallback
& callback
) = 0;
48 // Start recording on all processes.
50 // Recording begins immediately locally, and asynchronously on child processes
51 // as soon as they receive the EnableRecording request.
53 // Once all child processes have acked to the EnableRecording request,
54 // EnableRecordingDoneCallback will be called back.
56 // |category_filter| is a filter to control what category groups should be
57 // traced. A filter can have an optional '-' prefix to exclude category groups
58 // that contain a matching category. Having both included and excluded
59 // category patterns in the same list would not be supported.
61 // Examples: "test_MyTest*",
62 // "test_MyTest*,test_OtherStuff",
63 // "-excluded_category1,-excluded_category2"
65 // |options| controls what kind of tracing is enabled.
66 typedef base::Callback
<void()> EnableRecordingDoneCallback
;
67 virtual bool EnableRecording(
68 const std::string
& category_filter
,
69 TracingController::Options options
,
70 const EnableRecordingDoneCallback
& callback
) = 0;
72 // Stop recording on all processes.
74 // Child processes typically are caching trace data and only rarely flush
75 // and send trace data back to the browser process. That is because it may be
76 // an expensive operation to send the trace data over IPC, and we would like
77 // to avoid much runtime overhead of tracing. So, to end tracing, we must
78 // asynchronously ask all child processes to flush any pending trace data.
80 // Once all child processes have acked to the DisableRecording request,
81 // TracingFileResultCallback will be called back with a file that contains
84 // Trace data will be written into |result_file_path| if it is not empty, or
85 // into a temporary file. The actual file path will be passed to |callback| if
88 // If |result_file_path| is empty and |callback| is null, trace data won't be
89 // written to any file.
90 typedef base::Callback
<void(const base::FilePath
&)> TracingFileResultCallback
;
91 virtual bool DisableRecording(const base::FilePath
& result_file_path
,
92 const TracingFileResultCallback
& callback
) = 0;
94 // Start monitoring on all processes.
96 // Monitoring begins immediately locally, and asynchronously on child
97 // processes as soon as they receive the EnableMonitoring request.
99 // Once all child processes have acked to the EnableMonitoring request,
100 // EnableMonitoringDoneCallback will be called back.
102 // |category_filter| is a filter to control what category groups should be
105 // |options| controls what kind of tracing is enabled.
106 typedef base::Callback
<void()> EnableMonitoringDoneCallback
;
107 virtual bool EnableMonitoring(
108 const std::string
& category_filter
,
109 TracingController::Options options
,
110 const EnableMonitoringDoneCallback
& callback
) = 0;
112 // Stop monitoring on all processes.
114 // Once all child processes have acked to the DisableMonitoring request,
115 // DisableMonitoringDoneCallback is called back.
116 typedef base::Callback
<void()> DisableMonitoringDoneCallback
;
117 virtual bool DisableMonitoring(
118 const DisableMonitoringDoneCallback
& callback
) = 0;
120 // Get the current monitoring configuration.
121 virtual void GetMonitoringStatus(bool* out_enabled
,
122 std::string
* out_category_filter
,
123 TracingController::Options
* out_options
) = 0;
125 // Get the current monitoring traced data.
127 // Child processes typically are caching trace data and only rarely flush
128 // and send trace data back to the browser process. That is because it may be
129 // an expensive operation to send the trace data over IPC, and we would like
130 // to avoid much runtime overhead of tracing. So, to end tracing, we must
131 // asynchronously ask all child processes to flush any pending trace data.
133 // Once all child processes have acked to the CaptureMonitoringSnapshot
134 // request, TracingFileResultCallback will be called back with a file that
135 // contains the traced data.
137 // Trace data will be written into |result_file_path| if it is not empty, or
138 // into a temporary file. The actual file path will be passed to |callback|.
140 // If |result_file_path| is empty and |callback| is null, trace data won't be
141 // written to any file.
142 virtual bool CaptureMonitoringSnapshot(
143 const base::FilePath
& result_file_path
,
144 const TracingFileResultCallback
& callback
) = 0;
146 // Get the maximum across processes of trace buffer percent full state.
147 // When the TraceBufferPercentFull value is determined, the callback is
149 typedef base::Callback
<void(float)> GetTraceBufferPercentFullCallback
;
150 virtual bool GetTraceBufferPercentFull(
151 const GetTraceBufferPercentFullCallback
& callback
) = 0;
153 // |callback| will will be called every time the given event occurs on any
155 typedef base::Callback
<void()> WatchEventCallback
;
156 virtual bool SetWatchEvent(const std::string
& category_name
,
157 const std::string
& event_name
,
158 const WatchEventCallback
& callback
) = 0;
160 // Cancel the watch event. If tracing is enabled, this may race with the
161 // watch event callback.
162 virtual bool CancelWatchEvent() = 0;
165 virtual ~TracingController() {}
168 } // namespace content
170 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_