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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 const char* category) const; | 357 const char* category) const; |
358 | 358 |
359 StringList included_; | 359 StringList included_; |
360 StringList disabled_; | 360 StringList disabled_; |
361 StringList excluded_; | 361 StringList excluded_; |
362 StringList delays_; | 362 StringList delays_; |
363 }; | 363 }; |
364 | 364 |
365 class TraceSamplingThread; | 365 class TraceSamplingThread; |
366 | 366 |
367 // Options determines how the trace buffer stores data. | |
368 enum TraceRecordMode { | |
369 // Record until the trace buffer is full. | |
370 RECORD_UNTIL_FULL, | |
371 | |
372 // Record until the user ends the trace. The trace buffer is a fixed size | |
373 // and we use it as a ring buffer during recording. | |
374 RECORD_CONTINUOUSLY, | |
375 | |
376 // Echo to console. Events are discarded. | |
377 ECHO_TO_CONSOLE, | |
378 }; | |
379 | |
380 struct BASE_EXPORT TraceOptions { | |
381 | |
382 TraceOptions() | |
383 : record_mode(RECORD_UNTIL_FULL), | |
384 enable_sampling(false), | |
385 enable_systrace(false) {} | |
386 | |
387 TraceOptions(TraceRecordMode record_mode) | |
388 : record_mode(record_mode), | |
389 enable_sampling(false), | |
390 enable_systrace(false) {} | |
391 | |
392 TraceOptions& EnableSampling(bool option) { | |
nduca
2014/07/29 22:40:12
please make these go away, they dont add value.
| |
393 enable_sampling = option; | |
394 return *this; | |
395 } | |
396 | |
397 TraceOptions& EnableSystrace(bool option) { | |
398 enable_systrace = option; | |
399 return *this; | |
400 } | |
401 | |
402 explicit TraceOptions(const std::string& options); | |
403 | |
404 std::string ToString() const; | |
405 | |
406 TraceRecordMode record_mode; | |
407 bool enable_sampling; | |
408 bool enable_systrace; | |
409 }; | |
410 | |
367 class BASE_EXPORT TraceLog { | 411 class BASE_EXPORT TraceLog { |
368 public: | 412 public: |
369 enum Mode { | 413 enum Mode { |
370 DISABLED = 0, | 414 DISABLED = 0, |
371 RECORDING_MODE, | 415 RECORDING_MODE, |
372 MONITORING_MODE, | 416 MONITORING_MODE, |
373 }; | 417 }; |
374 | 418 |
375 // Options determines how the trace buffer stores data. | |
376 enum Options { | |
377 // Record until the trace buffer is full. | |
378 RECORD_UNTIL_FULL = 1 << 0, | |
379 | |
380 // Record until the user ends the trace. The trace buffer is a fixed size | |
381 // and we use it as a ring buffer during recording. | |
382 RECORD_CONTINUOUSLY = 1 << 1, | |
383 | |
384 // Enable the sampling profiler in the recording mode. | |
385 ENABLE_SAMPLING = 1 << 2, | |
386 | |
387 // Echo to console. Events are discarded. | |
388 ECHO_TO_CONSOLE = 1 << 3, | |
389 }; | |
390 | |
391 // The pointer returned from GetCategoryGroupEnabledInternal() points to a | 419 // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
392 // value with zero or more of the following bits. Used in this class only. | 420 // value with zero or more of the following bits. Used in this class only. |
393 // The TRACE_EVENT macros should only use the value as a bool. | 421 // The TRACE_EVENT macros should only use the value as a bool. |
394 // These values must be in sync with macro values in TraceEvent.h in Blink. | 422 // These values must be in sync with macro values in TraceEvent.h in Blink. |
395 enum CategoryGroupEnabledFlags { | 423 enum CategoryGroupEnabledFlags { |
396 // Category group enabled for the recording mode. | 424 // Category group enabled for the recording mode. |
397 ENABLED_FOR_RECORDING = 1 << 0, | 425 ENABLED_FOR_RECORDING = 1 << 0, |
398 // Category group enabled for the monitoring mode. | 426 // Category group enabled for the monitoring mode. |
399 ENABLED_FOR_MONITORING = 1 << 1, | 427 ENABLED_FOR_MONITORING = 1 << 1, |
400 // Category group enabled by SetEventCallbackEnabled(). | 428 // Category group enabled by SetEventCallbackEnabled(). |
401 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, | 429 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, |
402 }; | 430 }; |
403 | 431 |
404 static TraceLog* GetInstance(); | 432 static TraceLog* GetInstance(); |
405 | 433 |
406 // Get set of known category groups. This can change as new code paths are | 434 // Get set of known category groups. This can change as new code paths are |
407 // reached. The known category groups are inserted into |category_groups|. | 435 // reached. The known category groups are inserted into |category_groups|. |
408 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); | 436 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); |
409 | 437 |
410 // Retrieves a copy (for thread-safety) of the current CategoryFilter. | 438 // Retrieves a copy (for thread-safety) of the current CategoryFilter. |
411 CategoryFilter GetCurrentCategoryFilter(); | 439 CategoryFilter GetCurrentCategoryFilter(); |
412 | 440 |
413 Options trace_options() const { | 441 // Retrieves a copy (for thread-safety) of the current TraceOptions. |
414 return static_cast<Options>(subtle::NoBarrier_Load(&trace_options_)); | 442 TraceOptions GetCurrentTraceOptions() const; |
415 } | |
416 | 443 |
417 // Enables normal tracing (recording trace events in the trace buffer). | 444 // Enables normal tracing (recording trace events in the trace buffer). |
418 // See CategoryFilter comments for details on how to control what categories | 445 // See CategoryFilter comments for details on how to control what categories |
419 // will be traced. If tracing has already been enabled, |category_filter| will | 446 // will be traced. If tracing has already been enabled, |category_filter| will |
420 // be merged into the current category filter. | 447 // be merged into the current category filter. |
421 void SetEnabled(const CategoryFilter& category_filter, | 448 void SetEnabled(const CategoryFilter& category_filter, |
422 Mode mode, Options options); | 449 Mode mode, TraceOptions options); |
423 | 450 |
424 // Disables normal tracing for all categories. | 451 // Disables normal tracing for all categories. |
425 void SetDisabled(); | 452 void SetDisabled(); |
426 | 453 |
427 bool IsEnabled() { return mode_ != DISABLED; } | 454 bool IsEnabled() { return mode_ != DISABLED; } |
428 | 455 |
429 // The number of times we have begun recording traces. If tracing is off, | 456 // The number of times we have begun recording traces. If tracing is off, |
430 // returns -1. If tracing is on, then it returns the number of times we have | 457 // returns -1. If tracing is on, then it returns the number of times we have |
431 // recorded a trace. By watching for this number to increment, you can | 458 // recorded a trace. By watching for this number to increment, you can |
432 // passively discover when a new trace has begun. This is then used to | 459 // passively discover when a new trace has begun. This is then used to |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 void SetTimeOffset(TimeDelta offset); | 619 void SetTimeOffset(TimeDelta offset); |
593 | 620 |
594 size_t GetObserverCountForTest() const; | 621 size_t GetObserverCountForTest() const; |
595 | 622 |
596 // Call this method if the current thread may block the message loop to | 623 // Call this method if the current thread may block the message loop to |
597 // prevent the thread from using the thread-local buffer because the thread | 624 // prevent the thread from using the thread-local buffer because the thread |
598 // may not handle the flush request in time causing lost of unflushed events. | 625 // may not handle the flush request in time causing lost of unflushed events. |
599 void SetCurrentThreadBlocksMessageLoop(); | 626 void SetCurrentThreadBlocksMessageLoop(); |
600 | 627 |
601 private: | 628 private: |
629 typedef unsigned int InternalTraceOptions; | |
630 | |
602 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 631 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
603 TraceBufferRingBufferGetReturnChunk); | 632 TraceBufferRingBufferGetReturnChunk); |
604 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 633 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
605 TraceBufferRingBufferHalfIteration); | 634 TraceBufferRingBufferHalfIteration); |
606 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 635 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
607 TraceBufferRingBufferFullIteration); | 636 TraceBufferRingBufferFullIteration); |
608 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | 637 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, |
609 TraceBufferVectorReportFull); | 638 TraceBufferVectorReportFull); |
639 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, | |
640 ConvertTraceOptionsToInternalOptions); | |
641 | |
610 | 642 |
611 // This allows constructor and destructor to be private and usable only | 643 // This allows constructor and destructor to be private and usable only |
612 // by the Singleton class. | 644 // by the Singleton class. |
613 friend struct DefaultSingletonTraits<TraceLog>; | 645 friend struct DefaultSingletonTraits<TraceLog>; |
614 | 646 |
615 // Enable/disable each category group based on the current mode_, | 647 // Enable/disable each category group based on the current mode_, |
616 // category_filter_, event_callback_ and event_callback_category_filter_. | 648 // category_filter_, event_callback_ and event_callback_category_filter_. |
617 // Enable the category group in the enabled mode if category_filter_ matches | 649 // Enable the category group in the enabled mode if category_filter_ matches |
618 // the category group, or event_callback_ is not null and | 650 // the category group, or event_callback_ is not null and |
619 // event_callback_category_filter_ matches the category group. | 651 // event_callback_category_filter_ matches the category group. |
620 void UpdateCategoryGroupEnabledFlags(); | 652 void UpdateCategoryGroupEnabledFlags(); |
621 void UpdateCategoryGroupEnabledFlag(size_t category_index); | 653 void UpdateCategoryGroupEnabledFlag(size_t category_index); |
622 | 654 |
623 // Configure synthetic delays based on the values set in the current | 655 // Configure synthetic delays based on the values set in the current |
624 // category filter. | 656 // category filter. |
625 void UpdateSyntheticDelaysFromCategoryFilter(); | 657 void UpdateSyntheticDelaysFromCategoryFilter(); |
626 | 658 |
659 InternalTraceOptions GetInternalOptionsFromTraceOptions( | |
660 const TraceOptions& options); | |
661 | |
627 class ThreadLocalEventBuffer; | 662 class ThreadLocalEventBuffer; |
628 class OptionalAutoLock; | 663 class OptionalAutoLock; |
629 | 664 |
630 TraceLog(); | 665 TraceLog(); |
631 ~TraceLog(); | 666 ~TraceLog(); |
632 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); | 667 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); |
633 void AddMetadataEventsWhileLocked(); | 668 void AddMetadataEventsWhileLocked(); |
634 | 669 |
670 InternalTraceOptions trace_options() const { | |
671 return static_cast<InternalTraceOptions>( | |
672 subtle::NoBarrier_Load(&trace_options_)); | |
673 } | |
674 | |
635 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 675 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
636 TraceBuffer* CreateTraceBuffer(); | 676 TraceBuffer* CreateTraceBuffer(); |
637 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); | 677 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); |
638 | 678 |
639 std::string EventToConsoleMessage(unsigned char phase, | 679 std::string EventToConsoleMessage(unsigned char phase, |
640 const TimeTicks& timestamp, | 680 const TimeTicks& timestamp, |
641 TraceEvent* trace_event); | 681 TraceEvent* trace_event); |
642 | 682 |
643 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 683 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
644 bool check_buffer_is_full); | 684 bool check_buffer_is_full); |
(...skipping 19 matching lines...) Expand all Loading... | |
664 } | 704 } |
665 void UseNextTraceBuffer(); | 705 void UseNextTraceBuffer(); |
666 | 706 |
667 TimeTicks OffsetNow() const { | 707 TimeTicks OffsetNow() const { |
668 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); | 708 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); |
669 } | 709 } |
670 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { | 710 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { |
671 return timestamp - time_offset_; | 711 return timestamp - time_offset_; |
672 } | 712 } |
673 | 713 |
714 // Internal representation of trace options since we store the currently used | |
715 // trace option as an AtomicWord. | |
716 static const InternalTraceOptions kInternalNone; | |
717 static const InternalTraceOptions kInternalRecordUntilFull; | |
718 static const InternalTraceOptions kInternalRecordContinuously; | |
719 static const InternalTraceOptions kInternalEchoToConsole; | |
720 static const InternalTraceOptions kInternalEnableSampling; | |
721 | |
674 // This lock protects TraceLog member accesses (except for members protected | 722 // This lock protects TraceLog member accesses (except for members protected |
675 // by thread_info_lock_) from arbitrary threads. | 723 // by thread_info_lock_) from arbitrary threads. |
676 mutable Lock lock_; | 724 mutable Lock lock_; |
677 // This lock protects accesses to thread_names_, thread_event_start_times_ | 725 // This lock protects accesses to thread_names_, thread_event_start_times_ |
678 // and thread_colors_. | 726 // and thread_colors_. |
679 Lock thread_info_lock_; | 727 Lock thread_info_lock_; |
680 int locked_line_; | 728 int locked_line_; |
681 Mode mode_; | 729 Mode mode_; |
682 int num_traces_recorded_; | 730 int num_traces_recorded_; |
683 scoped_ptr<TraceBuffer> logged_events_; | 731 scoped_ptr<TraceBuffer> logged_events_; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 785 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
738 subtle::AtomicWord generation_; | 786 subtle::AtomicWord generation_; |
739 | 787 |
740 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 788 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
741 }; | 789 }; |
742 | 790 |
743 } // namespace debug | 791 } // namespace debug |
744 } // namespace base | 792 } // namespace base |
745 | 793 |
746 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ | 794 #endif // BASE_DEBUG_TRACE_EVENT_IMPL_H_ |
OLD | NEW |