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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 const unsigned long long* arg_values, | 202 const unsigned long long* arg_values, |
203 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 203 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
204 unsigned int flags); | 204 unsigned int flags); |
205 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 205 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
206 char phase, | 206 char phase, |
207 const unsigned char* category_group_enabled, | 207 const unsigned char* category_group_enabled, |
208 const char* name, | 208 const char* name, |
209 unsigned long long id, | 209 unsigned long long id, |
210 unsigned long long context_id, | 210 unsigned long long context_id, |
211 int thread_id, | 211 int thread_id, |
212 const TraceTicks& timestamp, | 212 const TimeTicks& timestamp, |
213 int num_args, | 213 int num_args, |
214 const char** arg_names, | 214 const char** arg_names, |
215 const unsigned char* arg_types, | 215 const unsigned char* arg_types, |
216 const unsigned long long* arg_values, | 216 const unsigned long long* arg_values, |
217 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 217 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
218 unsigned int flags); | 218 unsigned int flags); |
219 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( | 219 TraceEventHandle AddTraceEventWithThreadIdAndTimestamp( |
220 char phase, | 220 char phase, |
221 const unsigned char* category_group_enabled, | 221 const unsigned char* category_group_enabled, |
222 const char* name, | 222 const char* name, |
223 unsigned long long id, | 223 unsigned long long id, |
224 unsigned long long context_id, | 224 unsigned long long context_id, |
225 unsigned long long bind_id, | 225 unsigned long long bind_id, |
226 int thread_id, | 226 int thread_id, |
227 const TraceTicks& timestamp, | 227 const TimeTicks& timestamp, |
228 int num_args, | 228 int num_args, |
229 const char** arg_names, | 229 const char** arg_names, |
230 const unsigned char* arg_types, | 230 const unsigned char* arg_types, |
231 const unsigned long long* arg_values, | 231 const unsigned long long* arg_values, |
232 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 232 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
233 unsigned int flags); | 233 unsigned int flags); |
234 | 234 |
235 // Adds a metadata event that will be written when the trace log is flushed. | 235 // Adds a metadata event that will be written when the trace log is flushed. |
236 void AddMetadataEvent( | 236 void AddMetadataEvent( |
237 const char* name, | 237 const char* name, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // Processes can have labels in addition to their names. Use labels, for | 282 // Processes can have labels in addition to their names. Use labels, for |
283 // instance, to list out the web page titles that a process is handling. | 283 // instance, to list out the web page titles that a process is handling. |
284 void UpdateProcessLabel(int label_id, const std::string& current_label); | 284 void UpdateProcessLabel(int label_id, const std::string& current_label); |
285 void RemoveProcessLabel(int label_id); | 285 void RemoveProcessLabel(int label_id); |
286 | 286 |
287 // Thread sort indices, if set, override the order of a thread will appear | 287 // Thread sort indices, if set, override the order of a thread will appear |
288 // within its process in the trace viewer. Threads are sorted first on their | 288 // within its process in the trace viewer. Threads are sorted first on their |
289 // sort index, ascending, then by their name, and then tid. | 289 // sort index, ascending, then by their name, and then tid. |
290 void SetThreadSortIndex(PlatformThreadId thread_id, int sort_index); | 290 void SetThreadSortIndex(PlatformThreadId thread_id, int sort_index); |
291 | 291 |
292 // Allow setting an offset between the current TraceTicks time and the time | 292 // Allow setting an offset between the current TimeTicks time and the time |
293 // that should be reported. | 293 // that should be reported. |
294 void SetTimeOffset(TimeDelta offset); | 294 void SetTimeOffset(TimeDelta offset); |
295 | 295 |
296 size_t GetObserverCountForTest() const; | 296 size_t GetObserverCountForTest() const; |
297 | 297 |
298 // Call this method if the current thread may block the message loop to | 298 // Call this method if the current thread may block the message loop to |
299 // prevent the thread from using the thread-local buffer because the thread | 299 // prevent the thread from using the thread-local buffer because the thread |
300 // may not handle the flush request in time causing lost of unflushed events. | 300 // may not handle the flush request in time causing lost of unflushed events. |
301 void SetCurrentThreadBlocksMessageLoop(); | 301 void SetCurrentThreadBlocksMessageLoop(); |
302 | 302 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 355 |
356 InternalTraceOptions trace_options() const { | 356 InternalTraceOptions trace_options() const { |
357 return static_cast<InternalTraceOptions>( | 357 return static_cast<InternalTraceOptions>( |
358 subtle::NoBarrier_Load(&trace_options_)); | 358 subtle::NoBarrier_Load(&trace_options_)); |
359 } | 359 } |
360 | 360 |
361 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 361 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
362 TraceBuffer* CreateTraceBuffer(); | 362 TraceBuffer* CreateTraceBuffer(); |
363 | 363 |
364 std::string EventToConsoleMessage(unsigned char phase, | 364 std::string EventToConsoleMessage(unsigned char phase, |
365 const TraceTicks& timestamp, | 365 const TimeTicks& timestamp, |
366 TraceEvent* trace_event); | 366 TraceEvent* trace_event); |
367 | 367 |
368 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 368 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
369 bool check_buffer_is_full); | 369 bool check_buffer_is_full); |
370 void CheckIfBufferIsFullWhileLocked(); | 370 void CheckIfBufferIsFullWhileLocked(); |
371 void SetDisabledWhileLocked(); | 371 void SetDisabledWhileLocked(); |
372 | 372 |
373 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 373 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
374 OptionalAutoLock* lock); | 374 OptionalAutoLock* lock); |
375 | 375 |
(...skipping 13 matching lines...) Expand all Loading... |
389 void OnFlushTimeout(int generation, bool discard_events); | 389 void OnFlushTimeout(int generation, bool discard_events); |
390 | 390 |
391 int generation() const { | 391 int generation() const { |
392 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); | 392 return static_cast<int>(subtle::NoBarrier_Load(&generation_)); |
393 } | 393 } |
394 bool CheckGeneration(int generation) const { | 394 bool CheckGeneration(int generation) const { |
395 return generation == this->generation(); | 395 return generation == this->generation(); |
396 } | 396 } |
397 void UseNextTraceBuffer(); | 397 void UseNextTraceBuffer(); |
398 | 398 |
399 TraceTicks OffsetNow() const { return OffsetTimestamp(TraceTicks::Now()); } | 399 TimeTicks OffsetNow() const { return OffsetTimestamp(TimeTicks::Now()); } |
400 TraceTicks OffsetTimestamp(const TraceTicks& timestamp) const { | 400 TimeTicks OffsetTimestamp(const TimeTicks& timestamp) const { |
401 return timestamp - time_offset_; | 401 return timestamp - time_offset_; |
402 } | 402 } |
403 | 403 |
404 // Internal representation of trace options since we store the currently used | 404 // Internal representation of trace options since we store the currently used |
405 // trace option as an AtomicWord. | 405 // trace option as an AtomicWord. |
406 static const InternalTraceOptions kInternalNone; | 406 static const InternalTraceOptions kInternalNone; |
407 static const InternalTraceOptions kInternalRecordUntilFull; | 407 static const InternalTraceOptions kInternalRecordUntilFull; |
408 static const InternalTraceOptions kInternalRecordContinuously; | 408 static const InternalTraceOptions kInternalRecordContinuously; |
409 static const InternalTraceOptions kInternalEchoToConsole; | 409 static const InternalTraceOptions kInternalEchoToConsole; |
410 static const InternalTraceOptions kInternalEnableSampling; | 410 static const InternalTraceOptions kInternalEnableSampling; |
(...skipping 14 matching lines...) Expand all Loading... |
425 bool dispatching_to_observer_list_; | 425 bool dispatching_to_observer_list_; |
426 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 426 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
427 | 427 |
428 std::string process_name_; | 428 std::string process_name_; |
429 base::hash_map<int, std::string> process_labels_; | 429 base::hash_map<int, std::string> process_labels_; |
430 int process_sort_index_; | 430 int process_sort_index_; |
431 base::hash_map<int, int> thread_sort_indices_; | 431 base::hash_map<int, int> thread_sort_indices_; |
432 base::hash_map<int, std::string> thread_names_; | 432 base::hash_map<int, std::string> thread_names_; |
433 | 433 |
434 // The following two maps are used only when ECHO_TO_CONSOLE. | 434 // The following two maps are used only when ECHO_TO_CONSOLE. |
435 base::hash_map<int, std::stack<TraceTicks>> thread_event_start_times_; | 435 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; |
436 base::hash_map<std::string, int> thread_colors_; | 436 base::hash_map<std::string, int> thread_colors_; |
437 | 437 |
438 TraceTicks buffer_limit_reached_timestamp_; | 438 TimeTicks buffer_limit_reached_timestamp_; |
439 | 439 |
440 // XORed with TraceID to make it unlikely to collide with other processes. | 440 // XORed with TraceID to make it unlikely to collide with other processes. |
441 unsigned long long process_id_hash_; | 441 unsigned long long process_id_hash_; |
442 | 442 |
443 int process_id_; | 443 int process_id_; |
444 | 444 |
445 TimeDelta time_offset_; | 445 TimeDelta time_offset_; |
446 | 446 |
447 // Allow tests to wake up when certain events occur. | 447 // Allow tests to wake up when certain events occur. |
448 WatchEventCallback watch_event_callback_; | 448 WatchEventCallback watch_event_callback_; |
(...skipping 30 matching lines...) Expand all Loading... |
479 subtle::AtomicWord generation_; | 479 subtle::AtomicWord generation_; |
480 bool use_worker_thread_; | 480 bool use_worker_thread_; |
481 | 481 |
482 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 482 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
483 }; | 483 }; |
484 | 484 |
485 } // namespace trace_event | 485 } // namespace trace_event |
486 } // namespace base | 486 } // namespace base |
487 | 487 |
488 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ | 488 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ |
OLD | NEW |