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