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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 const unsigned char* arg_types, | 115 const unsigned char* arg_types, |
116 const unsigned long long* arg_values, | 116 const unsigned long long* arg_values, |
117 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 117 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
118 unsigned char flags); | 118 unsigned char flags); |
119 | 119 |
120 void Reset(); | 120 void Reset(); |
121 | 121 |
122 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); | 122 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); |
123 | 123 |
124 // Serialize event data to JSON | 124 // Serialize event data to JSON |
125 void AppendAsJSON(std::string* out) const; | 125 typedef base::Callback<bool(const char* category_group_name, |
126 const char* event_name)> EventFilterPredicate; | |
127 void AppendAsJSON(std::string* out, | |
128 const EventFilterPredicate& event_filter_predicate) const; | |
126 void AppendPrettyPrinted(std::ostringstream* out) const; | 129 void AppendPrettyPrinted(std::ostringstream* out) const; |
127 | 130 |
128 static void AppendValueAsJSON(unsigned char type, | 131 static void AppendValueAsJSON(unsigned char type, |
129 TraceValue value, | 132 TraceValue value, |
130 std::string* out); | 133 std::string* out); |
131 | 134 |
132 TimeTicks timestamp() const { return timestamp_; } | 135 TimeTicks timestamp() const { return timestamp_; } |
133 TimeTicks thread_timestamp() const { return thread_timestamp_; } | 136 TimeTicks thread_timestamp() const { return thread_timestamp_; } |
134 char phase() const { return phase_; } | 137 char phase() const { return phase_; } |
135 int thread_id() const { return thread_id_; } | 138 int thread_id() const { return thread_id_; } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 ECHO_TO_CONSOLE, | 379 ECHO_TO_CONSOLE, |
377 | 380 |
378 // Record until the trace buffer is full, but with a huge buffer size. | 381 // Record until the trace buffer is full, but with a huge buffer size. |
379 RECORD_AS_MUCH_AS_POSSIBLE | 382 RECORD_AS_MUCH_AS_POSSIBLE |
380 }; | 383 }; |
381 | 384 |
382 struct BASE_EXPORT TraceOptions { | 385 struct BASE_EXPORT TraceOptions { |
383 TraceOptions() | 386 TraceOptions() |
384 : record_mode(RECORD_UNTIL_FULL), | 387 : record_mode(RECORD_UNTIL_FULL), |
385 enable_sampling(false), | 388 enable_sampling(false), |
386 enable_systrace(false) {} | 389 enable_systrace(false), |
390 enable_args_whitelist(false) {} | |
387 | 391 |
388 explicit TraceOptions(TraceRecordMode record_mode) | 392 explicit TraceOptions(TraceRecordMode record_mode) |
389 : record_mode(record_mode), | 393 : record_mode(record_mode), |
390 enable_sampling(false), | 394 enable_sampling(false), |
391 enable_systrace(false) {} | 395 enable_systrace(false), |
396 enable_args_whitelist(false) {} | |
nduca
2015/05/01 03:09:03
Should devtools protocol support this enable_args_
| |
392 | 397 |
393 // |options_string| is a comma-delimited list of trace options. | 398 // |options_string| is a comma-delimited list of trace options. |
394 // Possible options are: "record-until-full", "record-continuously", | 399 // Possible options are: "record-until-full", "record-continuously", |
395 // "trace-to-console", "enable-sampling" and "enable-systrace". | 400 // "trace-to-console", "enable-sampling" and "enable-systrace". |
396 // The first 3 options are trace recoding modes and hence | 401 // The first 3 options are trace recoding modes and hence |
397 // mutually exclusive. If more than one trace recording modes appear in the | 402 // mutually exclusive. If more than one trace recording modes appear in the |
398 // options_string, the last one takes precedence. If none of the trace | 403 // options_string, the last one takes precedence. If none of the trace |
399 // recording mode is specified, recording mode is RECORD_UNTIL_FULL. | 404 // recording mode is specified, recording mode is RECORD_UNTIL_FULL. |
400 // | 405 // |
401 // The trace option will first be reset to the default option | 406 // The trace option will first be reset to the default option |
(...skipping 10 matching lines...) Expand all Loading... | |
412 // will set ECHO_TO_CONSOLE as the recording mode. | 417 // will set ECHO_TO_CONSOLE as the recording mode. |
413 // | 418 // |
414 // Returns true on success. | 419 // Returns true on success. |
415 bool SetFromString(const std::string& options_string); | 420 bool SetFromString(const std::string& options_string); |
416 | 421 |
417 std::string ToString() const; | 422 std::string ToString() const; |
418 | 423 |
419 TraceRecordMode record_mode; | 424 TraceRecordMode record_mode; |
420 bool enable_sampling; | 425 bool enable_sampling; |
421 bool enable_systrace; | 426 bool enable_systrace; |
427 bool enable_args_whitelist; | |
422 }; | 428 }; |
423 | 429 |
424 struct BASE_EXPORT TraceLogStatus { | 430 struct BASE_EXPORT TraceLogStatus { |
425 TraceLogStatus(); | 431 TraceLogStatus(); |
426 ~TraceLogStatus(); | 432 ~TraceLogStatus(); |
427 size_t event_capacity; | 433 size_t event_capacity; |
428 size_t event_count; | 434 size_t event_count; |
429 }; | 435 }; |
430 | 436 |
431 class BASE_EXPORT TraceLog { | 437 class BASE_EXPORT TraceLog { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 int num_args, | 531 int num_args, |
526 const char* const arg_names[], | 532 const char* const arg_names[], |
527 const unsigned char arg_types[], | 533 const unsigned char arg_types[], |
528 const unsigned long long arg_values[], | 534 const unsigned long long arg_values[], |
529 unsigned char flags); | 535 unsigned char flags); |
530 | 536 |
531 // Enable tracing for EventCallback. | 537 // Enable tracing for EventCallback. |
532 void SetEventCallbackEnabled(const CategoryFilter& category_filter, | 538 void SetEventCallbackEnabled(const CategoryFilter& category_filter, |
533 EventCallback cb); | 539 EventCallback cb); |
534 void SetEventCallbackDisabled(); | 540 void SetEventCallbackDisabled(); |
541 void SetEventFilterPredicate( | |
542 const TraceEvent::EventFilterPredicate& event_filter_predicate); | |
535 | 543 |
536 // Flush all collected events to the given output callback. The callback will | 544 // Flush all collected events to the given output callback. The callback will |
537 // be called one or more times either synchronously or asynchronously from | 545 // be called one or more times either synchronously or asynchronously from |
538 // the current thread with IPC-bite-size chunks. The string format is | 546 // the current thread with IPC-bite-size chunks. The string format is |
539 // undefined. Use TraceResultBuffer to convert one or more trace strings to | 547 // undefined. Use TraceResultBuffer to convert one or more trace strings to |
540 // JSON. The callback can be null if the caller doesn't want any data. | 548 // JSON. The callback can be null if the caller doesn't want any data. |
541 // Due to the implementation of thread-local buffers, flush can't be | 549 // Due to the implementation of thread-local buffers, flush can't be |
542 // done when tracing is enabled. If called when tracing is enabled, the | 550 // done when tracing is enabled. If called when tracing is enabled, the |
543 // callback will be called directly with (empty_string, false) to indicate | 551 // callback will be called directly with (empty_string, false) to indicate |
544 // the end of this unsuccessful flush. Flush does the serialization | 552 // the end of this unsuccessful flush. Flush does the serialization |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
710 void CheckIfBufferIsFullWhileLocked(); | 718 void CheckIfBufferIsFullWhileLocked(); |
711 void SetDisabledWhileLocked(); | 719 void SetDisabledWhileLocked(); |
712 | 720 |
713 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 721 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
714 OptionalAutoLock* lock); | 722 OptionalAutoLock* lock); |
715 | 723 |
716 // |generation| is used in the following callbacks to check if the callback | 724 // |generation| is used in the following callbacks to check if the callback |
717 // is called for the flush of the current |logged_events_|. | 725 // is called for the flush of the current |logged_events_|. |
718 void FlushCurrentThread(int generation); | 726 void FlushCurrentThread(int generation); |
719 // Usually it runs on a different thread. | 727 // Usually it runs on a different thread. |
720 static void ConvertTraceEventsToTraceFormat( | 728 void ConvertTraceEventsToTraceFormat( |
721 scoped_ptr<TraceBuffer> logged_events, | 729 scoped_ptr<TraceBuffer> logged_events, |
722 const TraceLog::OutputCallback& flush_output_callback); | 730 const TraceLog::OutputCallback& flush_output_callback, |
731 const TraceEvent::EventFilterPredicate& event_filter_predicate); | |
723 void FinishFlush(int generation); | 732 void FinishFlush(int generation); |
724 void OnFlushTimeout(int generation); | 733 void OnFlushTimeout(int generation); |
725 | 734 |
726 int generation() const { | 735 int generation() const { |
727 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 736 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
728 } | 737 } |
729 bool CheckGeneration(int generation) const { | 738 bool CheckGeneration(int generation) const { |
730 return generation == this->generation(); | 739 return generation == this->generation(); |
731 } | 740 } |
732 void UseNextTraceBuffer(); | 741 void UseNextTraceBuffer(); |
733 | 742 |
734 TimeTicks OffsetNow() const { | 743 TimeTicks OffsetNow() const { |
735 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); | 744 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); |
736 } | 745 } |
737 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { | 746 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { |
738 return timestamp - time_offset_; | 747 return timestamp - time_offset_; |
739 } | 748 } |
740 | 749 |
741 // Internal representation of trace options since we store the currently used | 750 // Internal representation of trace options since we store the currently used |
742 // trace option as an AtomicWord. | 751 // trace option as an AtomicWord. |
743 static const InternalTraceOptions kInternalNone; | 752 static const InternalTraceOptions kInternalNone; |
744 static const InternalTraceOptions kInternalRecordUntilFull; | 753 static const InternalTraceOptions kInternalRecordUntilFull; |
745 static const InternalTraceOptions kInternalRecordContinuously; | 754 static const InternalTraceOptions kInternalRecordContinuously; |
746 static const InternalTraceOptions kInternalEchoToConsole; | 755 static const InternalTraceOptions kInternalEchoToConsole; |
747 static const InternalTraceOptions kInternalEnableSampling; | 756 static const InternalTraceOptions kInternalEnableSampling; |
748 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; | 757 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; |
758 static const InternalTraceOptions kInternalEnableArgsWhitelist; | |
749 | 759 |
750 // This lock protects TraceLog member accesses (except for members protected | 760 // This lock protects TraceLog member accesses (except for members protected |
751 // by thread_info_lock_) from arbitrary threads. | 761 // by thread_info_lock_) from arbitrary threads. |
752 mutable Lock lock_; | 762 mutable Lock lock_; |
753 // This lock protects accesses to thread_names_, thread_event_start_times_ | 763 // This lock protects accesses to thread_names_, thread_event_start_times_ |
754 // and thread_colors_. | 764 // and thread_colors_. |
755 Lock thread_info_lock_; | 765 Lock thread_info_lock_; |
756 Mode mode_; | 766 Mode mode_; |
757 int num_traces_recorded_; | 767 int num_traces_recorded_; |
758 scoped_ptr<TraceBuffer> logged_events_; | 768 scoped_ptr<TraceBuffer> logged_events_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
802 // need to know the life time of the message loops. | 812 // need to know the life time of the message loops. |
803 hash_set<MessageLoop*> thread_message_loops_; | 813 hash_set<MessageLoop*> thread_message_loops_; |
804 | 814 |
805 // For events which can't be added into the thread local buffer, e.g. events | 815 // For events which can't be added into the thread local buffer, e.g. events |
806 // from threads without a message loop. | 816 // from threads without a message loop. |
807 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; | 817 scoped_ptr<TraceBufferChunk> thread_shared_chunk_; |
808 size_t thread_shared_chunk_index_; | 818 size_t thread_shared_chunk_index_; |
809 | 819 |
810 // Set when asynchronous Flush is in progress. | 820 // Set when asynchronous Flush is in progress. |
811 OutputCallback flush_output_callback_; | 821 OutputCallback flush_output_callback_; |
822 TraceEvent::EventFilterPredicate event_filter_predicate_; | |
812 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; | 823 scoped_refptr<MessageLoopProxy> flush_message_loop_proxy_; |
813 subtle::AtomicWord generation_; | 824 subtle::AtomicWord generation_; |
814 bool use_worker_thread_; | 825 bool use_worker_thread_; |
815 | 826 |
816 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 827 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
817 }; | 828 }; |
818 | 829 |
819 } // namespace trace_event | 830 } // namespace trace_event |
820 } // namespace base | 831 } // namespace base |
821 | 832 |
822 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 833 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
OLD | NEW |