OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | |
10 | 9 |
11 #include "base/callback.h" | 10 #include "base/debug/trace_event.h" |
12 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 class FilePath; | 14 class FilePath; |
16 }; | 15 }; |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 | 18 |
20 class TracingController; | 19 class TracingController; |
21 | 20 |
22 // TracingController is used on the browser processes to enable/disable | 21 // TracingController is used on the browser processes to enable/disable |
23 // trace status and collect trace data. Only the browser UI thread is allowed | 22 // 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 | 23 // to interact with the TracingController object. All callbacks are called on |
25 // the UI thread. | 24 // the UI thread. |
26 class TracingController { | 25 class TracingController { |
27 public: | 26 public: |
28 enum Options { | 27 enum Options { |
29 DEFAULT_OPTIONS = 0, | |
30 ENABLE_SYSTRACE = 1 << 0, | 28 ENABLE_SYSTRACE = 1 << 0, |
31 ENABLE_SAMPLING = 1 << 1, | 29 ENABLE_SAMPLING = 1 << 1, |
32 RECORD_CONTINUOUSLY = 1 << 2, // For EnableRecording() only. | 30 RECORD_CONTINUOUSLY = 1 << 2, // For EnableRecording() only. |
33 }; | 31 }; |
34 | 32 |
35 CONTENT_EXPORT static TracingController* GetInstance(); | 33 CONTENT_EXPORT static TracingController* GetInstance(); |
36 | 34 |
37 // Get a set of category groups. The category groups can change as | 35 // Get a set of category groups. The category groups can change as |
38 // new code paths are reached. | 36 // new code paths are reached. |
39 // | 37 // |
40 // Once all child processes have acked to the GetCategories request, | 38 // Once all child processes have acked to the GetCategories request, |
41 // GetCategoriesDoneCallback is called back with a set of category | 39 // GetCategoriesDoneCallback is called back with a set of category |
42 // groups. | 40 // groups. |
43 typedef base::Callback<void(const std::set<std::string>&)> | 41 typedef base::Callback<void(const std::set<std::string>&)> |
44 GetCategoriesDoneCallback; | 42 GetCategoriesDoneCallback; |
45 virtual bool GetCategories( | 43 virtual void GetCategories( |
46 const GetCategoriesDoneCallback& callback) = 0; | 44 const GetCategoriesDoneCallback& callback) = 0; |
47 | 45 |
48 // Start recording on all processes. | 46 // Start recording on all processes. |
49 // | 47 // |
50 // Recording begins immediately locally, and asynchronously on child processes | 48 // Recording begins immediately locally, and asynchronously on child processes |
51 // as soon as they receive the EnableRecording request. | 49 // as soon as they receive the EnableRecording request. |
52 // | 50 // |
53 // Once all child processes have acked to the EnableRecording request, | 51 // Once all child processes have acked to the EnableRecording request, |
54 // EnableRecordingDoneCallback will be called back. | 52 // EnableRecordingDoneCallback will be called back. |
55 // | 53 // |
56 // |category_filter| is a filter to control what category groups should be | 54 // |filter| is a filter to control what category groups should be traced. |
57 // traced. A filter can have an optional '-' prefix to exclude category groups | 55 // A filter can have an optional '-' prefix to exclude category groups |
58 // that contain a matching category. Having both included and excluded | 56 // that contain a matching category. Having both included and excluded |
59 // category patterns in the same list would not be supported. | 57 // category patterns in the same list would not be supported. |
60 // | 58 // |
61 // Examples: "test_MyTest*", | 59 // Examples: "test_MyTest*", |
62 // "test_MyTest*,test_OtherStuff", | 60 // "test_MyTest*,test_OtherStuff", |
63 // "-excluded_category1,-excluded_category2" | 61 // "-excluded_category1,-excluded_category2" |
64 // | 62 // |
65 // |options| controls what kind of tracing is enabled. | 63 // |options| controls what kind of tracing is enabled. |
66 typedef base::Callback<void()> EnableRecordingDoneCallback; | 64 typedef base::Callback<void()> EnableRecordingDoneCallback; |
67 virtual bool EnableRecording( | 65 virtual bool EnableRecording( |
68 const std::string& category_filter, | 66 const base::debug::CategoryFilter& filter, |
69 TracingController::Options options, | 67 TracingController::Options options, |
70 const EnableRecordingDoneCallback& callback) = 0; | 68 const EnableRecordingDoneCallback& callback) = 0; |
71 | 69 |
72 // Stop recording on all processes. | 70 // Stop recording on all processes. |
73 // | 71 // |
74 // Child processes typically are caching trace data and only rarely flush | 72 // 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 | 73 // 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 | 74 // 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 | 75 // 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. | 76 // asynchronously ask all child processes to flush any pending trace data. |
(...skipping 13 matching lines...) Expand all Loading... |
92 const TracingFileResultCallback& callback) = 0; | 90 const TracingFileResultCallback& callback) = 0; |
93 | 91 |
94 // Start monitoring on all processes. | 92 // Start monitoring on all processes. |
95 // | 93 // |
96 // Monitoring begins immediately locally, and asynchronously on child | 94 // Monitoring begins immediately locally, and asynchronously on child |
97 // processes as soon as they receive the EnableMonitoring request. | 95 // processes as soon as they receive the EnableMonitoring request. |
98 // | 96 // |
99 // Once all child processes have acked to the EnableMonitoring request, | 97 // Once all child processes have acked to the EnableMonitoring request, |
100 // EnableMonitoringDoneCallback will be called back. | 98 // EnableMonitoringDoneCallback will be called back. |
101 // | 99 // |
102 // |category_filter| is a filter to control what category groups should be | 100 // |filter| is a filter to control what category groups should be traced. |
103 // traced. | |
104 // | 101 // |
105 // |options| controls what kind of tracing is enabled. | 102 // |options| controls what kind of tracing is enabled. |
106 typedef base::Callback<void()> EnableMonitoringDoneCallback; | 103 typedef base::Callback<void()> EnableMonitoringDoneCallback; |
107 virtual bool EnableMonitoring( | 104 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, |
108 const std::string& category_filter, | |
109 TracingController::Options options, | 105 TracingController::Options options, |
110 const EnableMonitoringDoneCallback& callback) = 0; | 106 const EnableMonitoringDoneCallback& callback) = 0; |
111 | 107 |
112 // Stop monitoring on all processes. | 108 // Stop monitoring on all processes. |
113 // | 109 // |
114 // Once all child processes have acked to the DisableMonitoring request, | 110 // Once all child processes have acked to the DisableMonitoring request, |
115 // DisableMonitoringDoneCallback is called back. | 111 // DisableMonitoringDoneCallback is called back. |
116 typedef base::Callback<void()> DisableMonitoringDoneCallback; | 112 typedef base::Callback<void()> DisableMonitoringDoneCallback; |
117 virtual bool DisableMonitoring( | 113 virtual bool DisableMonitoring( |
118 const DisableMonitoringDoneCallback& callback) = 0; | 114 const DisableMonitoringDoneCallback& callback) = 0; |
119 | 115 |
120 // Get the current monitoring configuration. | 116 // Get the current monitoring configuration. |
121 virtual void GetMonitoringStatus(bool* out_enabled, | 117 virtual void GetMonitoringStatus(bool* out_enabled, |
122 std::string* out_category_filter, | 118 base::debug::CategoryFilter* out_filter, |
123 TracingController::Options* out_options) = 0; | 119 TracingController::Options* out_options) = 0; |
124 | 120 |
125 // Get the current monitoring traced data. | 121 // Get the current monitoring traced data. |
126 // | 122 // |
127 // Child processes typically are caching trace data and only rarely flush | 123 // 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 | 124 // 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 | 125 // 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 | 126 // 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. | 127 // asynchronously ask all child processes to flush any pending trace data. |
132 // | 128 // |
133 // Once all child processes have acked to the CaptureMonitoringSnapshot | 129 // Once all child processes have acked to the CaptureMonitoringSnapshot |
134 // request, TracingFileResultCallback will be called back with a file that | 130 // request, TracingFileResultCallback will be called back with a file that |
135 // contains the traced data. | 131 // contains the traced data. |
136 // | 132 // |
137 // Trace data will be written into |result_file_path| if it is not empty, or | 133 // 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|. | 134 // into a temporary file. The actual file path will be passed to |callback|. |
139 // | 135 // |
140 // If |result_file_path| is empty and |callback| is null, trace data won't be | 136 // If |result_file_path| is empty and |callback| is null, trace data won't be |
141 // written to any file. | 137 // written to any file. |
142 virtual bool CaptureMonitoringSnapshot( | 138 virtual void CaptureMonitoringSnapshot( |
143 const base::FilePath& result_file_path, | 139 const base::FilePath& result_file_path, |
144 const TracingFileResultCallback& callback) = 0; | 140 const TracingFileResultCallback& callback) = 0; |
145 | 141 |
146 // Get the maximum across processes of trace buffer percent full state. | 142 // Get the maximum across processes of trace buffer percent full state. |
147 // When the TraceBufferPercentFull value is determined, the callback is | 143 // When the TraceBufferPercentFull value is determined, the callback is |
148 // called. | 144 // called. |
149 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; | 145 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; |
150 virtual bool GetTraceBufferPercentFull( | 146 virtual bool GetTraceBufferPercentFull( |
151 const GetTraceBufferPercentFullCallback& callback) = 0; | 147 const GetTraceBufferPercentFullCallback& callback) = 0; |
152 | 148 |
153 // |callback| will will be called every time the given event occurs on any | |
154 // process. | |
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; | |
159 | |
160 // Cancel the watch event. If tracing is enabled, this may race with the | |
161 // watch event callback. | |
162 virtual bool CancelWatchEvent() = 0; | |
163 | |
164 protected: | 149 protected: |
165 virtual ~TracingController() {} | 150 virtual ~TracingController() {} |
166 }; | 151 }; |
167 | 152 |
168 } // namespace content | 153 } // namespace content |
169 | 154 |
170 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 155 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
OLD | NEW |