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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 StringList included_; | 348 StringList included_; |
349 StringList disabled_; | 349 StringList disabled_; |
350 StringList excluded_; | 350 StringList excluded_; |
351 }; | 351 }; |
352 | 352 |
353 class TraceSamplingThread; | 353 class TraceSamplingThread; |
354 | 354 |
355 class BASE_EXPORT TraceLog { | 355 class BASE_EXPORT TraceLog { |
356 public: | 356 public: |
357 enum Mode { | |
358 DISABLED = 0, | |
359 RECORDING_MODE, | |
360 MONITORING_MODE, | |
361 }; | |
362 | |
363 // Options determines how the trace buffer stores data. | 357 // Options determines how the trace buffer stores data. |
364 enum Options { | 358 enum Options { |
365 // Record until the trace buffer is full. | 359 // Record until the trace buffer is full. |
366 RECORD_UNTIL_FULL = 1 << 0, | 360 RECORD_UNTIL_FULL = 1 << 0, |
367 | 361 |
368 // Record until the user ends the trace. The trace buffer is a fixed size | 362 // Record until the user ends the trace. The trace buffer is a fixed size |
369 // and we use it as a ring buffer during recording. | 363 // and we use it as a ring buffer during recording. |
370 RECORD_CONTINUOUSLY = 1 << 1, | 364 RECORD_CONTINUOUSLY = 1 << 1, |
371 | 365 |
372 // Enable the sampling profiler in the recording mode. | 366 // Enable the sampling profiler in the recording mode. |
373 ENABLE_SAMPLING = 1 << 2, | 367 ENABLE_SAMPLING = 1 << 2, |
374 | 368 |
| 369 // Enable the sampling profiler in the monitoring mode. |
| 370 MONITOR_SAMPLING = 1 << 3, |
| 371 |
375 // Echo to console. Events are discarded. | 372 // Echo to console. Events are discarded. |
376 ECHO_TO_CONSOLE = 1 << 3, | 373 ECHO_TO_CONSOLE = 1 << 4, |
377 }; | 374 }; |
378 | 375 |
379 // The pointer returned from GetCategoryGroupEnabledInternal() points to a | 376 // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
380 // value with zero or more of the following bits. Used in this class only. | 377 // value with zero or more of the following bits. Used in this class only. |
381 // The TRACE_EVENT macros should only use the value as a bool. | 378 // The TRACE_EVENT macros should only use the value as a bool. |
382 // These values must be in sync with macro values in TraceEvent.h in Blink. | |
383 enum CategoryGroupEnabledFlags { | 379 enum CategoryGroupEnabledFlags { |
384 // Category group enabled for the recording mode. | 380 // Normal enabled flag for category groups enabled by SetEnabled(). |
385 ENABLED_FOR_RECORDING = 1 << 0, | 381 ENABLED_FOR_RECORDING = 1 << 0, |
386 // Category group enabled for the monitoring mode. | |
387 ENABLED_FOR_MONITORING = 1 << 1, | |
388 // Category group enabled by SetEventCallbackEnabled(). | 382 // Category group enabled by SetEventCallbackEnabled(). |
389 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, | 383 ENABLED_FOR_EVENT_CALLBACK = 1 << 1, |
390 }; | 384 }; |
391 | 385 |
392 static TraceLog* GetInstance(); | 386 static TraceLog* GetInstance(); |
393 | 387 |
394 // Get set of known category groups. This can change as new code paths are | 388 // Get set of known category groups. This can change as new code paths are |
395 // reached. The known category groups are inserted into |category_groups|. | 389 // reached. The known category groups are inserted into |category_groups|. |
396 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); | 390 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); |
397 | 391 |
398 // Retrieves a copy (for thread-safety) of the current CategoryFilter. | 392 // Retrieves a copy (for thread-safety) of the current CategoryFilter. |
399 CategoryFilter GetCurrentCategoryFilter(); | 393 CategoryFilter GetCurrentCategoryFilter(); |
400 | 394 |
401 Options trace_options() const { | 395 Options trace_options() const { |
402 return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_)); | 396 return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_)); |
403 } | 397 } |
404 | 398 |
405 // Enables normal tracing (recording trace events in the trace buffer). | 399 // Enables normal tracing (recording trace events in the trace buffer). |
406 // See CategoryFilter comments for details on how to control what categories | 400 // See CategoryFilter comments for details on how to control what categories |
407 // will be traced. If tracing has already been enabled, |category_filter| will | 401 // will be traced. If tracing has already been enabled, |category_filter| will |
408 // be merged into the current category filter. | 402 // be merged into the current category filter. |
409 void SetEnabled(const CategoryFilter& category_filter, | 403 void SetEnabled(const CategoryFilter& category_filter, Options options); |
410 Mode mode, Options options); | |
411 | 404 |
412 // Disables normal tracing for all categories. | 405 // Disables normal tracing for all categories. |
413 void SetDisabled(); | 406 void SetDisabled(); |
414 | 407 |
415 bool IsEnabled() { return mode_ != DISABLED; } | 408 bool IsEnabled() { return enabled_; } |
416 | 409 |
417 // The number of times we have begun recording traces. If tracing is off, | 410 // The number of times we have begun recording traces. If tracing is off, |
418 // returns -1. If tracing is on, then it returns the number of times we have | 411 // returns -1. If tracing is on, then it returns the number of times we have |
419 // recorded a trace. By watching for this number to increment, you can | 412 // recorded a trace. By watching for this number to increment, you can |
420 // passively discover when a new trace has begun. This is then used to | 413 // passively discover when a new trace has begun. This is then used to |
421 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. | 414 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. |
422 int GetNumTracesRecorded(); | 415 int GetNumTracesRecorded(); |
423 | 416 |
424 #if defined(OS_ANDROID) | 417 #if defined(OS_ANDROID) |
425 void StartATrace(); | 418 void StartATrace(); |
426 void StopATrace(); | 419 void StopATrace(); |
427 void AddClockSyncMetadataEvent(); | 420 void AddClockSyncMetadataEvent(); |
428 #endif | 421 #endif |
429 | 422 |
430 // Enabled state listeners give a callback when tracing is enabled or | 423 // Enabled state listeners give a callback when tracing is enabled or |
431 // disabled. This can be used to tie into other library's tracing systems | 424 // disabled. This can be used to tie into other library's tracing systems |
432 // on-demand. | 425 // on-demand. |
433 class EnabledStateObserver { | 426 class EnabledStateObserver { |
434 public: | 427 public: |
435 // Called just after the tracing system becomes enabled, outside of the | 428 // Called just after the tracing system becomes enabled, outside of the |
436 // |lock_|. TraceLog::IsEnabled() is true at this point. | 429 // |lock_|. TraceLog::IsEnabled() is true at this point. |
437 virtual void OnTraceLogEnabled() = 0; | 430 virtual void OnTraceLogEnabled() = 0; |
438 | 431 |
439 // Called just after the tracing system disables, outside of the |lock_|. | 432 // Called just after the tracing system disables, outside of the |lock_|. |
440 // TraceLog::IsEnabled() is false at this point. | 433 // TraceLog::IsEnabled() is false at this point. |
441 virtual void OnTraceLogDisabled() = 0; | 434 virtual void OnTraceLogDisabled() = 0; |
442 }; | 435 }; |
443 void AddEnabledStateObserver(EnabledStateObserver* listener); | 436 void AddEnabledStateObserver(EnabledStateObserver* listener); |
444 void RemoveEnabledStateObserver(EnabledStateObserver* listener); | 437 void RemoveEnabledStateObserver(EnabledStateObserver* listener); |
445 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; | 438 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; |
446 | 439 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 TraceBufferRingBufferGetReturnChunk); | 584 TraceBufferRingBufferGetReturnChunk); |
592 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 585 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
593 TraceBufferRingBufferHalfIteration); | 586 TraceBufferRingBufferHalfIteration); |
594 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 587 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
595 TraceBufferRingBufferFullIteration); | 588 TraceBufferRingBufferFullIteration); |
596 | 589 |
597 // This allows constructor and destructor to be private and usable only | 590 // This allows constructor and destructor to be private and usable only |
598 // by the Singleton class. | 591 // by the Singleton class. |
599 friend struct DefaultSingletonTraits<TraceLog>; | 592 friend struct DefaultSingletonTraits<TraceLog>; |
600 | 593 |
601 // Enable/disable each category group based on the current mode_, | 594 // Enable/disable each category group based on the current enabled_, |
602 // category_filter_, event_callback_ and event_callback_category_filter_. | 595 // category_filter_, event_callback_ and event_callback_category_filter_. |
603 // Enable the category group in the enabled mode if category_filter_ matches | 596 // Enable the category group if enabled_ is true and category_filter_ matches |
604 // the category group, or event_callback_ is not null and | 597 // the category group, or event_callback_ is not null and |
605 // event_callback_category_filter_ matches the category group. | 598 // event_callback_category_filter_ matches the category group. |
606 void UpdateCategoryGroupEnabledFlags(); | 599 void UpdateCategoryGroupEnabledFlags(); |
607 void UpdateCategoryGroupEnabledFlag(int category_index); | 600 void UpdateCategoryGroupEnabledFlag(int category_index); |
608 | 601 |
609 class ThreadLocalEventBuffer; | 602 class ThreadLocalEventBuffer; |
610 class OptionalAutoLock; | 603 class OptionalAutoLock; |
611 | 604 |
612 TraceLog(); | 605 TraceLog(); |
613 ~TraceLog(); | 606 ~TraceLog(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 return timestamp - time_offset_; | 645 return timestamp - time_offset_; |
653 } | 646 } |
654 | 647 |
655 // This lock protects TraceLog member accesses (except for members protected | 648 // This lock protects TraceLog member accesses (except for members protected |
656 // by thread_info_lock_) from arbitrary threads. | 649 // by thread_info_lock_) from arbitrary threads. |
657 mutable Lock lock_; | 650 mutable Lock lock_; |
658 // This lock protects accesses to thread_names_, thread_event_start_times_ | 651 // This lock protects accesses to thread_names_, thread_event_start_times_ |
659 // and thread_colors_. | 652 // and thread_colors_. |
660 Lock thread_info_lock_; | 653 Lock thread_info_lock_; |
661 int locked_line_; | 654 int locked_line_; |
662 Mode mode_; | 655 bool enabled_; |
663 int num_traces_recorded_; | 656 int num_traces_recorded_; |
664 scoped_ptr<TraceBuffer> logged_events_; | 657 scoped_ptr<TraceBuffer> logged_events_; |
665 subtle::AtomicWord /* EventCallback */ event_callback_; | 658 subtle::AtomicWord /* EventCallback */ event_callback_; |
666 bool dispatching_to_observer_list_; | 659 bool dispatching_to_observer_list_; |
667 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 660 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
668 | 661 |
669 std::string process_name_; | 662 std::string process_name_; |
670 base::hash_map<int, std::string> process_labels_; | 663 base::hash_map<int, std::string> process_labels_; |
671 int process_sort_index_; | 664 int process_sort_index_; |
672 base::hash_map<int, int> thread_sort_indices_; | 665 base::hash_map<int, int> thread_sort_indices_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 709 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
717 subtle::AtomicWord generation_; | 710 subtle::AtomicWord generation_; |
718 | 711 |
719 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 712 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
720 }; | 713 }; |
721 | 714 |
722 } // namespace debug | 715 } // namespace debug |
723 } // namespace base | 716 } // namespace base |
724 | 717 |
725 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 718 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |