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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 TraceEvent(); | 101 TraceEvent(); |
102 ~TraceEvent(); | 102 ~TraceEvent(); |
103 | 103 |
104 // We don't need to copy TraceEvent except when TraceEventBuffer is cloned. | 104 // We don't need to copy TraceEvent except when TraceEventBuffer is cloned. |
105 // Use explicit copy method to avoid accidentally misuse of copy. | 105 // Use explicit copy method to avoid accidentally misuse of copy. |
106 void CopyFrom(const TraceEvent& other); | 106 void CopyFrom(const TraceEvent& other); |
107 | 107 |
108 void Initialize( | 108 void Initialize( |
109 int thread_id, | 109 int thread_id, |
110 TimeTicks timestamp, | 110 TraceTicks timestamp, |
111 TimeTicks thread_timestamp, | 111 ThreadTicks thread_timestamp, |
112 char phase, | 112 char phase, |
113 const unsigned char* category_group_enabled, | 113 const unsigned char* category_group_enabled, |
114 const char* name, | 114 const char* name, |
115 unsigned long long id, | 115 unsigned long long id, |
116 int num_args, | 116 int num_args, |
117 const char** arg_names, | 117 const char** arg_names, |
118 const unsigned char* arg_types, | 118 const unsigned char* arg_types, |
119 const unsigned long long* arg_values, | 119 const unsigned long long* arg_values, |
120 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 120 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
121 unsigned char flags); | 121 unsigned char flags); |
122 | 122 |
123 void Reset(); | 123 void Reset(); |
124 | 124 |
125 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); | 125 void UpdateDuration(const TraceTicks& now, const ThreadTicks& thread_now); |
126 | 126 |
127 // Serialize event data to JSON | 127 // Serialize event data to JSON |
128 typedef base::Callback<bool(const char* category_group_name, | 128 typedef base::Callback<bool(const char* category_group_name, |
129 const char* event_name)> ArgumentFilterPredicate; | 129 const char* event_name)> ArgumentFilterPredicate; |
130 void AppendAsJSON( | 130 void AppendAsJSON( |
131 std::string* out, | 131 std::string* out, |
132 const ArgumentFilterPredicate& argument_filter_predicate) const; | 132 const ArgumentFilterPredicate& argument_filter_predicate) const; |
133 void AppendPrettyPrinted(std::ostringstream* out) const; | 133 void AppendPrettyPrinted(std::ostringstream* out) const; |
134 | 134 |
135 static void AppendValueAsJSON(unsigned char type, | 135 static void AppendValueAsJSON(unsigned char type, |
136 TraceValue value, | 136 TraceValue value, |
137 std::string* out); | 137 std::string* out); |
138 | 138 |
139 TimeTicks timestamp() const { return timestamp_; } | 139 TraceTicks timestamp() const { return timestamp_; } |
140 TimeTicks thread_timestamp() const { return thread_timestamp_; } | 140 ThreadTicks thread_timestamp() const { return thread_timestamp_; } |
141 char phase() const { return phase_; } | 141 char phase() const { return phase_; } |
142 int thread_id() const { return thread_id_; } | 142 int thread_id() const { return thread_id_; } |
143 TimeDelta duration() const { return duration_; } | 143 TimeDelta duration() const { return duration_; } |
144 TimeDelta thread_duration() const { return thread_duration_; } | 144 TimeDelta thread_duration() const { return thread_duration_; } |
145 unsigned long long id() const { return id_; } | 145 unsigned long long id() const { return id_; } |
146 unsigned char flags() const { return flags_; } | 146 unsigned char flags() const { return flags_; } |
147 | 147 |
148 // Exposed for unittesting: | 148 // Exposed for unittesting: |
149 | 149 |
150 const base::RefCountedString* parameter_copy_storage() const { | 150 const base::RefCountedString* parameter_copy_storage() const { |
151 return parameter_copy_storage_.get(); | 151 return parameter_copy_storage_.get(); |
152 } | 152 } |
153 | 153 |
154 const unsigned char* category_group_enabled() const { | 154 const unsigned char* category_group_enabled() const { |
155 return category_group_enabled_; | 155 return category_group_enabled_; |
156 } | 156 } |
157 | 157 |
158 const char* name() const { return name_; } | 158 const char* name() const { return name_; } |
159 | 159 |
160 #if defined(OS_ANDROID) | 160 #if defined(OS_ANDROID) |
161 void SendToATrace(); | 161 void SendToATrace(); |
162 #endif | 162 #endif |
163 | 163 |
164 private: | 164 private: |
165 // Note: these are ordered by size (largest first) for optimal packing. | 165 // Note: these are ordered by size (largest first) for optimal packing. |
166 TimeTicks timestamp_; | 166 TraceTicks timestamp_; |
167 TimeTicks thread_timestamp_; | 167 ThreadTicks thread_timestamp_; |
168 TimeDelta duration_; | 168 TimeDelta duration_; |
169 TimeDelta thread_duration_; | 169 TimeDelta thread_duration_; |
170 // id_ can be used to store phase-specific data. | 170 // id_ can be used to store phase-specific data. |
171 unsigned long long id_; | 171 unsigned long long id_; |
172 TraceValue arg_values_[kTraceMaxNumArgs]; | 172 TraceValue arg_values_[kTraceMaxNumArgs]; |
173 const char* arg_names_[kTraceMaxNumArgs]; | 173 const char* arg_names_[kTraceMaxNumArgs]; |
174 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; | 174 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; |
175 const unsigned char* category_group_enabled_; | 175 const unsigned char* category_group_enabled_; |
176 const char* name_; | 176 const char* name_; |
177 scoped_refptr<base::RefCountedString> parameter_copy_storage_; | 177 scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 372 |
373 // Not using base::Callback because of its limited by 7 parameters. | 373 // Not using base::Callback because of its limited by 7 parameters. |
374 // Also, using primitive type allows directly passing callback from WebCore. | 374 // Also, using primitive type allows directly passing callback from WebCore. |
375 // WARNING: It is possible for the previously set callback to be called | 375 // WARNING: It is possible for the previously set callback to be called |
376 // after a call to SetEventCallbackEnabled() that replaces or a call to | 376 // after a call to SetEventCallbackEnabled() that replaces or a call to |
377 // SetEventCallbackDisabled() that disables the callback. | 377 // SetEventCallbackDisabled() that disables the callback. |
378 // This callback may be invoked on any thread. | 378 // This callback may be invoked on any thread. |
379 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs | 379 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs |
380 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the | 380 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the |
381 // interface simple. | 381 // interface simple. |
382 typedef void (*EventCallback)(TimeTicks timestamp, | 382 typedef void (*EventCallback)(TraceTicks timestamp, |
383 char phase, | 383 char phase, |
384 const unsigned char* category_group_enabled, | 384 const unsigned char* category_group_enabled, |
385 const char* name, | 385 const char* name, |
386 unsigned long long id, | 386 unsigned long long id, |
387 int num_args, | 387 int num_args, |
388 const char* const arg_names[], | 388 const char* const arg_names[], |
389 const unsigned char arg_types[], | 389 const unsigned char arg_types[], |
390 const unsigned long long arg_values[], | 390 const unsigned long long arg_values[], |
391 unsigned char flags); | 391 unsigned char flags); |
392 | 392 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 const unsigned char* arg_types, | 432 const unsigned char* arg_types, |
433 const unsigned long long* arg_values, | 433 const unsigned long long* arg_values, |
434 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 434 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
435 unsigned char flags); | 435 unsigned char flags); |
436 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 436 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
437 char phase, | 437 char phase, |
438 const unsigned char* category_group_enabled, | 438 const unsigned char* category_group_enabled, |
439 const char* name, | 439 const char* name, |
440 unsigned long long id, | 440 unsigned long long id, |
441 int thread_id, | 441 int thread_id, |
442 const TimeTicks& timestamp, | 442 const TraceTicks& timestamp, |
443 int num_args, | 443 int num_args, |
444 const char** arg_names, | 444 const char** arg_names, |
445 const unsigned char* arg_types, | 445 const unsigned char* arg_types, |
446 const unsigned long long* arg_values, | 446 const unsigned long long* arg_values, |
447 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 447 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
448 unsigned char flags); | 448 unsigned char flags); |
449 static void AddTraceEventEtw(char phase, | 449 static void AddTraceEventEtw(char phase, |
450 const char* category_group, | 450 const char* category_group, |
451 const void* id, | 451 const void* id, |
452 const char* extra); | 452 const char* extra); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 // Processes can have labels in addition to their names. Use labels, for | 495 // Processes can have labels in addition to their names. Use labels, for |
496 // instance, to list out the web page titles that a process is handling. | 496 // instance, to list out the web page titles that a process is handling. |
497 void UpdateProcessLabel(int label_id, const std::string& current_label); | 497 void UpdateProcessLabel(int label_id, const std::string& current_label); |
498 void RemoveProcessLabel(int label_id); | 498 void RemoveProcessLabel(int label_id); |
499 | 499 |
500 // Thread sort indices, if set, override the order of a thread will appear | 500 // Thread sort indices, if set, override the order of a thread will appear |
501 // within its process in the trace viewer. Threads are sorted first on their | 501 // within its process in the trace viewer. Threads are sorted first on their |
502 // sort index, ascending, then by their name, and then tid. | 502 // sort index, ascending, then by their name, and then tid. |
503 void SetThreadSortIndex(PlatformThreadId , int sort_index); | 503 void SetThreadSortIndex(PlatformThreadId , int sort_index); |
504 | 504 |
505 // Allow setting an offset between the current TimeTicks time and the time | 505 // Allow setting an offset between the current TraceTicks time and the time |
506 // that should be reported. | 506 // that should be reported. |
507 void SetTimeOffset(TimeDelta offset); | 507 void SetTimeOffset(TimeDelta offset); |
508 | 508 |
509 size_t GetObserverCountForTest() const; | 509 size_t GetObserverCountForTest() const; |
510 | 510 |
511 // Call this method if the current thread may block the message loop to | 511 // Call this method if the current thread may block the message loop to |
512 // prevent the thread from using the thread-local buffer because the thread | 512 // prevent the thread from using the thread-local buffer because the thread |
513 // may not handle the flush request in time causing lost of unflushed events. | 513 // may not handle the flush request in time causing lost of unflushed events. |
514 void SetCurrentThreadBlocksMessageLoop(); | 514 void SetCurrentThreadBlocksMessageLoop(); |
515 | 515 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 InternalTraceOptions trace_options() const { | 559 InternalTraceOptions trace_options() const { |
560 return static_cast<InternalTraceOptions>( | 560 return static_cast<InternalTraceOptions>( |
561 subtle::NoBarrier_Load(&trace_options_)); | 561 subtle::NoBarrier_Load(&trace_options_)); |
562 } | 562 } |
563 | 563 |
564 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 564 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
565 TraceBuffer* CreateTraceBuffer(); | 565 TraceBuffer* CreateTraceBuffer(); |
566 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); | 566 TraceBuffer* CreateTraceBufferVectorOfSize(size_t max_chunks); |
567 | 567 |
568 std::string EventToConsoleMessage(unsigned char phase, | 568 std::string EventToConsoleMessage(unsigned char phase, |
569 const TimeTicks& timestamp, | 569 const TraceTicks& timestamp, |
570 TraceEvent* trace_event); | 570 TraceEvent* trace_event); |
571 | 571 |
572 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 572 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
573 bool check_buffer_is_full); | 573 bool check_buffer_is_full); |
574 void CheckIfBufferIsFullWhileLocked(); | 574 void CheckIfBufferIsFullWhileLocked(); |
575 void SetDisabledWhileLocked(); | 575 void SetDisabledWhileLocked(); |
576 | 576 |
577 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 577 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
578 OptionalAutoLock* lock); | 578 OptionalAutoLock* lock); |
579 | 579 |
580 // |generation| is used in the following callbacks to check if the callback | 580 // |generation| is used in the following callbacks to check if the callback |
581 // is called for the flush of the current |logged_events_|. | 581 // is called for the flush of the current |logged_events_|. |
582 void FlushCurrentThread(int generation); | 582 void FlushCurrentThread(int generation); |
583 // Usually it runs on a different thread. | 583 // Usually it runs on a different thread. |
584 static void ConvertTraceEventsToTraceFormat( | 584 static void ConvertTraceEventsToTraceFormat( |
585 scoped_ptr<TraceBuffer> logged_events, | 585 scoped_ptr<TraceBuffer> logged_events, |
586 const TraceLog::OutputCallback& flush_output_callback, | 586 const TraceLog::OutputCallback& flush_output_callback, |
587 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate); | 587 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate); |
588 void FinishFlush(int generation); | 588 void FinishFlush(int generation); |
589 void OnFlushTimeout(int generation); | 589 void OnFlushTimeout(int generation); |
590 | 590 |
591 int generation() const { | 591 int generation() const { |
592 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 592 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
593 } | 593 } |
594 bool CheckGeneration(int generation) const { | 594 bool CheckGeneration(int generation) const { |
595 return generation == this->generation(); | 595 return generation == this->generation(); |
596 } | 596 } |
597 void UseNextTraceBuffer(); | 597 void UseNextTraceBuffer(); |
598 | 598 |
599 TimeTicks OffsetNow() const { | 599 TraceTicks OffsetNow() const { |
600 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); | 600 return OffsetTimestamp(TraceTicks::Now()); |
601 } | 601 } |
602 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { | 602 TraceTicks OffsetTimestamp(const TraceTicks& timestamp) const { |
603 return timestamp - time_offset_; | 603 return timestamp - time_offset_; |
604 } | 604 } |
605 | 605 |
606 // Internal representation of trace options since we store the currently used | 606 // Internal representation of trace options since we store the currently used |
607 // trace option as an AtomicWord. | 607 // trace option as an AtomicWord. |
608 static const InternalTraceOptions kInternalNone; | 608 static const InternalTraceOptions kInternalNone; |
609 static const InternalTraceOptions kInternalRecordUntilFull; | 609 static const InternalTraceOptions kInternalRecordUntilFull; |
610 static const InternalTraceOptions kInternalRecordContinuously; | 610 static const InternalTraceOptions kInternalRecordContinuously; |
611 static const InternalTraceOptions kInternalEchoToConsole; | 611 static const InternalTraceOptions kInternalEchoToConsole; |
612 static const InternalTraceOptions kInternalEnableSampling; | 612 static const InternalTraceOptions kInternalEnableSampling; |
(...skipping 13 matching lines...) Expand all Loading... |
626 bool dispatching_to_observer_list_; | 626 bool dispatching_to_observer_list_; |
627 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 627 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
628 | 628 |
629 std::string process_name_; | 629 std::string process_name_; |
630 base::hash_map<int, std::string> process_labels_; | 630 base::hash_map<int, std::string> process_labels_; |
631 int process_sort_index_; | 631 int process_sort_index_; |
632 base::hash_map<int, int> thread_sort_indices_; | 632 base::hash_map<int, int> thread_sort_indices_; |
633 base::hash_map<int, std::string> thread_names_; | 633 base::hash_map<int, std::string> thread_names_; |
634 | 634 |
635 // The following two maps are used only when ECHO_TO_CONSOLE. | 635 // The following two maps are used only when ECHO_TO_CONSOLE. |
636 base::hash_map<int, std::stack<TimeTicks> > thread_event_start_times_; | 636 base::hash_map<int, std::stack<TraceTicks> > thread_event_start_times_; |
637 base::hash_map<std::string, int> thread_colors_; | 637 base::hash_map<std::string, int> thread_colors_; |
638 | 638 |
639 TimeTicks buffer_limit_reached_timestamp_; | 639 TraceTicks buffer_limit_reached_timestamp_; |
640 | 640 |
641 // XORed with TraceID to make it unlikely to collide with other processes. | 641 // XORed with TraceID to make it unlikely to collide with other processes. |
642 unsigned long long process_id_hash_; | 642 unsigned long long process_id_hash_; |
643 | 643 |
644 int process_id_; | 644 int process_id_; |
645 | 645 |
646 TimeDelta time_offset_; | 646 TimeDelta time_offset_; |
647 | 647 |
648 // Allow tests to wake up when certain events occur. | 648 // Allow tests to wake up when certain events occur. |
649 WatchEventCallback watch_event_callback_; | 649 WatchEventCallback watch_event_callback_; |
(...skipping 30 matching lines...) Expand all Loading... |
680 subtle::AtomicWord generation_; | 680 subtle::AtomicWord generation_; |
681 bool use_worker_thread_; | 681 bool use_worker_thread_; |
682 | 682 |
683 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 683 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
684 }; | 684 }; |
685 | 685 |
686 } // namespace trace_event | 686 } // namespace trace_event |
687 } // namespace base | 687 } // namespace base |
688 | 688 |
689 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 689 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
OLD | NEW |