OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 5 |
6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 7 #define BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 // When all fragments have been added, call Finish to complete the JSON | 151 // When all fragments have been added, call Finish to complete the JSON |
152 // formatted output. | 152 // formatted output. |
153 void Finish(); | 153 void Finish(); |
154 | 154 |
155 private: | 155 private: |
156 OutputCallback output_callback_; | 156 OutputCallback output_callback_; |
157 bool append_comma_; | 157 bool append_comma_; |
158 }; | 158 }; |
159 | 159 |
| 160 // TraceMode determines how the trace buffer stores data. |
| 161 enum BASE_EXPORT TraceMode { |
| 162 UNTIL_FULL = 0 |
| 163 }; |
160 | 164 |
161 class BASE_EXPORT TraceLog { | 165 class BASE_EXPORT TraceLog { |
162 public: | 166 public: |
163 // Notification is a mask of one or more of the following events. | 167 // Notification is a mask of one or more of the following events. |
164 enum Notification { | 168 enum Notification { |
165 // The trace buffer does not flush dynamically, so when it fills up, | 169 // The trace buffer does not flush dynamically, so when it fills up, |
166 // subsequent trace events will be dropped. This callback is generated when | 170 // subsequent trace events will be dropped. This callback is generated when |
167 // the trace buffer is full. The callback must be thread safe. | 171 // the trace buffer is full. The callback must be thread safe. |
168 TRACE_BUFFER_FULL = 1 << 0, | 172 TRACE_BUFFER_FULL = 1 << 0, |
169 // A subscribed trace-event occurred. | 173 // A subscribed trace-event occurred. |
170 EVENT_WATCH_NOTIFICATION = 1 << 1 | 174 EVENT_WATCH_NOTIFICATION = 1 << 1 |
171 }; | 175 }; |
172 | 176 |
173 static TraceLog* GetInstance(); | 177 static TraceLog* GetInstance(); |
174 | 178 |
175 // Get set of known categories. This can change as new code paths are reached. | 179 // Get set of known categories. This can change as new code paths are reached. |
176 // The known categories are inserted into |categories|. | 180 // The known categories are inserted into |categories|. |
177 void GetKnownCategories(std::vector<std::string>* categories); | 181 void GetKnownCategories(std::vector<std::string>* categories); |
178 | 182 |
179 // Enable tracing for provided list of categories. If tracing is already | 183 // Enable tracing for provided list of categories. If tracing is already |
180 // enabled, this method does nothing -- changing categories during trace is | 184 // enabled, this method does nothing -- changing categories during trace is |
181 // not supported. | 185 // not supported. |
182 // If both included_categories and excluded_categories are empty, | 186 // If both included_categories and excluded_categories are empty, |
183 // all categories are traced. | 187 // all categories are traced. |
184 // Else if included_categories is non-empty, only those are traced. | 188 // Else if included_categories is non-empty, only those are traced. |
185 // Else if excluded_categories is non-empty, everything but those are traced. | 189 // Else if excluded_categories is non-empty, everything but those are traced. |
186 // Wildcards * and ? are supported (see MatchPattern in string_util.h). | 190 // Wildcards * and ? are supported (see MatchPattern in string_util.h). |
187 void SetEnabled(const std::vector<std::string>& included_categories, | 191 void SetEnabled(const std::vector<std::string>& included_categories, |
188 const std::vector<std::string>& excluded_categories); | 192 const std::vector<std::string>& excluded_categories, |
| 193 TraceMode mode); |
189 | 194 |
190 // |categories| is a comma-delimited list of category wildcards. | 195 // |categories| is a comma-delimited list of category wildcards. |
191 // A category can have an optional '-' prefix to make it an excluded category. | 196 // A category can have an optional '-' prefix to make it an excluded category. |
192 // All the same rules apply above, so for example, having both included and | 197 // All the same rules apply above, so for example, having both included and |
193 // excluded categories in the same list would not be supported. | 198 // excluded categories in the same list would not be supported. |
194 // | 199 // |
195 // Example: SetEnabled("test_MyTest*"); | 200 // Example: SetEnabled("test_MyTest*"); |
196 // Example: SetEnabled("test_MyTest*,test_OtherStuff"); | 201 // Example: SetEnabled("test_MyTest*,test_OtherStuff"); |
197 // Example: SetEnabled("-excluded_category1,-excluded_category2"); | 202 // Example: SetEnabled("-excluded_category1,-excluded_category2"); |
198 void SetEnabled(const std::string& categories); | 203 void SetEnabled(const std::string& categories, TraceMode mode); |
199 | 204 |
200 // Retieves the categories set via a prior call to SetEnabled(). Only | 205 // Retieves the categories set via a prior call to SetEnabled(). Only |
201 // meaningful if |IsEnabled()| is true. | 206 // meaningful if |IsEnabled()| is true. |
202 void GetEnabledTraceCategories(std::vector<std::string>* included_out, | 207 void GetEnabledTraceCategories(std::vector<std::string>* included_out, |
203 std::vector<std::string>* excluded_out); | 208 std::vector<std::string>* excluded_out); |
204 | 209 |
| 210 TraceMode GetTraceMode() { return trace_mode_; } |
| 211 |
205 // Disable tracing for all categories. | 212 // Disable tracing for all categories. |
206 void SetDisabled(); | 213 void SetDisabled(); |
207 // Helper method to enable/disable tracing for all categories. | 214 // Helper method to enable/disable tracing for all categories. |
208 void SetEnabled(bool enabled); | 215 void SetEnabled(bool enabled, TraceMode mode); |
209 bool IsEnabled() { return !!enable_count_; } | 216 bool IsEnabled() { return !!enable_count_; } |
210 | 217 |
211 #if defined(OS_ANDROID) | 218 #if defined(OS_ANDROID) |
212 void StartATrace(); | 219 void StartATrace(); |
213 void StopATrace(); | 220 void StopATrace(); |
214 #endif | 221 #endif |
215 | 222 |
216 // Enabled state listeners give a callback when tracing is enabled or | 223 // Enabled state listeners give a callback when tracing is enabled or |
217 // disabled. This can be used to tie into other library's tracing systems | 224 // disabled. This can be used to tie into other library's tracing systems |
218 // on-demand. | 225 // on-demand. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 unsigned long long process_id_hash_; | 400 unsigned long long process_id_hash_; |
394 | 401 |
395 int process_id_; | 402 int process_id_; |
396 | 403 |
397 TimeDelta time_offset_; | 404 TimeDelta time_offset_; |
398 | 405 |
399 // Allow tests to wake up when certain events occur. | 406 // Allow tests to wake up when certain events occur. |
400 const unsigned char* watch_category_; | 407 const unsigned char* watch_category_; |
401 std::string watch_event_name_; | 408 std::string watch_event_name_; |
402 | 409 |
| 410 TraceMode trace_mode_; |
| 411 |
403 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 412 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
404 }; | 413 }; |
405 | 414 |
406 } // namespace debug | 415 } // namespace debug |
407 } // namespace base | 416 } // namespace base |
408 | 417 |
409 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 418 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |