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