| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // A subscribed trace-event occurred. | 169 // A subscribed trace-event occurred. |
| 170 EVENT_WATCH_NOTIFICATION = 1 << 1 | 170 EVENT_WATCH_NOTIFICATION = 1 << 1 |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 static TraceLog* GetInstance(); | 173 static TraceLog* GetInstance(); |
| 174 | 174 |
| 175 // Get set of known categories. This can change as new code paths are reached. | 175 // Get set of known categories. This can change as new code paths are reached. |
| 176 // The known categories are inserted into |categories|. | 176 // The known categories are inserted into |categories|. |
| 177 void GetKnownCategories(std::vector<std::string>* categories); | 177 void GetKnownCategories(std::vector<std::string>* categories); |
| 178 | 178 |
| 179 // Enable tracing for provided list of categories. If tracing is already | 179 // Enable tracing for provided list of category tags. If tracing is already |
| 180 // enabled, this method does nothing -- changing categories during trace is | 180 // enabled, this method does nothing -- changing category tags during trace |
| 181 // not supported. | 181 // is not supported. |
| 182 // If both included_categories and excluded_categories are empty, | 182 // If both included_tag_patterns and excluded_tag_patterns are empty, |
| 183 // all categories are traced. | 183 // all categories are traced. |
| 184 // Else if included_categories is non-empty, only those are traced. | 184 // Else if included_tag_patterns is non-empty, only those categories with |
| 185 // Else if excluded_categories is non-empty, everything but those are traced. | 185 // matching tags are traced. |
| 186 // Else if excluded_tag_patterns is non-empty, everything but those |
| 187 // categories with matching tags are traced. |
| 186 // Wildcards * and ? are supported (see MatchPattern in string_util.h). | 188 // Wildcards * and ? are supported (see MatchPattern in string_util.h). |
| 187 void SetEnabled(const std::vector<std::string>& included_categories, | 189 void SetEnabled(const std::vector<std::string>& included_tag_patterns, |
| 188 const std::vector<std::string>& excluded_categories); | 190 const std::vector<std::string>& excluded_tag_patterns); |
| 189 | 191 |
| 190 // |categories| is a comma-delimited list of category wildcards. | 192 // |tag_patterns| is a comma-delimited list of category tag wildcards. |
| 191 // A category can have an optional '-' prefix to make it an excluded category. | 193 // A tag pattern can have an optional '-' prefix to exclude categories |
| 194 // with matching tags excluded. |
| 195 // |
| 192 // All the same rules apply above, so for example, having both included and | 196 // All the same rules apply above, so for example, having both included and |
| 193 // excluded categories in the same list would not be supported. | 197 // excluded category tags in the same list would not be supported. |
| 194 // | 198 // |
| 195 // Example: SetEnabled("test_MyTest*"); | 199 // Example: SetEnabled("test_MyTest*"); |
| 196 // Example: SetEnabled("test_MyTest*,test_OtherStuff"); | 200 // Example: SetEnabled("test_MyTest*,test_OtherStuff"); |
| 197 // Example: SetEnabled("-excluded_category1,-excluded_category2"); | 201 // Example: SetEnabled("-excluded_category_tag1,-excluded_category_tag2"); |
| 198 void SetEnabled(const std::string& categories); | 202 void SetEnabled(const std::string& tag_patterns); |
| 199 | 203 |
| 200 // Retieves the categories set via a prior call to SetEnabled(). Only | 204 // Retieves the categories set via a prior call to SetEnabled(). Only |
| 201 // meaningful if |IsEnabled()| is true. | 205 // meaningful if |IsEnabled()| is true. |
| 202 void GetEnabledTraceCategories(std::vector<std::string>* included_out, | 206 void GetEnabledTraceCategories(std::vector<std::string>* included_out, |
| 203 std::vector<std::string>* excluded_out); | 207 std::vector<std::string>* excluded_out); |
| 204 | 208 |
| 205 // Disable tracing for all categories. | 209 // Disable tracing for all categories. |
| 206 void SetDisabled(); | 210 void SetDisabled(); |
| 207 // Helper method to enable/disable tracing for all categories. | 211 // Helper method to enable/disable tracing for all categories. |
| 208 void SetEnabled(bool enabled); | 212 void SetEnabled(bool enabled); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 247 |
| 244 // Flush all collected events to the given output callback. The callback will | 248 // Flush all collected events to the given output callback. The callback will |
| 245 // be called one or more times with IPC-bite-size chunks. The string format is | 249 // be called one or more times with IPC-bite-size chunks. The string format is |
| 246 // undefined. Use TraceResultBuffer to convert one or more trace strings to | 250 // undefined. Use TraceResultBuffer to convert one or more trace strings to |
| 247 // JSON. | 251 // JSON. |
| 248 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&)> | 252 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&)> |
| 249 OutputCallback; | 253 OutputCallback; |
| 250 void Flush(const OutputCallback& cb); | 254 void Flush(const OutputCallback& cb); |
| 251 | 255 |
| 252 // Called by TRACE_EVENT* macros, don't call this directly. | 256 // Called by TRACE_EVENT* macros, don't call this directly. |
| 257 // The name parameter is a category name that can be made up of tags, for |
| 258 // example: TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
| 253 static const unsigned char* GetCategoryEnabled(const char* name); | 259 static const unsigned char* GetCategoryEnabled(const char* name); |
| 254 static const char* GetCategoryName(const unsigned char* category_enabled); | 260 static const char* GetCategoryName(const unsigned char* category_enabled); |
| 255 | 261 |
| 256 // Called by TRACE_EVENT* macros, don't call this directly. | 262 // Called by TRACE_EVENT* macros, don't call this directly. |
| 257 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied | 263 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
| 258 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. | 264 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. |
| 259 void AddTraceEvent(char phase, | 265 void AddTraceEvent(char phase, |
| 260 const unsigned char* category_enabled, | 266 const unsigned char* category_enabled, |
| 261 const char* name, | 267 const char* name, |
| 262 unsigned long long id, | 268 unsigned long long id, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 static void ApplyATraceEnabledFlag(unsigned char* category_enabled); | 369 static void ApplyATraceEnabledFlag(unsigned char* category_enabled); |
| 364 #endif | 370 #endif |
| 365 | 371 |
| 366 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 372 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
| 367 // synchronization. | 373 // synchronization. |
| 368 // This lock protects TraceLog member accesses from arbitrary threads. | 374 // This lock protects TraceLog member accesses from arbitrary threads. |
| 369 Lock lock_; | 375 Lock lock_; |
| 370 bool enabled_; | 376 bool enabled_; |
| 371 NotificationCallback notification_callback_; | 377 NotificationCallback notification_callback_; |
| 372 std::vector<TraceEvent> logged_events_; | 378 std::vector<TraceEvent> logged_events_; |
| 373 std::vector<std::string> included_categories_; | 379 std::vector<std::string> included_tag_patterns_; |
| 374 std::vector<std::string> excluded_categories_; | 380 std::vector<std::string> excluded_tag_patterns_; |
| 375 bool dispatching_to_observer_list_; | 381 bool dispatching_to_observer_list_; |
| 376 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; | 382 ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; |
| 377 | 383 |
| 378 base::hash_map<int, std::string> thread_names_; | 384 base::hash_map<int, std::string> thread_names_; |
| 379 | 385 |
| 380 // XORed with TraceID to make it unlikely to collide with other processes. | 386 // XORed with TraceID to make it unlikely to collide with other processes. |
| 381 unsigned long long process_id_hash_; | 387 unsigned long long process_id_hash_; |
| 382 | 388 |
| 383 int process_id_; | 389 int process_id_; |
| 384 | 390 |
| 385 TimeDelta time_offset_; | 391 TimeDelta time_offset_; |
| 386 | 392 |
| 387 // Allow tests to wake up when certain events occur. | 393 // Allow tests to wake up when certain events occur. |
| 388 const unsigned char* watch_category_; | 394 const unsigned char* watch_category_; |
| 389 std::string watch_event_name_; | 395 std::string watch_event_name_; |
| 390 | 396 |
| 391 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 397 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 392 }; | 398 }; |
| 393 | 399 |
| 394 } // namespace debug | 400 } // namespace debug |
| 395 } // namespace base | 401 } // namespace base |
| 396 | 402 |
| 397 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 403 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
| OLD | NEW |