| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // TracingController is used on the browser processes to enable/disable | 24 // TracingController is used on the browser processes to enable/disable |
| 25 // tracing status and collect trace data. Only the browser UI thread is allowed | 25 // tracing status and collect trace data. Only the browser UI thread is allowed |
| 26 // to interact with the TracingController object. All callbacks are called on | 26 // to interact with the TracingController object. All callbacks are called on |
| 27 // the UI thread. | 27 // the UI thread. |
| 28 class TracingController { | 28 class TracingController { |
| 29 public: | 29 public: |
| 30 | 30 |
| 31 CONTENT_EXPORT static TracingController* GetInstance(); | 31 CONTENT_EXPORT static TracingController* GetInstance(); |
| 32 | 32 |
| 33 // An interface for trace data consumer. An implemnentation of this interface | 33 // An interface for trace data consumer. An implementation of this interface |
| 34 // is passed to either DisableTracing() or CaptureMonitoringSnapshot() and | 34 // is passed to DisableTracing() and receives the trace data |
| 35 // receives the trace data followed by a notification that all child processes | 35 // followed by a notification that all child processes |
| 36 // have completed tracing and the data collection is over. | 36 // have completed tracing and the data collection is over. |
| 37 // All methods are called on the UI thread. | 37 // All methods are called on the UI thread. |
| 38 // Close method will be called exactly once and no methods will be | 38 // Close method will be called exactly once and no methods will be |
| 39 // called after that. | 39 // called after that. |
| 40 class CONTENT_EXPORT TraceDataSink | 40 class CONTENT_EXPORT TraceDataSink |
| 41 : public base::RefCountedThreadSafe<TraceDataSink> { | 41 : public base::RefCountedThreadSafe<TraceDataSink> { |
| 42 public: | 42 public: |
| 43 TraceDataSink(); | 43 TraceDataSink(); |
| 44 | 44 |
| 45 virtual void AddTraceChunk(const std::string& chunk) {} | 45 virtual void AddTraceChunk(const std::string& chunk) {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 virtual void ReceiveTraceChunk(const std::string& chunk) {} | 83 virtual void ReceiveTraceChunk(const std::string& chunk) {} |
| 84 virtual void ReceiveTraceFinalContents( | 84 virtual void ReceiveTraceFinalContents( |
| 85 scoped_ptr<const base::DictionaryValue> metadata, | 85 scoped_ptr<const base::DictionaryValue> metadata, |
| 86 const std::string& contents) {} | 86 const std::string& contents) {} |
| 87 | 87 |
| 88 protected: | 88 protected: |
| 89 friend class base::RefCountedThreadSafe<TraceDataEndpoint>; | 89 friend class base::RefCountedThreadSafe<TraceDataEndpoint>; |
| 90 virtual ~TraceDataEndpoint() {} | 90 virtual ~TraceDataEndpoint() {} |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // Create a trace sink that may be supplied to StopTracing or | 93 // Create a trace sink that may be supplied to StopTracing |
| 94 // CaptureMonitoringSnapshot to capture the trace data as a string. | 94 // to capture the trace data as a string. |
| 95 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink( | 95 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink( |
| 96 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, | 96 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, |
| 97 base::RefCountedString*)>& callback); | 97 base::RefCountedString*)>& callback); |
| 98 | 98 |
| 99 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink( | 99 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink( |
| 100 scoped_refptr<TraceDataEndpoint> endpoint); | 100 scoped_refptr<TraceDataEndpoint> endpoint); |
| 101 | 101 |
| 102 // Create a trace sink that may be supplied to StopTracing or | 102 // Create a trace sink that may be supplied to StopTracing |
| 103 // CaptureMonitoringSnapshot to dump the trace data to a file. | 103 // to dump the trace data to a file. |
| 104 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink( | 104 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink( |
| 105 const base::FilePath& file_path, | 105 const base::FilePath& file_path, |
| 106 const base::Closure& callback); | 106 const base::Closure& callback); |
| 107 | 107 |
| 108 // Create an endpoint that may be supplied to any TraceDataSink to | 108 // Create an endpoint that may be supplied to any TraceDataSink to |
| 109 // dump the trace data to a callback. | 109 // dump the trace data to a callback. |
| 110 CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint( | 110 CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint( |
| 111 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, | 111 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, |
| 112 base::RefCountedString*)>& callback); | 112 base::RefCountedString*)>& callback); |
| 113 | 113 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 // TracingFileResultCallback will be called back with a file that contains | 163 // TracingFileResultCallback will be called back with a file that contains |
| 164 // the traced data. | 164 // the traced data. |
| 165 // | 165 // |
| 166 // If |trace_data_sink| is not null, it will receive chunks of trace data | 166 // If |trace_data_sink| is not null, it will receive chunks of trace data |
| 167 // as a comma-separated sequences of JSON-stringified events, followed by | 167 // as a comma-separated sequences of JSON-stringified events, followed by |
| 168 // a notification that the trace collection is finished. | 168 // a notification that the trace collection is finished. |
| 169 // | 169 // |
| 170 virtual bool StopTracing( | 170 virtual bool StopTracing( |
| 171 const scoped_refptr<TraceDataSink>& trace_data_sink) = 0; | 171 const scoped_refptr<TraceDataSink>& trace_data_sink) = 0; |
| 172 | 172 |
| 173 // Start monitoring on all processes. | |
| 174 // | |
| 175 // Monitoring begins immediately locally, and asynchronously on child | |
| 176 // processes as soon as they receive the StartMonitoring request. | |
| 177 // | |
| 178 // Once all child processes have acked to the StartMonitoring request, | |
| 179 // StartMonitoringDoneCallback will be called back. | |
| 180 // | |
| 181 // |category_filter| is a filter to control what category groups should be | |
| 182 // traced. | |
| 183 // | |
| 184 // |trace_config| controls what kind of tracing is enabled. | |
| 185 typedef base::Callback<void()> StartMonitoringDoneCallback; | |
| 186 virtual bool StartMonitoring( | |
| 187 const base::trace_event::TraceConfig& trace_config, | |
| 188 const StartMonitoringDoneCallback& callback) = 0; | |
| 189 | |
| 190 // Stop monitoring on all processes. | |
| 191 // | |
| 192 // Once all child processes have acked to the StopMonitoring request, | |
| 193 // StopMonitoringDoneCallback is called back. | |
| 194 typedef base::Callback<void()> StopMonitoringDoneCallback; | |
| 195 virtual bool StopMonitoring( | |
| 196 const StopMonitoringDoneCallback& callback) = 0; | |
| 197 | |
| 198 // Get the current monitoring configuration. | |
| 199 virtual void GetMonitoringStatus( | |
| 200 bool* out_enabled, | |
| 201 base::trace_event::TraceConfig* out_trace_config) = 0; | |
| 202 | |
| 203 // Get the current monitoring traced data. | |
| 204 // | |
| 205 // Child processes typically are caching trace data and only rarely flush | |
| 206 // and send trace data back to the browser process. That is because it may be | |
| 207 // an expensive operation to send the trace data over IPC, and we would like | |
| 208 // to avoid much runtime overhead of tracing. So, to end tracing, we must | |
| 209 // asynchronously ask all child processes to flush any pending trace data. | |
| 210 // | |
| 211 // Once all child processes have acked to the CaptureMonitoringSnapshot | |
| 212 // request, TracingFileResultCallback will be called back with a file that | |
| 213 // contains the traced data. | |
| 214 // | |
| 215 // If |trace_data_sink| is not null, it will receive chunks of trace data | |
| 216 // as a comma-separated sequences of JSON-stringified events, followed by | |
| 217 // a notification that the trace collection is finished. | |
| 218 virtual bool CaptureMonitoringSnapshot( | |
| 219 const scoped_refptr<TraceDataSink>& trace_data_sink) = 0; | |
| 220 | |
| 221 // Get the maximum across processes of trace buffer percent full state. | 173 // Get the maximum across processes of trace buffer percent full state. |
| 222 // When the TraceBufferUsage value is determined, the callback is | 174 // When the TraceBufferUsage value is determined, the callback is |
| 223 // called. | 175 // called. |
| 224 typedef base::Callback<void(float, size_t)> GetTraceBufferUsageCallback; | 176 typedef base::Callback<void(float, size_t)> GetTraceBufferUsageCallback; |
| 225 virtual bool GetTraceBufferUsage( | 177 virtual bool GetTraceBufferUsage( |
| 226 const GetTraceBufferUsageCallback& callback) = 0; | 178 const GetTraceBufferUsageCallback& callback) = 0; |
| 227 | 179 |
| 228 // |callback| will will be called every time the given event occurs on any | 180 // |callback| will will be called every time the given event occurs on any |
| 229 // process. | 181 // process. |
| 230 typedef base::Callback<void()> WatchEventCallback; | 182 typedef base::Callback<void()> WatchEventCallback; |
| 231 virtual bool SetWatchEvent(const std::string& category_name, | 183 virtual bool SetWatchEvent(const std::string& category_name, |
| 232 const std::string& event_name, | 184 const std::string& event_name, |
| 233 const WatchEventCallback& callback) = 0; | 185 const WatchEventCallback& callback) = 0; |
| 234 | 186 |
| 235 // Cancel the watch event. If tracing is enabled, this may race with the | 187 // Cancel the watch event. If tracing is enabled, this may race with the |
| 236 // watch event callback. | 188 // watch event callback. |
| 237 virtual bool CancelWatchEvent() = 0; | 189 virtual bool CancelWatchEvent() = 0; |
| 238 | 190 |
| 239 // Check if the tracing system is tracing | 191 // Check if the tracing system is tracing |
| 240 virtual bool IsTracing() const = 0; | 192 virtual bool IsTracing() const = 0; |
| 241 | 193 |
| 242 protected: | 194 protected: |
| 243 virtual ~TracingController() {} | 195 virtual ~TracingController() {} |
| 244 }; | 196 }; |
| 245 | 197 |
| 246 } // namespace content | 198 } // namespace content |
| 247 | 199 |
| 248 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 200 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
| OLD | NEW |