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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const unsigned char* arg_types, | 114 const unsigned char* arg_types, |
115 const unsigned long long* arg_values, | 115 const unsigned long long* arg_values, |
116 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 116 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
117 unsigned char flags); | 117 unsigned char flags); |
118 | 118 |
119 void Reset(); | 119 void Reset(); |
120 | 120 |
121 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); | 121 void UpdateDuration(const TimeTicks& now, const TimeTicks& thread_now); |
122 | 122 |
123 // Serialize event data to JSON | 123 // Serialize event data to JSON |
124 void AppendAsJSON(std::string* out) const; | 124 void AppendAsJSON(std::string* out, bool enable_args_whitelist) const; |
125 void AppendPrettyPrinted(std::ostringstream* out) const; | 125 void AppendPrettyPrinted(std::ostringstream* out) const; |
126 | 126 |
127 static void AppendValueAsJSON(unsigned char type, | 127 static void AppendValueAsJSON(unsigned char type, |
128 TraceValue value, | 128 TraceValue value, |
129 std::string* out); | 129 std::string* out); |
130 | 130 |
131 TimeTicks timestamp() const { return timestamp_; } | 131 TimeTicks timestamp() const { return timestamp_; } |
132 TimeTicks thread_timestamp() const { return thread_timestamp_; } | 132 TimeTicks thread_timestamp() const { return thread_timestamp_; } |
133 char phase() const { return phase_; } | 133 char phase() const { return phase_; } |
134 int thread_id() const { return thread_id_; } | 134 int thread_id() const { return thread_id_; } |
(...skipping 12 matching lines...) Expand all Loading... |
147 return category_group_enabled_; | 147 return category_group_enabled_; |
148 } | 148 } |
149 | 149 |
150 const char* name() const { return name_; } | 150 const char* name() const { return name_; } |
151 | 151 |
152 #if defined(OS_ANDROID) | 152 #if defined(OS_ANDROID) |
153 void SendToATrace(); | 153 void SendToATrace(); |
154 #endif | 154 #endif |
155 | 155 |
156 private: | 156 private: |
| 157 bool IsPIIWhitelisted() const; |
| 158 |
| 159 // List of events with args whitelisted for PII. |
| 160 static const char* const kEventArgsWhitelist[][2]; |
| 161 |
157 // Note: these are ordered by size (largest first) for optimal packing. | 162 // Note: these are ordered by size (largest first) for optimal packing. |
158 TimeTicks timestamp_; | 163 TimeTicks timestamp_; |
159 TimeTicks thread_timestamp_; | 164 TimeTicks thread_timestamp_; |
160 TimeDelta duration_; | 165 TimeDelta duration_; |
161 TimeDelta thread_duration_; | 166 TimeDelta thread_duration_; |
162 // id_ can be used to store phase-specific data. | 167 // id_ can be used to store phase-specific data. |
163 unsigned long long id_; | 168 unsigned long long id_; |
164 TraceValue arg_values_[kTraceMaxNumArgs]; | 169 TraceValue arg_values_[kTraceMaxNumArgs]; |
165 const char* arg_names_[kTraceMaxNumArgs]; | 170 const char* arg_names_[kTraceMaxNumArgs]; |
166 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; | 171 scoped_refptr<ConvertableToTraceFormat> convertable_values_[kTraceMaxNumArgs]; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 ECHO_TO_CONSOLE, | 380 ECHO_TO_CONSOLE, |
376 | 381 |
377 // Record until the trace buffer is full, but with a huge buffer size. | 382 // Record until the trace buffer is full, but with a huge buffer size. |
378 RECORD_AS_MUCH_AS_POSSIBLE | 383 RECORD_AS_MUCH_AS_POSSIBLE |
379 }; | 384 }; |
380 | 385 |
381 struct BASE_EXPORT TraceOptions { | 386 struct BASE_EXPORT TraceOptions { |
382 TraceOptions() | 387 TraceOptions() |
383 : record_mode(RECORD_UNTIL_FULL), | 388 : record_mode(RECORD_UNTIL_FULL), |
384 enable_sampling(false), | 389 enable_sampling(false), |
385 enable_systrace(false) {} | 390 enable_systrace(false), |
| 391 enable_args_whitelist(false) {} |
386 | 392 |
387 explicit TraceOptions(TraceRecordMode record_mode) | 393 explicit TraceOptions(TraceRecordMode record_mode) |
388 : record_mode(record_mode), | 394 : record_mode(record_mode), |
389 enable_sampling(false), | 395 enable_sampling(false), |
390 enable_systrace(false) {} | 396 enable_systrace(false), |
| 397 enable_args_whitelist(false) {} |
391 | 398 |
392 // |options_string| is a comma-delimited list of trace options. | 399 // |options_string| is a comma-delimited list of trace options. |
393 // Possible options are: "record-until-full", "record-continuously", | 400 // Possible options are: "record-until-full", "record-continuously", |
394 // "trace-to-console", "enable-sampling" and "enable-systrace". | 401 // "trace-to-console", "enable-sampling" and "enable-systrace". |
395 // The first 3 options are trace recoding modes and hence | 402 // The first 3 options are trace recoding modes and hence |
396 // mutually exclusive. If more than one trace recording modes appear in the | 403 // mutually exclusive. If more than one trace recording modes appear in the |
397 // options_string, the last one takes precedence. If none of the trace | 404 // options_string, the last one takes precedence. If none of the trace |
398 // recording mode is specified, recording mode is RECORD_UNTIL_FULL. | 405 // recording mode is specified, recording mode is RECORD_UNTIL_FULL. |
399 // | 406 // |
400 // The trace option will first be reset to the default option | 407 // The trace option will first be reset to the default option |
(...skipping 10 matching lines...) Expand all Loading... |
411 // will set ECHO_TO_CONSOLE as the recording mode. | 418 // will set ECHO_TO_CONSOLE as the recording mode. |
412 // | 419 // |
413 // Returns true on success. | 420 // Returns true on success. |
414 bool SetFromString(const std::string& options_string); | 421 bool SetFromString(const std::string& options_string); |
415 | 422 |
416 std::string ToString() const; | 423 std::string ToString() const; |
417 | 424 |
418 TraceRecordMode record_mode; | 425 TraceRecordMode record_mode; |
419 bool enable_sampling; | 426 bool enable_sampling; |
420 bool enable_systrace; | 427 bool enable_systrace; |
| 428 bool enable_args_whitelist; |
421 }; | 429 }; |
422 | 430 |
423 struct BASE_EXPORT TraceLogStatus { | 431 struct BASE_EXPORT TraceLogStatus { |
424 TraceLogStatus(); | 432 TraceLogStatus(); |
425 ~TraceLogStatus(); | 433 ~TraceLogStatus(); |
426 size_t event_capacity; | 434 size_t event_capacity; |
427 size_t event_count; | 435 size_t event_count; |
428 }; | 436 }; |
429 | 437 |
430 class BASE_EXPORT TraceLog { | 438 class BASE_EXPORT TraceLog { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 void CheckIfBufferIsFullWhileLocked(); | 713 void CheckIfBufferIsFullWhileLocked(); |
706 void SetDisabledWhileLocked(); | 714 void SetDisabledWhileLocked(); |
707 | 715 |
708 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 716 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
709 OptionalAutoLock* lock); | 717 OptionalAutoLock* lock); |
710 | 718 |
711 // |generation| is used in the following callbacks to check if the callback | 719 // |generation| is used in the following callbacks to check if the callback |
712 // is called for the flush of the current |logged_events_|. | 720 // is called for the flush of the current |logged_events_|. |
713 void FlushCurrentThread(int generation); | 721 void FlushCurrentThread(int generation); |
714 // Usually it runs on a different thread. | 722 // Usually it runs on a different thread. |
715 static void ConvertTraceEventsToTraceFormat( | 723 void ConvertTraceEventsToTraceFormat( |
716 scoped_ptr<TraceBuffer> logged_events, | 724 scoped_ptr<TraceBuffer> logged_events, |
717 const TraceLog::OutputCallback& flush_output_callback); | 725 const TraceLog::OutputCallback& flush_output_callback); |
718 void FinishFlush(int generation); | 726 void FinishFlush(int generation); |
719 void OnFlushTimeout(int generation); | 727 void OnFlushTimeout(int generation); |
720 | 728 |
721 int generation() const { | 729 int generation() const { |
722 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 730 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
723 } | 731 } |
724 bool CheckGeneration(int generation) const { | 732 bool CheckGeneration(int generation) const { |
725 return generation == this->generation(); | 733 return generation == this->generation(); |
726 } | 734 } |
727 void UseNextTraceBuffer(); | 735 void UseNextTraceBuffer(); |
728 | 736 |
729 TimeTicks OffsetNow() const { | 737 TimeTicks OffsetNow() const { |
730 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); | 738 return OffsetTimestamp(TimeTicks::NowFromSystemTraceTime()); |
731 } | 739 } |
732 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { | 740 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { |
733 return timestamp - time_offset_; | 741 return timestamp - time_offset_; |
734 } | 742 } |
735 | 743 |
736 // Internal representation of trace options since we store the currently used | 744 // Internal representation of trace options since we store the currently used |
737 // trace option as an AtomicWord. | 745 // trace option as an AtomicWord. |
738 static const InternalTraceOptions kInternalNone; | 746 static const InternalTraceOptions kInternalNone; |
739 static const InternalTraceOptions kInternalRecordUntilFull; | 747 static const InternalTraceOptions kInternalRecordUntilFull; |
740 static const InternalTraceOptions kInternalRecordContinuously; | 748 static const InternalTraceOptions kInternalRecordContinuously; |
741 static const InternalTraceOptions kInternalEchoToConsole; | 749 static const InternalTraceOptions kInternalEchoToConsole; |
742 static const InternalTraceOptions kInternalEnableSampling; | 750 static const InternalTraceOptions kInternalEnableSampling; |
743 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; | 751 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; |
| 752 static const InternalTraceOptions kInternalEnableArgsWhitelist; |
744 | 753 |
745 // This lock protects TraceLog member accesses (except for members protected | 754 // This lock protects TraceLog member accesses (except for members protected |
746 // by thread_info_lock_) from arbitrary threads. | 755 // by thread_info_lock_) from arbitrary threads. |
747 mutable Lock lock_; | 756 mutable Lock lock_; |
748 // This lock protects accesses to thread_names_, thread_event_start_times_ | 757 // This lock protects accesses to thread_names_, thread_event_start_times_ |
749 // and thread_colors_. | 758 // and thread_colors_. |
750 Lock thread_info_lock_; | 759 Lock thread_info_lock_; |
751 Mode mode_; | 760 Mode mode_; |
752 int num_traces_recorded_; | 761 int num_traces_recorded_; |
753 scoped_ptr<TraceBuffer> logged_events_; | 762 scoped_ptr<TraceBuffer> logged_events_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 subtle::AtomicWord generation_; | 817 subtle::AtomicWord generation_; |
809 bool use_worker_thread_; | 818 bool use_worker_thread_; |
810 | 819 |
811 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 820 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
812 }; | 821 }; |
813 | 822 |
814 } // namespace trace_event | 823 } // namespace trace_event |
815 } // namespace base | 824 } // namespace base |
816 | 825 |
817 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 826 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
OLD | NEW |