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 <stack> | 9 #include <stack> |
10 #include <string> | 10 #include <string> |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 // formatted output. | 276 // formatted output. |
277 void Finish(); | 277 void Finish(); |
278 | 278 |
279 private: | 279 private: |
280 OutputCallback output_callback_; | 280 OutputCallback output_callback_; |
281 bool append_comma_; | 281 bool append_comma_; |
282 }; | 282 }; |
283 | 283 |
284 class BASE_EXPORT CategoryFilter { | 284 class BASE_EXPORT CategoryFilter { |
285 public: | 285 public: |
| 286 typedef std::pair<std::string, std::string> DelayValue; |
| 287 typedef std::vector<DelayValue> DelayValueList; |
| 288 |
286 // The default category filter, used when none is provided. | 289 // The default category filter, used when none is provided. |
287 // Allows all categories through, except if they end in the suffix 'Debug' or | 290 // Allows all categories through, except if they end in the suffix 'Debug' or |
288 // 'Test'. | 291 // 'Test'. |
289 static const char* kDefaultCategoryFilterString; | 292 static const char* kDefaultCategoryFilterString; |
290 | 293 |
291 // |filter_string| is a comma-delimited list of category wildcards. | 294 // |filter_string| is a comma-delimited list of category wildcards. |
292 // A category can have an optional '-' prefix to make it an excluded category. | 295 // A category can have an optional '-' prefix to make it an excluded category. |
293 // All the same rules apply above, so for example, having both included and | 296 // All the same rules apply above, so for example, having both included and |
294 // excluded categories in the same list would not be supported. | 297 // excluded categories in the same list would not be supported. |
295 // | 298 // |
296 // Example: CategoryFilter"test_MyTest*"); | 299 // Example: CategoryFilter"test_MyTest*"); |
297 // Example: CategoryFilter("test_MyTest*,test_OtherStuff"); | 300 // Example: CategoryFilter("test_MyTest*,test_OtherStuff"); |
298 // Example: CategoryFilter("-excluded_category1,-excluded_category2"); | 301 // Example: CategoryFilter("-excluded_category1,-excluded_category2"); |
299 // Example: CategoryFilter("-*,webkit"); would disable everything but webkit. | 302 // Example: CategoryFilter("-*,webkit"); would disable everything but webkit. |
300 // Example: CategoryFilter("-webkit"); would enable everything but webkit. | 303 // Example: CategoryFilter("-webkit"); would enable everything but webkit. |
| 304 // |
| 305 // Category filters can also be used to configure synthetic delays. |
| 306 // |
| 307 // Example: CategoryFilter("gpu.SwapBuffers=16"); would make swap buffers |
| 308 // always take at least 16 ms. |
| 309 // Example: CategoryFilter("gpu.SwapBuffers=16;oneshot"); would make swap |
| 310 // buffers take at least 16 ms the first time it is called. |
| 311 // Example: CategoryFilter("gpu.SwapBuffers=16;alternating"); would make swap |
| 312 // buffers take at least 16 ms every other time it is called. |
301 explicit CategoryFilter(const std::string& filter_string); | 313 explicit CategoryFilter(const std::string& filter_string); |
302 | 314 |
303 CategoryFilter(const CategoryFilter& cf); | 315 CategoryFilter(const CategoryFilter& cf); |
304 | 316 |
305 ~CategoryFilter(); | 317 ~CategoryFilter(); |
306 | 318 |
307 CategoryFilter& operator=(const CategoryFilter& rhs); | 319 CategoryFilter& operator=(const CategoryFilter& rhs); |
308 | 320 |
309 // Writes the string representation of the CategoryFilter. This is a comma | 321 // Writes the string representation of the CategoryFilter. This is a comma |
310 // separated string, similar in nature to the one used to determine | 322 // separated string, similar in nature to the one used to determine |
311 // enabled/disabled category patterns, except here there is an arbitrary | 323 // enabled/disabled category patterns, except here there is an arbitrary |
312 // order, included categories go first, then excluded categories. Excluded | 324 // order, included categories go first, then excluded categories. Excluded |
313 // categories are distinguished from included categories by the prefix '-'. | 325 // categories are distinguished from included categories by the prefix '-'. |
314 std::string ToString() const; | 326 std::string ToString() const; |
315 | 327 |
316 // Determines whether category group would be enabled or | 328 // Determines whether category group would be enabled or |
317 // disabled by this category filter. | 329 // disabled by this category filter. |
318 bool IsCategoryGroupEnabled(const char* category_group) const; | 330 bool IsCategoryGroupEnabled(const char* category_group) const; |
319 | 331 |
| 332 // Return a list of the synthetic delays specified in this category filter. |
| 333 const DelayValueList& GetSyntheticDelayValues() const; |
| 334 |
320 // Merges nested_filter with the current CategoryFilter | 335 // Merges nested_filter with the current CategoryFilter |
321 void Merge(const CategoryFilter& nested_filter); | 336 void Merge(const CategoryFilter& nested_filter); |
322 | 337 |
323 // Clears both included/excluded pattern lists. This would be equivalent to | 338 // Clears both included/excluded pattern lists. This would be equivalent to |
324 // creating a CategoryFilter with an empty string, through the constructor. | 339 // creating a CategoryFilter with an empty string, through the constructor. |
325 // i.e: CategoryFilter(""). | 340 // i.e: CategoryFilter(""). |
326 // | 341 // |
327 // When using an empty filter, all categories are considered included as we | 342 // When using an empty filter, all categories are considered included as we |
328 // are not excluding anything. | 343 // are not excluding anything. |
329 void Clear(); | 344 void Clear(); |
330 | 345 |
331 private: | 346 private: |
332 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter); | 347 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter); |
333 | 348 |
334 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( | 349 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
335 const std::string& str); | 350 const std::string& str); |
336 | 351 |
337 typedef std::vector<std::string> StringList; | 352 typedef std::vector<std::string> StringList; |
338 | 353 |
339 void Initialize(const std::string& filter_string); | 354 void Initialize(const std::string& filter_string); |
340 void WriteString(const StringList& values, | 355 void WriteString(const StringList& values, |
341 std::string* out, | 356 std::string* out, |
342 bool included) const; | 357 bool included) const; |
| 358 void WriteString(const DelayValueList& delays, std::string* out) const; |
343 bool HasIncludedPatterns() const; | 359 bool HasIncludedPatterns() const; |
344 | 360 |
345 bool DoesCategoryGroupContainCategory(const char* category_group, | 361 bool DoesCategoryGroupContainCategory(const char* category_group, |
346 const char* category) const; | 362 const char* category) const; |
347 | 363 |
348 StringList included_; | 364 StringList included_; |
349 StringList disabled_; | 365 StringList disabled_; |
350 StringList excluded_; | 366 StringList excluded_; |
| 367 DelayValueList delays_; |
351 }; | 368 }; |
352 | 369 |
353 class TraceSamplingThread; | 370 class TraceSamplingThread; |
354 | 371 |
355 class BASE_EXPORT TraceLog { | 372 class BASE_EXPORT TraceLog { |
356 public: | 373 public: |
357 // Options determines how the trace buffer stores data. | 374 // Options determines how the trace buffer stores data. |
358 enum Options { | 375 enum Options { |
359 // Record until the trace buffer is full. | 376 // Record until the trace buffer is full. |
360 RECORD_UNTIL_FULL = 1 << 0, | 377 RECORD_UNTIL_FULL = 1 << 0, |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 friend struct DefaultSingletonTraits<TraceLog>; | 609 friend struct DefaultSingletonTraits<TraceLog>; |
593 | 610 |
594 // Enable/disable each category group based on the current enabled_, | 611 // Enable/disable each category group based on the current enabled_, |
595 // category_filter_, event_callback_ and event_callback_category_filter_. | 612 // category_filter_, event_callback_ and event_callback_category_filter_. |
596 // Enable the category group if enabled_ is true and category_filter_ matches | 613 // Enable the category group if enabled_ is true and category_filter_ matches |
597 // the category group, or event_callback_ is not null and | 614 // the category group, or event_callback_ is not null and |
598 // event_callback_category_filter_ matches the category group. | 615 // event_callback_category_filter_ matches the category group. |
599 void UpdateCategoryGroupEnabledFlags(); | 616 void UpdateCategoryGroupEnabledFlags(); |
600 void UpdateCategoryGroupEnabledFlag(int category_index); | 617 void UpdateCategoryGroupEnabledFlag(int category_index); |
601 | 618 |
| 619 // Configure synthetic delays based on the values set in the current |
| 620 // category filter. |
| 621 void UpdateSyntheticDelaysFromCategoryFilter(); |
| 622 |
602 class ThreadLocalEventBuffer; | 623 class ThreadLocalEventBuffer; |
603 class OptionalAutoLock; | 624 class OptionalAutoLock; |
604 | 625 |
605 TraceLog(); | 626 TraceLog(); |
606 ~TraceLog(); | 627 ~TraceLog(); |
607 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); | 628 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); |
608 void AddMetadataEventsWhileLocked(); | 629 void AddMetadataEventsWhileLocked(); |
609 | 630 |
610 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 631 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
611 TraceBuffer* CreateTraceBuffer(); | 632 TraceBuffer* CreateTraceBuffer(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 732 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
712 subtle::AtomicWord generation_; | 733 subtle::AtomicWord generation_; |
713 | 734 |
714 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 735 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
715 }; | 736 }; |
716 | 737 |
717 } // namespace debug | 738 } // namespace debug |
718 } // namespace base | 739 } // namespace base |
719 | 740 |
720 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 741 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |