| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef BASE_TRACE_EVENT_TRACE_LOG_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_LOG_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_LOG_H_ | 6 #define BASE_TRACE_EVENT_TRACE_LOG_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 // Not using base::Callback because of its limited by 7 parameters. | 127 // Not using base::Callback because of its limited by 7 parameters. |
| 128 // Also, using primitive type allows directly passing callback from WebCore. | 128 // Also, using primitive type allows directly passing callback from WebCore. |
| 129 // WARNING: It is possible for the previously set callback to be called | 129 // WARNING: It is possible for the previously set callback to be called |
| 130 // after a call to SetEventCallbackEnabled() that replaces or a call to | 130 // after a call to SetEventCallbackEnabled() that replaces or a call to |
| 131 // SetEventCallbackDisabled() that disables the callback. | 131 // SetEventCallbackDisabled() that disables the callback. |
| 132 // This callback may be invoked on any thread. | 132 // This callback may be invoked on any thread. |
| 133 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs | 133 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs |
| 134 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the | 134 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the |
| 135 // interface simple. | 135 // interface simple. |
| 136 typedef void (*EventCallback)(TraceTicks timestamp, | 136 typedef void (*EventCallback)(TimeTicks timestamp, |
| 137 char phase, | 137 char phase, |
| 138 const unsigned char* category_group_enabled, | 138 const unsigned char* category_group_enabled, |
| 139 const char* name, | 139 const char* name, |
| 140 unsigned long long id, | 140 unsigned long long id, |
| 141 int num_args, | 141 int num_args, |
| 142 const char* const arg_names[], | 142 const char* const arg_names[], |
| 143 const unsigned char arg_types[], | 143 const unsigned char arg_types[], |
| 144 const unsigned long long arg_values[], | 144 const unsigned long long arg_values[], |
| 145 unsigned int flags); | 145 unsigned int flags); |
| 146 | 146 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const unsigned long long* arg_values, | 214 const unsigned long long* arg_values, |
| 215 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 215 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 216 unsigned int flags); | 216 unsigned int flags); |
| 217 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 217 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
| 218 char phase, | 218 char phase, |
| 219 const unsigned char* category_group_enabled, | 219 const unsigned char* category_group_enabled, |
| 220 const char* name, | 220 const char* name, |
| 221 unsigned long long id, | 221 unsigned long long id, |
| 222 unsigned long long context_id, | 222 unsigned long long context_id, |
| 223 int thread_id, | 223 int thread_id, |
| 224 const TraceTicks& timestamp, | 224 const TimeTicks& timestamp, |
| 225 int num_args, | 225 int num_args, |
| 226 const char** arg_names, | 226 const char** arg_names, |
| 227 const unsigned char* arg_types, | 227 const unsigned char* arg_types, |
| 228 const unsigned long long* arg_values, | 228 const unsigned long long* arg_values, |
| 229 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 229 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 230 unsigned int flags); | 230 unsigned int flags); |
| 231 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 231 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
| 232 char phase, | 232 char phase, |
| 233 const unsigned char* category_group_enabled, | 233 const unsigned char* category_group_enabled, |
| 234 const char* name, | 234 const char* name, |
| 235 unsigned long long id, | 235 unsigned long long id, |
| 236 unsigned long long context_id, | 236 unsigned long long context_id, |
| 237 unsigned long long bind_id, | 237 unsigned long long bind_id, |
| 238 int thread_id, | 238 int thread_id, |
| 239 const TraceTicks& timestamp, | 239 const TimeTicks& timestamp, |
| 240 int num_args, | 240 int num_args, |
| 241 const char** arg_names, | 241 const char** arg_names, |
| 242 const unsigned char* arg_types, | 242 const unsigned char* arg_types, |
| 243 const unsigned long long* arg_values, | 243 const unsigned long long* arg_values, |
| 244 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 244 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 245 unsigned int flags); | 245 unsigned int flags); |
| 246 | 246 |
| 247 // Adds a metadata event that will be written when the trace log is flushed. | 247 // Adds a metadata event that will be written when the trace log is flushed. |
| 248 void AddMetadataEvent( | 248 void AddMetadataEvent( |
| 249 const char* name, | 249 const char* name, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // Processes can have labels in addition to their names. Use labels, for | 294 // Processes can have labels in addition to their names. Use labels, for |
| 295 // instance, to list out the web page titles that a process is handling. | 295 // instance, to list out the web page titles that a process is handling. |
| 296 void UpdateProcessLabel(int label_id, const std::string& current_label); | 296 void UpdateProcessLabel(int label_id, const std::string& current_label); |
| 297 void RemoveProcessLabel(int label_id); | 297 void RemoveProcessLabel(int label_id); |
| 298 | 298 |
| 299 // Thread sort indices, if set, override the order of a thread will appear | 299 // Thread sort indices, if set, override the order of a thread will appear |
| 300 // within its process in the trace viewer. Threads are sorted first on their | 300 // within its process in the trace viewer. Threads are sorted first on their |
| 301 // sort index, ascending, then by their name, and then tid. | 301 // sort index, ascending, then by their name, and then tid. |
| 302 void SetThreadSortIndex(PlatformThreadId thread_id, int sort_index); | 302 void SetThreadSortIndex(PlatformThreadId thread_id, int sort_index); |
| 303 | 303 |
| 304 // Allow setting an offset between the current TraceTicks time and the time | 304 // Allow setting an offset between the current TimeTicks time and the time |
| 305 // that should be reported. | 305 // that should be reported. |
| 306 void SetTimeOffset(TimeDelta offset); | 306 void SetTimeOffset(TimeDelta offset); |
| 307 | 307 |
| 308 size_t GetObserverCountForTest() const; | 308 size_t GetObserverCountForTest() const; |
| 309 | 309 |
| 310 // Call this method if the current thread may block the message loop to | 310 // Call this method if the current thread may block the message loop to |
| 311 // prevent the thread from using the thread-local buffer because the thread | 311 // prevent the thread from using the thread-local buffer because the thread |
| 312 // may not handle the flush request in time causing lost of unflushed events. | 312 // may not handle the flush request in time causing lost of unflushed events. |
| 313 void SetCurrentThreadBlocksMessageLoop(); | 313 void SetCurrentThreadBlocksMessageLoop(); |
| 314 | 314 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 InternalTraceOptions trace_options() const { | 368 InternalTraceOptions trace_options() const { |
| 369 return static_cast<InternalTraceOptions>( | 369 return static_cast<InternalTraceOptions>( |
| 370 subtle::NoBarrier_Load(&trace_options_)); | 370 subtle::NoBarrier_Load(&trace_options_)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 373 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
| 374 TraceBuffer* CreateTraceBuffer(); | 374 TraceBuffer* CreateTraceBuffer(); |
| 375 | 375 |
| 376 std::string EventToConsoleMessage(unsigned char phase, | 376 std::string EventToConsoleMessage(unsigned char phase, |
| 377 const TraceTicks& timestamp, | 377 const TimeTicks& timestamp, |
| 378 TraceEvent* trace_event); | 378 TraceEvent* trace_event); |
| 379 | 379 |
| 380 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 380 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
| 381 bool check_buffer_is_full); | 381 bool check_buffer_is_full); |
| 382 void CheckIfBufferIsFullWhileLocked(); | 382 void CheckIfBufferIsFullWhileLocked(); |
| 383 void SetDisabledWhileLocked(); | 383 void SetDisabledWhileLocked(); |
| 384 | 384 |
| 385 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 385 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
| 386 OptionalAutoLock* lock); | 386 OptionalAutoLock* lock); |
| 387 | 387 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 401 void OnFlushTimeout(int generation, bool discard_events); | 401 void OnFlushTimeout(int generation, bool discard_events); |
| 402 | 402 |
| 403 int generation() const { | 403 int generation() const { |
| 404 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 404 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
| 405 } | 405 } |
| 406 bool CheckGeneration(int generation) const { | 406 bool CheckGeneration(int generation) const { |
| 407 return generation == this->generation(); | 407 return generation == this->generation(); |
| 408 } | 408 } |
| 409 void UseNextTraceBuffer(); | 409 void UseNextTraceBuffer(); |
| 410 | 410 |
| 411 TraceTicks OffsetNow() const { return OffsetTimestamp(TraceTicks::Now()); } | 411 TimeTicks OffsetNow() const { return OffsetTimestamp(TimeTicks::Now()); } |
| 412 TraceTicks OffsetTimestamp(const TraceTicks& timestamp) const { | 412 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { |
| 413 return timestamp - time_offset_; | 413 return timestamp - time_offset_; |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Internal representation of trace options since we store the currently used | 416 // Internal representation of trace options since we store the currently used |
| 417 // trace option as an AtomicWord. | 417 // trace option as an AtomicWord. |
| 418 static const InternalTraceOptions kInternalNone; | 418 static const InternalTraceOptions kInternalNone; |
| 419 static const InternalTraceOptions kInternalRecordUntilFull; | 419 static const InternalTraceOptions kInternalRecordUntilFull; |
| 420 static const InternalTraceOptions kInternalRecordContinuously; | 420 static const InternalTraceOptions kInternalRecordContinuously; |
| 421 static const InternalTraceOptions kInternalEchoToConsole; | 421 static const InternalTraceOptions kInternalEchoToConsole; |
| 422 static const InternalTraceOptions kInternalEnableSampling; | 422 static const InternalTraceOptions kInternalEnableSampling; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 437 bool dispatching_to_observer_list_; | 437 bool dispatching_to_observer_list_; |
| 438 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 438 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
| 439 | 439 |
| 440 std::string process_name_; | 440 std::string process_name_; |
| 441 base::hash_map<int, std::string> process_labels_; | 441 base::hash_map<int, std::string> process_labels_; |
| 442 int process_sort_index_; | 442 int process_sort_index_; |
| 443 base::hash_map<int, int> thread_sort_indices_; | 443 base::hash_map<int, int> thread_sort_indices_; |
| 444 base::hash_map<int, std::string> thread_names_; | 444 base::hash_map<int, std::string> thread_names_; |
| 445 | 445 |
| 446 // The following two maps are used only when ECHO_TO_CONSOLE. | 446 // The following two maps are used only when ECHO_TO_CONSOLE. |
| 447 base::hash_map<int, std::stack<TraceTicks>> thread_event_start_times_; | 447 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; |
| 448 base::hash_map<std::string, int> thread_colors_; | 448 base::hash_map<std::string, int> thread_colors_; |
| 449 | 449 |
| 450 TraceTicks buffer_limit_reached_timestamp_; | 450 TimeTicks buffer_limit_reached_timestamp_; |
| 451 | 451 |
| 452 // XORed with TraceID to make it unlikely to collide with other processes. | 452 // XORed with TraceID to make it unlikely to collide with other processes. |
| 453 unsigned long long process_id_hash_; | 453 unsigned long long process_id_hash_; |
| 454 | 454 |
| 455 int process_id_; | 455 int process_id_; |
| 456 | 456 |
| 457 TimeDelta time_offset_; | 457 TimeDelta time_offset_; |
| 458 | 458 |
| 459 // Allow tests to wake up when certain events occur. | 459 // Allow tests to wake up when certain events occur. |
| 460 WatchEventCallback watch_event_callback_; | 460 WatchEventCallback watch_event_callback_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 491 subtle::AtomicWord generation_; | 491 subtle::AtomicWord generation_; |
| 492 bool use_worker_thread_; | 492 bool use_worker_thread_; |
| 493 | 493 |
| 494 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 494 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 495 }; | 495 }; |
| 496 | 496 |
| 497 } // namespace trace_event | 497 } // namespace trace_event |
| 498 } // namespace base | 498 } // namespace base |
| 499 | 499 |
| 500 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ | 500 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ |
| OLD | NEW |