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_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
8 | 8 |
9 #include <stack> | 9 #include <stack> |
10 #include <string> | 10 #include <string> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 TraceEvent(); | 99 TraceEvent(); |
100 ~TraceEvent(); | 100 ~TraceEvent(); |
101 | 101 |
102 // We don't need to copy TraceEvent except when TraceEventBuffer is cloned. | 102 // We don't need to copy TraceEvent except when TraceEventBuffer is cloned. |
103 // Use explicit copy method to avoid accidentally misuse of copy. | 103 // Use explicit copy method to avoid accidentally misuse of copy. |
104 void CopyFrom(const TraceEvent& other); | 104 void CopyFrom(const TraceEvent& other); |
105 | 105 |
106 void Initialize( | 106 void Initialize( |
107 int thread_id, | 107 int thread_id, |
108 TimeTicks timestamp, | 108 TraceTicks timestamp, |
109 TimeTicks thread_timestamp, | 109 ThreadTicks thread_timestamp, |
110 char phase, | 110 char phase, |
111 const unsigned char* category_group_enabled, | 111 const unsigned char* category_group_enabled, |
112 const char* name, | 112 const char* name, |
113 unsigned long long id, | 113 unsigned long long id, |
114 int num_args, | 114 int num_args, |
115 const char** arg_names, | 115 const char** arg_names, |
116 const unsigned char* arg_types, | 116 const unsigned char* arg_types, |
117 const unsigned long long* arg_values, | 117 const unsigned long long* arg_values, |
118 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 118 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
119 unsigned char flags); | 119 unsigned char flags); |
120 | 120 |
121 void Reset(); | 121 void Reset(); |
122 | 122 |
123 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); | 123 void UpdateDuration(const TraceTicks& now, const ThreadTicks& thread_now); |
124 | 124 |
125 // Serialize event data to JSON | 125 // Serialize event data to JSON |
126 void AppendAsJSON(std::string* out) const; | 126 void AppendAsJSON(std::string* out) const; |
127 void AppendPrettyPrinted(std::ostringstream* out) const; | 127 void AppendPrettyPrinted(std::ostringstream* out) const; |
128 | 128 |
129 static void AppendValueAsJSON(unsigned char type, | 129 static void AppendValueAsJSON(unsigned char type, |
130 TraceValue value, | 130 TraceValue value, |
131 std::string* out); | 131 std::string* out); |
132 | 132 |
133 TimeTicks timestamp() const { return timestamp_; } | 133 TraceTicks timestamp() const { return timestamp_; } |
134 TimeTicks thread_timestamp() const { return thread_timestamp_; } | 134 ThreadTicks thread_timestamp() const { return thread_timestamp_; } |
135 char phase() const { return phase_; } | 135 char phase() const { return phase_; } |
136 int thread_id() const { return thread_id_; } | 136 int thread_id() const { return thread_id_; } |
137 TimeDelta duration() const { return duration_; } | 137 TimeDelta duration() const { return duration_; } |
138 TimeDelta thread_duration() const { return thread_duration_; } | 138 TimeDelta thread_duration() const { return thread_duration_; } |
139 unsigned long long id() const { return id_; } | 139 unsigned long long id() const { return id_; } |
140 unsigned char flags() const { return flags_; } | 140 unsigned char flags() const { return flags_; } |
141 | 141 |
142 // Exposed for unittesting: | 142 // Exposed for unittesting: |
143 | 143 |
144 const base::RefCountedString* parameter_copy_storage() const { | 144 const base::RefCountedString* parameter_copy_storage() const { |
145 return parameter_copy_storage_.get(); | 145 return parameter_copy_storage_.get(); |
146 } | 146 } |
147 | 147 |
148 const unsigned char* category_group_enabled() const { | 148 const unsigned char* category_group_enabled() const { |
149 return category_group_enabled_; | 149 return category_group_enabled_; |
150 } | 150 } |
151 | 151 |
152 const char* name() const { return name_; } | 152 const char* name() const { return name_; } |
153 | 153 |
154 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
155 void SendToATrace(); | 155 void SendToATrace(); |
156 #endif | 156 #endif |
157 | 157 |
158 private: | 158 private: |
159 // Note: these are ordered by size (largest first) for optimal packing. | 159 // Note: these are ordered by size (largest first) for optimal packing. |
160 TimeTicks timestamp_; | 160 TraceTicks timestamp_; |
161 TimeTicks thread_timestamp_; | 161 ThreadTicks thread_timestamp_; |
162 TimeDelta duration_; | 162 TimeDelta duration_; |
163 TimeDelta thread_duration_; | 163 TimeDelta thread_duration_; |
164 // id_ can be used to store phase-specific data. | 164 // id_ can be used to store phase-specific data. |
165 unsigned long long id_; | 165 unsigned long long id_; |
166 TraceValue arg_values_[kTraceMaxNumArgs]; | 166 TraceValue arg_values_[kTraceMaxNumArgs]; |
167 const char* arg_names_[kTraceMaxNumArgs]; | 167 const char* arg_names_[kTraceMaxNumArgs]; |
168 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; | 168 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; |
169 const unsigned char* category_group_enabled_; | 169 const unsigned char* category_group_enabled_; |
170 const char* name_; | 170 const char* name_; |
171 scoped_refptr<base::RefCountedString> parameter_copy_storage_; | 171 scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 511 |
512 // Not using base::Callback because of its limited by 7 parameters. | 512 // Not using base::Callback because of its limited by 7 parameters. |
513 // Also, using primitive type allows directly passing callback from WebCore. | 513 // Also, using primitive type allows directly passing callback from WebCore. |
514 // WARNING: It is possible for the previously set callback to be called | 514 // WARNING: It is possible for the previously set callback to be called |
515 // after a call to SetEventCallbackEnabled() that replaces or a call to | 515 // after a call to SetEventCallbackEnabled() that replaces or a call to |
516 // SetEventCallbackDisabled() that disables the callback. | 516 // SetEventCallbackDisabled() that disables the callback. |
517 // This callback may be invoked on any thread. | 517 // This callback may be invoked on any thread. |
518 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs | 518 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs |
519 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the | 519 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the |
520 // interface simple. | 520 // interface simple. |
521 typedef void (*EventCallback)(TimeTicks timestamp, | 521 typedef void (*EventCallback)(TraceTicks timestamp, |
522 char phase, | 522 char phase, |
523 const unsigned char* category_group_enabled, | 523 const unsigned char* category_group_enabled, |
524 const char* name, | 524 const char* name, |
525 unsigned long long id, | 525 unsigned long long id, |
526 int num_args, | 526 int num_args, |
527 const char* const arg_names[], | 527 const char* const arg_names[], |
528 const unsigned char arg_types[], | 528 const unsigned char arg_types[], |
529 const unsigned long long arg_values[], | 529 const unsigned long long arg_values[], |
530 unsigned char flags); | 530 unsigned char flags); |
531 | 531 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 const unsigned char* arg_types, | 569 const unsigned char* arg_types, |
570 const unsigned long long* arg_values, | 570 const unsigned long long* arg_values, |
571 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 571 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
572 unsigned char flags); | 572 unsigned char flags); |
573 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 573 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
574 char phase, | 574 char phase, |
575 const unsigned char* category_group_enabled, | 575 const unsigned char* category_group_enabled, |
576 const char* name, | 576 const char* name, |
577 unsigned long long id, | 577 unsigned long long id, |
578 int thread_id, | 578 int thread_id, |
579 const TimeTicks& timestamp, | 579 const TraceTicks& timestamp, |
580 int num_args, | 580 int num_args, |
581 const char** arg_names, | 581 const char** arg_names, |
582 const unsigned char* arg_types, | 582 const unsigned char* arg_types, |
583 const unsigned long long* arg_values, | 583 const unsigned long long* arg_values, |
584 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 584 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
585 unsigned char flags); | 585 unsigned char flags); |
586 static void AddTraceEventEtw(char phase, | 586 static void AddTraceEventEtw(char phase, |
587 const char* category_group, | 587 const char* category_group, |
588 const void* id, | 588 const void* id, |
589 const char* extra); | 589 const char* extra); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 // Processes can have labels in addition to their names. Use labels, for | 632 // Processes can have labels in addition to their names. Use labels, for |
633 // instance, to list out the web page titles that a process is handling. | 633 // instance, to list out the web page titles that a process is handling. |
634 void UpdateProcessLabel(int label_id, const std::string& current_label); | 634 void UpdateProcessLabel(int label_id, const std::string& current_label); |
635 void RemoveProcessLabel(int label_id); | 635 void RemoveProcessLabel(int label_id); |
636 | 636 |
637 // Thread sort indices, if set, override the order of a thread will appear | 637 // Thread sort indices, if set, override the order of a thread will appear |
638 // within its process in the trace viewer. Threads are sorted first on their | 638 // within its process in the trace viewer. Threads are sorted first on their |
639 // sort index, ascending, then by their name, and then tid. | 639 // sort index, ascending, then by their name, and then tid. |
640 void SetThreadSortIndex(PlatformThreadId , int sort_index); | 640 void SetThreadSortIndex(PlatformThreadId , int sort_index); |
641 | 641 |
642 // Allow setting an offset between the current TimeTicks time and the time | 642 // Allow setting an offset between the current TraceTicks time and the time |
643 // that should be reported. | 643 // that should be reported. |
644 void SetTimeOffset(TimeDelta offset); | 644 void SetTimeOffset(TimeDelta offset); |
645 | 645 |
646 size_t GetObserverCountForTest() const; | 646 size_t GetObserverCountForTest() const; |
647 | 647 |
648 // Call this method if the current thread may block the message loop to | 648 // Call this method if the current thread may block the message loop to |
649 // prevent the thread from using the thread-local buffer because the thread | 649 // prevent the thread from using the thread-local buffer because the thread |
650 // may not handle the flush request in time causing lost of unflushed events. | 650 // may not handle the flush request in time causing lost of unflushed events. |
651 void SetCurrentThreadBlocksMessageLoop(); | 651 void SetCurrentThreadBlocksMessageLoop(); |
652 | 652 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 InternalTraceOptions trace_options() const { | 696 InternalTraceOptions trace_options() const { |
697 return static_cast<InternalTraceOptions>( | 697 return static_cast<InternalTraceOptions>( |
698 subtle::NoBarrier_Load(&trace_options_)); | 698 subtle::NoBarrier_Load(&trace_options_)); |
699 } | 699 } |
700 | 700 |
701 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 701 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
702 TraceBuffer* CreateTraceBuffer(); | 702 TraceBuffer* CreateTraceBuffer(); |
703 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); | 703 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); |
704 | 704 |
705 std::string EventToConsoleMessage(unsigned char phase, | 705 std::string EventToConsoleMessage(unsigned char phase, |
706 const TimeTicks& timestamp, | 706 const TraceTicks& timestamp, |
707 TraceEvent* trace_event); | 707 TraceEvent* trace_event); |
708 | 708 |
709 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 709 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
710 bool check_buffer_is_full); | 710 bool check_buffer_is_full); |
711 void CheckIfBufferIsFullWhileLocked(); | 711 void CheckIfBufferIsFullWhileLocked(); |
712 void SetDisabledWhileLocked(); | 712 void SetDisabledWhileLocked(); |
713 | 713 |
714 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 714 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
715 OptionalAutoLock* lock); | 715 OptionalAutoLock* lock); |
716 | 716 |
717 // |generation| is used in the following callbacks to check if the callback | 717 // |generation| is used in the following callbacks to check if the callback |
718 // is called for the flush of the current |logged_events_|. | 718 // is called for the flush of the current |logged_events_|. |
719 void FlushCurrentThread(int generation); | 719 void FlushCurrentThread(int generation); |
720 // Usually it runs on a different thread. | 720 // Usually it runs on a different thread. |
721 static void ConvertTraceEventsToTraceFormat( | 721 static void ConvertTraceEventsToTraceFormat( |
722 scoped_ptr<TraceBuffer> logged_events, | 722 scoped_ptr<TraceBuffer> logged_events, |
723 const TraceLog::OutputCallback& flush_output_callback); | 723 const TraceLog::OutputCallback& flush_output_callback); |
724 void FinishFlush(int generation); | 724 void FinishFlush(int generation); |
725 void OnFlushTimeout(int generation); | 725 void OnFlushTimeout(int generation); |
726 | 726 |
727 int generation() const { | 727 int generation() const { |
728 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 728 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
729 } | 729 } |
730 bool CheckGeneration(int generation) const { | 730 bool CheckGeneration(int generation) const { |
731 return generation == this->generation(); | 731 return generation == this->generation(); |
732 } | 732 } |
733 void UseNextTraceBuffer(); | 733 void UseNextTraceBuffer(); |
734 | 734 |
735 TimeTicks OffsetNow() const { | 735 TraceTicks OffsetNow() const { |
736 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); | 736 return OffsetTimestamp(TraceTicks::Now()); |
737 } | 737 } |
738 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { | 738 TraceTicks OffsetTimestamp(const TraceTicks& timestamp) const { |
739 return timestamp - time_offset_; | 739 return timestamp - time_offset_; |
740 } | 740 } |
741 | 741 |
742 // Internal representation of trace options since we store the currently used | 742 // Internal representation of trace options since we store the currently used |
743 // trace option as an AtomicWord. | 743 // trace option as an AtomicWord. |
744 static const InternalTraceOptions kInternalNone; | 744 static const InternalTraceOptions kInternalNone; |
745 static const InternalTraceOptions kInternalRecordUntilFull; | 745 static const InternalTraceOptions kInternalRecordUntilFull; |
746 static const InternalTraceOptions kInternalRecordContinuously; | 746 static const InternalTraceOptions kInternalRecordContinuously; |
747 static const InternalTraceOptions kInternalEchoToConsole; | 747 static const InternalTraceOptions kInternalEchoToConsole; |
748 static const InternalTraceOptions kInternalEnableSampling; | 748 static const InternalTraceOptions kInternalEnableSampling; |
(...skipping 12 matching lines...) Expand all Loading... |
761 bool dispatching_to_observer_list_; | 761 bool dispatching_to_observer_list_; |
762 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 762 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
763 | 763 |
764 std::string process_name_; | 764 std::string process_name_; |
765 base::hash_map<int, std::string> process_labels_; | 765 base::hash_map<int, std::string> process_labels_; |
766 int process_sort_index_; | 766 int process_sort_index_; |
767 base::hash_map<int, int> thread_sort_indices_; | 767 base::hash_map<int, int> thread_sort_indices_; |
768 base::hash_map<int, std::string> thread_names_; | 768 base::hash_map<int, std::string> thread_names_; |
769 | 769 |
770 // The following two maps are used only when ECHO_TO_CONSOLE. | 770 // The following two maps are used only when ECHO_TO_CONSOLE. |
771 base::hash_map<int, std::stack<TimeTicks> > thread_event_start_times_; | 771 base::hash_map<int, std::stack<TraceTicks> > thread_event_start_times_; |
772 base::hash_map<std::string, int> thread_colors_; | 772 base::hash_map<std::string, int> thread_colors_; |
773 | 773 |
774 TimeTicks buffer_limit_reached_timestamp_; | 774 TraceTicks buffer_limit_reached_timestamp_; |
775 | 775 |
776 // XORed with TraceID to make it unlikely to collide with other processes. | 776 // XORed with TraceID to make it unlikely to collide with other processes. |
777 unsigned long long process_id_hash_; | 777 unsigned long long process_id_hash_; |
778 | 778 |
779 int process_id_; | 779 int process_id_; |
780 | 780 |
781 TimeDelta time_offset_; | 781 TimeDelta time_offset_; |
782 | 782 |
783 // Allow tests to wake up when certain events occur. | 783 // Allow tests to wake up when certain events occur. |
784 WatchEventCallback watch_event_callback_; | 784 WatchEventCallback watch_event_callback_; |
(...skipping 29 matching lines...) Expand all Loading... |
814 subtle::AtomicWord generation_; | 814 subtle::AtomicWord generation_; |
815 bool use_worker_thread_; | 815 bool use_worker_thread_; |
816 | 816 |
817 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 817 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
818 }; | 818 }; |
819 | 819 |
820 } // namespace trace_event | 820 } // namespace trace_event |
821 } // namespace base | 821 } // namespace base |
822 | 822 |
823 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 823 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
OLD | NEW |