| 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 bool 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 13 matching lines...) Expand all Loading... |
| 90 const TracingFileResultCallback& callback) = 0; | 92 const TracingFileResultCallback& callback) = 0; |
| 91 | 93 |
| 92 // Start monitoring on all processes. | 94 // Start monitoring on all processes. |
| 93 // | 95 // |
| 94 // Monitoring begins immediately locally, and asynchronously on child | 96 // Monitoring begins immediately locally, and asynchronously on child |
| 95 // processes as soon as they receive the EnableMonitoring request. | 97 // processes as soon as they receive the EnableMonitoring request. |
| 96 // | 98 // |
| 97 // Once all child processes have acked to the EnableMonitoring request, | 99 // Once all child processes have acked to the EnableMonitoring request, |
| 98 // EnableMonitoringDoneCallback will be called back. | 100 // EnableMonitoringDoneCallback will be called back. |
| 99 // | 101 // |
| 100 // |filter| is a filter to control what category groups should be traced. | 102 // |category_filter| is a filter to control what category groups should be |
| 103 // traced. |
| 101 // | 104 // |
| 102 // |options| controls what kind of tracing is enabled. | 105 // |options| controls what kind of tracing is enabled. |
| 103 typedef base::Callback<void()> EnableMonitoringDoneCallback; | 106 typedef base::Callback<void()> EnableMonitoringDoneCallback; |
| 104 virtual bool EnableMonitoring(const base::debug::CategoryFilter& filter, | 107 virtual bool EnableMonitoring( |
| 108 const std::string& category_filter, |
| 105 TracingController::Options options, | 109 TracingController::Options options, |
| 106 const EnableMonitoringDoneCallback& callback) = 0; | 110 const EnableMonitoringDoneCallback& callback) = 0; |
| 107 | 111 |
| 108 // Stop monitoring on all processes. | 112 // Stop monitoring on all processes. |
| 109 // | 113 // |
| 110 // Once all child processes have acked to the DisableMonitoring request, | 114 // Once all child processes have acked to the DisableMonitoring request, |
| 111 // DisableMonitoringDoneCallback is called back. | 115 // DisableMonitoringDoneCallback is called back. |
| 112 typedef base::Callback<void()> DisableMonitoringDoneCallback; | 116 typedef base::Callback<void()> DisableMonitoringDoneCallback; |
| 113 virtual bool DisableMonitoring( | 117 virtual bool DisableMonitoring( |
| 114 const DisableMonitoringDoneCallback& callback) = 0; | 118 const DisableMonitoringDoneCallback& callback) = 0; |
| 115 | 119 |
| 116 // Get the current monitoring configuration. | 120 // Get the current monitoring configuration. |
| 117 virtual void GetMonitoringStatus(bool* out_enabled, | 121 virtual void GetMonitoringStatus(bool* out_enabled, |
| 118 base::debug::CategoryFilter* out_filter, | 122 std::string* out_category_filter, |
| 119 TracingController::Options* out_options) = 0; | 123 TracingController::Options* out_options) = 0; |
| 120 | 124 |
| 121 // Get the current monitoring traced data. | 125 // Get the current monitoring traced data. |
| 122 // | 126 // |
| 123 // Child processes typically are caching trace data and only rarely flush | 127 // Child processes typically are caching trace data and only rarely flush |
| 124 // and send trace data back to the browser process. That is because it may be | 128 // and send trace data back to the browser process. That is because it may be |
| 125 // an expensive operation to send the trace data over IPC, and we would like | 129 // an expensive operation to send the trace data over IPC, and we would like |
| 126 // to avoid much runtime overhead of tracing. So, to end tracing, we must | 130 // to avoid much runtime overhead of tracing. So, to end tracing, we must |
| 127 // asynchronously ask all child processes to flush any pending trace data. | 131 // asynchronously ask all child processes to flush any pending trace data. |
| 128 // | 132 // |
| 129 // Once all child processes have acked to the CaptureMonitoringSnapshot | 133 // Once all child processes have acked to the CaptureMonitoringSnapshot |
| 130 // request, TracingFileResultCallback will be called back with a file that | 134 // request, TracingFileResultCallback will be called back with a file that |
| 131 // contains the traced data. | 135 // contains the traced data. |
| 132 // | 136 // |
| 133 // Trace data will be written into |result_file_path| if it is not empty, or | 137 // Trace data will be written into |result_file_path| if it is not empty, or |
| 134 // into a temporary file. The actual file path will be passed to |callback|. | 138 // into a temporary file. The actual file path will be passed to |callback|. |
| 135 // | 139 // |
| 136 // If |result_file_path| is empty and |callback| is null, trace data won't be | 140 // If |result_file_path| is empty and |callback| is null, trace data won't be |
| 137 // written to any file. | 141 // written to any file. |
| 138 virtual void CaptureMonitoringSnapshot( | 142 virtual bool CaptureMonitoringSnapshot( |
| 139 const base::FilePath& result_file_path, | 143 const base::FilePath& result_file_path, |
| 140 const TracingFileResultCallback& callback) = 0; | 144 const TracingFileResultCallback& callback) = 0; |
| 141 | 145 |
| 142 // Get the maximum across processes of trace buffer percent full state. | 146 // Get the maximum across processes of trace buffer percent full state. |
| 143 // When the TraceBufferPercentFull value is determined, the callback is | 147 // When the TraceBufferPercentFull value is determined, the callback is |
| 144 // called. | 148 // called. |
| 145 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; | 149 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; |
| 146 virtual bool GetTraceBufferPercentFull( | 150 virtual bool GetTraceBufferPercentFull( |
| 147 const GetTraceBufferPercentFullCallback& callback) = 0; | 151 const GetTraceBufferPercentFullCallback& callback) = 0; |
| 148 | 152 |
| 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 |
| 149 protected: | 164 protected: |
| 150 virtual ~TracingController() {} | 165 virtual ~TracingController() {} |
| 151 }; | 166 }; |
| 152 | 167 |
| 153 } // namespace content | 168 } // namespace content |
| 154 | 169 |
| 155 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 170 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
| OLD | NEW |