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 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/memory/ref_counted.h" | |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
14 | 15 |
15 namespace base { | |
16 class FilePath; | |
17 }; | |
18 | |
19 namespace content { | 16 namespace content { |
20 | 17 |
21 class TracingController; | 18 class TracingController; |
22 | 19 |
23 // TracingController is used on the browser processes to enable/disable | 20 // TracingController is used on the browser processes to enable/disable |
24 // trace status and collect trace data. Only the browser UI thread is allowed | 21 // trace status and collect trace data. Only the browser UI thread is allowed |
25 // to interact with the TracingController object. All callbacks are called on | 22 // to interact with the TracingController object. All callbacks are called on |
26 // the UI thread. | 23 // the UI thread. |
27 class TracingController { | 24 class TracingController { |
28 public: | 25 public: |
29 | 26 |
30 CONTENT_EXPORT static TracingController* GetInstance(); | 27 CONTENT_EXPORT static TracingController* GetInstance(); |
31 | 28 |
29 // An interface for trace data consumer. An implemnentation of this interface | |
30 // is passed to either DisableTracing() or CaptureMonitoringSnapshot() and | |
31 // receives the trace data followed by a notification that all child processes | |
32 // have completed tracing and the data collection is over. | |
33 // All methods are called on the UI thread. | |
34 // Close method will be called exactly once and no methods will be | |
35 // called after that. | |
36 class CONTENT_EXPORT TraceDataSink | |
37 : public base::RefCountedThreadSafe<TraceDataSink> { | |
jochen (gone - plz use gerrit)
2014/09/10 07:33:55
why threadsafe if all happens on the UI thread?
| |
38 public: | |
39 virtual void AddTraceChunk(const std::string& chunk) {} | |
40 virtual void SetSystemTrace(const std::string& data) {} | |
41 virtual void Close() {} | |
42 protected: | |
43 friend class base::RefCountedThreadSafe<TraceDataSink>; | |
44 virtual ~TraceDataSink() {} | |
45 }; | |
46 | |
47 // Create a trace sink that may be supplied to DisableRecording or | |
48 // CaptureMonitoringSnapshot to capture the trace data as a string. | |
49 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink( | |
50 const base::Callback<void(base::RefCountedString*)>& callback); | |
51 | |
52 // Create a trace sink that may be supplied to DisableRecording or | |
53 // CaptureMonitoringSnapshot to dump the trace data to a file. | |
54 CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink( | |
55 const base::FilePath& file_path, const base::Closure& callback); | |
56 | |
32 // Get a set of category groups. The category groups can change as | 57 // Get a set of category groups. The category groups can change as |
33 // new code paths are reached. | 58 // new code paths are reached. |
34 // | 59 // |
35 // Once all child processes have acked to the GetCategories request, | 60 // Once all child processes have acked to the GetCategories request, |
36 // GetCategoriesDoneCallback is called back with a set of category | 61 // GetCategoriesDoneCallback is called back with a set of category |
37 // groups. | 62 // groups. |
38 typedef base::Callback<void(const std::set<std::string>&)> | 63 typedef base::Callback<void(const std::set<std::string>&)> |
39 GetCategoriesDoneCallback; | 64 GetCategoriesDoneCallback; |
40 virtual bool GetCategories( | 65 virtual bool GetCategories( |
41 const GetCategoriesDoneCallback& callback) = 0; | 66 const GetCategoriesDoneCallback& callback) = 0; |
(...skipping 27 matching lines...) Expand all Loading... | |
69 // Child processes typically are caching trace data and only rarely flush | 94 // Child processes typically are caching trace data and only rarely flush |
70 // and send trace data back to the browser process. That is because it may be | 95 // and send trace data back to the browser process. That is because it may be |
71 // an expensive operation to send the trace data over IPC, and we would like | 96 // an expensive operation to send the trace data over IPC, and we would like |
72 // to avoid much runtime overhead of tracing. So, to end tracing, we must | 97 // to avoid much runtime overhead of tracing. So, to end tracing, we must |
73 // asynchronously ask all child processes to flush any pending trace data. | 98 // asynchronously ask all child processes to flush any pending trace data. |
74 // | 99 // |
75 // Once all child processes have acked to the DisableRecording request, | 100 // Once all child processes have acked to the DisableRecording request, |
76 // TracingFileResultCallback will be called back with a file that contains | 101 // TracingFileResultCallback will be called back with a file that contains |
77 // the traced data. | 102 // the traced data. |
78 // | 103 // |
79 // Trace data will be written into |result_file_path| if it is not empty, or | 104 // If |trace_data_sink| is not null, it will receive chunks of trace data |
80 // into a temporary file. The actual file path will be passed to |callback| if | 105 // as a comma-separated sequences of JSON-stringified events, followed by |
81 // it's not null. | 106 // a notification that the trace collection is finished. |
82 // | 107 // |
83 // If |result_file_path| is empty and |callback| is null, trace data won't be | 108 virtual bool DisableRecording( |
84 // written to any file. | 109 const scoped_refptr<TraceDataSink> &trace_data_sink) = 0; |
jochen (gone - plz use gerrit)
2014/09/10 07:33:56
nit please clang-format (& should be before the sp
| |
85 typedef base::Callback<void(const base::FilePath&)> TracingFileResultCallback; | |
86 virtual bool DisableRecording(const base::FilePath& result_file_path, | |
87 const TracingFileResultCallback& callback) = 0; | |
88 | 110 |
89 // Start monitoring on all processes. | 111 // Start monitoring on all processes. |
90 // | 112 // |
91 // Monitoring begins immediately locally, and asynchronously on child | 113 // Monitoring begins immediately locally, and asynchronously on child |
92 // processes as soon as they receive the EnableMonitoring request. | 114 // processes as soon as they receive the EnableMonitoring request. |
93 // | 115 // |
94 // Once all child processes have acked to the EnableMonitoring request, | 116 // Once all child processes have acked to the EnableMonitoring request, |
95 // EnableMonitoringDoneCallback will be called back. | 117 // EnableMonitoringDoneCallback will be called back. |
96 // | 118 // |
97 // |category_filter| is a filter to control what category groups should be | 119 // |category_filter| is a filter to control what category groups should be |
(...skipping 25 matching lines...) Expand all Loading... | |
123 // Child processes typically are caching trace data and only rarely flush | 145 // 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 | 146 // 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 | 147 // 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 | 148 // 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. | 149 // asynchronously ask all child processes to flush any pending trace data. |
128 // | 150 // |
129 // Once all child processes have acked to the CaptureMonitoringSnapshot | 151 // Once all child processes have acked to the CaptureMonitoringSnapshot |
130 // request, TracingFileResultCallback will be called back with a file that | 152 // request, TracingFileResultCallback will be called back with a file that |
131 // contains the traced data. | 153 // contains the traced data. |
132 // | 154 // |
133 // Trace data will be written into |result_file_path| if it is not empty, or | 155 // If |trace_data_sink| is not null, it will receive chunks of trace data |
134 // into a temporary file. The actual file path will be passed to |callback|. | 156 // as a comma-separated sequences of JSON-stringified events, followed by |
135 // | 157 // a notification that the trace collection is finished. |
136 // If |result_file_path| is empty and |callback| is null, trace data won't be | |
137 // written to any file. | |
138 virtual bool CaptureMonitoringSnapshot( | 158 virtual bool CaptureMonitoringSnapshot( |
139 const base::FilePath& result_file_path, | 159 const scoped_refptr<TraceDataSink> &trace_data_sink) = 0; |
140 const TracingFileResultCallback& callback) = 0; | |
141 | 160 |
142 // Get the maximum across processes of trace buffer percent full state. | 161 // Get the maximum across processes of trace buffer percent full state. |
143 // When the TraceBufferPercentFull value is determined, the callback is | 162 // When the TraceBufferPercentFull value is determined, the callback is |
144 // called. | 163 // called. |
145 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; | 164 typedef base::Callback<void(float)> GetTraceBufferPercentFullCallback; |
146 virtual bool GetTraceBufferPercentFull( | 165 virtual bool GetTraceBufferPercentFull( |
147 const GetTraceBufferPercentFullCallback& callback) = 0; | 166 const GetTraceBufferPercentFullCallback& callback) = 0; |
148 | 167 |
149 // |callback| will will be called every time the given event occurs on any | 168 // |callback| will will be called every time the given event occurs on any |
150 // process. | 169 // process. |
151 typedef base::Callback<void()> WatchEventCallback; | 170 typedef base::Callback<void()> WatchEventCallback; |
152 virtual bool SetWatchEvent(const std::string& category_name, | 171 virtual bool SetWatchEvent(const std::string& category_name, |
153 const std::string& event_name, | 172 const std::string& event_name, |
154 const WatchEventCallback& callback) = 0; | 173 const WatchEventCallback& callback) = 0; |
155 | 174 |
156 // Cancel the watch event. If tracing is enabled, this may race with the | 175 // Cancel the watch event. If tracing is enabled, this may race with the |
157 // watch event callback. | 176 // watch event callback. |
158 virtual bool CancelWatchEvent() = 0; | 177 virtual bool CancelWatchEvent() = 0; |
159 | 178 |
160 protected: | 179 protected: |
161 virtual ~TracingController() {} | 180 virtual ~TracingController() {} |
162 }; | 181 }; |
163 | 182 |
164 } // namespace content | 183 } // namespace content |
165 | 184 |
166 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ | 185 #endif // CONTENT_PUBLIC_BROWSER_TRACING_CONTROLLER_H_ |
OLD | NEW |