| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 FILTERING_MODE = 1 << 1 | 54 FILTERING_MODE = 1 << 1 |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // The pointer returned from GetCategoryGroupEnabledInternal() points to a | 57 // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
| 58 // value with zero or more of the following bits. Used in this class only. | 58 // value with zero or more of the following bits. Used in this class only. |
| 59 // The TRACE_EVENT macros should only use the value as a bool. | 59 // The TRACE_EVENT macros should only use the value as a bool. |
| 60 // These values must be in sync with macro values in TraceEvent.h in Blink. | 60 // These values must be in sync with macro values in TraceEvent.h in Blink. |
| 61 enum CategoryGroupEnabledFlags { | 61 enum CategoryGroupEnabledFlags { |
| 62 // Category group enabled for the recording mode. | 62 // Category group enabled for the recording mode. |
| 63 ENABLED_FOR_RECORDING = 1 << 0, | 63 ENABLED_FOR_RECORDING = 1 << 0, |
| 64 // Category group enabled by SetEventCallbackEnabled(). | 64 // 1 << 2 was used for ENABLED_FOR_EVENT_CALLBACK. |
| 65 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, | 65 |
| 66 // Category group enabled to export events to ETW. | 66 // Category group enabled to export events to ETW. |
| 67 ENABLED_FOR_ETW_EXPORT = 1 << 3, | 67 ENABLED_FOR_ETW_EXPORT = 1 << 3, |
| 68 // Category group being filtered before logged. | 68 // Category group being filtered before logged. |
| 69 ENABLED_FOR_FILTERING = 1 << 4 | 69 ENABLED_FOR_FILTERING = 1 << 4 |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static TraceLog* GetInstance(); | 72 static TraceLog* GetInstance(); |
| 73 | 73 |
| 74 // Get set of known category groups. This can change as new code paths are | 74 // Get set of known category groups. This can change as new code paths are |
| 75 // reached. The known category groups are inserted into |category_groups|. | 75 // reached. The known category groups are inserted into |category_groups|. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void RemoveAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener); | 161 void RemoveAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener); |
| 162 bool HasAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener) const; | 162 bool HasAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener) const; |
| 163 | 163 |
| 164 TraceLogStatus GetStatus() const; | 164 TraceLogStatus GetStatus() const; |
| 165 bool BufferIsFull() const; | 165 bool BufferIsFull() const; |
| 166 | 166 |
| 167 // Computes an estimate of the size of the TraceLog including all the retained | 167 // Computes an estimate of the size of the TraceLog including all the retained |
| 168 // objects. | 168 // objects. |
| 169 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); | 169 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); |
| 170 | 170 |
| 171 // Not using base::Callback because of its limited by 7 parameters. | |
| 172 // Also, using primitive type allows directly passing callback from WebCore. | |
| 173 // WARNING: It is possible for the previously set callback to be called | |
| 174 // after a call to SetEventCallbackEnabled() that replaces or a call to | |
| 175 // SetEventCallbackDisabled() that disables the callback. | |
| 176 // This callback may be invoked on any thread. | |
| 177 // For TRACE_EVENT_PHASE_COMPLETE events, the client will still receive pairs | |
| 178 // of TRACE_EVENT_PHASE_BEGIN and TRACE_EVENT_PHASE_END events to keep the | |
| 179 // interface simple. | |
| 180 typedef void (*EventCallback)(TimeTicks timestamp, | |
| 181 char phase, | |
| 182 const unsigned char* category_group_enabled, | |
| 183 const char* name, | |
| 184 const char* scope, | |
| 185 unsigned long long id, | |
| 186 int num_args, | |
| 187 const char* const arg_names[], | |
| 188 const unsigned char arg_types[], | |
| 189 const unsigned long long arg_values[], | |
| 190 unsigned int flags); | |
| 191 | |
| 192 // Enable tracing for EventCallback. | |
| 193 void SetEventCallbackEnabled(const TraceConfig& trace_config, | |
| 194 EventCallback cb); | |
| 195 void SetEventCallbackDisabled(); | |
| 196 void SetArgumentFilterPredicate( | 171 void SetArgumentFilterPredicate( |
| 197 const ArgumentFilterPredicate& argument_filter_predicate); | 172 const ArgumentFilterPredicate& argument_filter_predicate); |
| 198 | 173 |
| 199 // Flush all collected events to the given output callback. The callback will | 174 // Flush all collected events to the given output callback. The callback will |
| 200 // be called one or more times either synchronously or asynchronously from | 175 // be called one or more times either synchronously or asynchronously from |
| 201 // the current thread with IPC-bite-size chunks. The string format is | 176 // the current thread with IPC-bite-size chunks. The string format is |
| 202 // undefined. Use TraceResultBuffer to convert one or more trace strings to | 177 // undefined. Use TraceResultBuffer to convert one or more trace strings to |
| 203 // JSON. The callback can be null if the caller doesn't want any data. | 178 // JSON. The callback can be null if the caller doesn't want any data. |
| 204 // Due to the implementation of thread-local buffers, flush can't be | 179 // Due to the implementation of thread-local buffers, flush can't be |
| 205 // done when tracing is enabled. If called when tracing is enabled, the | 180 // done when tracing is enabled. If called when tracing is enabled, the |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 380 |
| 406 // This allows constructor and destructor to be private and usable only | 381 // This allows constructor and destructor to be private and usable only |
| 407 // by the Singleton class. | 382 // by the Singleton class. |
| 408 friend struct DefaultSingletonTraits<TraceLog>; | 383 friend struct DefaultSingletonTraits<TraceLog>; |
| 409 | 384 |
| 410 // MemoryDumpProvider implementation. | 385 // MemoryDumpProvider implementation. |
| 411 bool OnMemoryDump(const MemoryDumpArgs& args, | 386 bool OnMemoryDump(const MemoryDumpArgs& args, |
| 412 ProcessMemoryDump* pmd) override; | 387 ProcessMemoryDump* pmd) override; |
| 413 | 388 |
| 414 // Enable/disable each category group based on the current mode_, | 389 // Enable/disable each category group based on the current mode_, |
| 415 // category_filter_, event_callback_ and event_callback_category_filter_. | 390 // category_filter_ and event_filters_enabled_. |
| 416 // Enable the category group in the enabled mode if category_filter_ matches | 391 // Enable the category group in the recording mode if category_filter_ matches |
| 417 // the category group, or event_callback_ is not null and | 392 // the category group, is not null. Enable category for filtering if any |
| 418 // event_callback_category_filter_ matches the category group. | 393 // filter in event_filters_enabled_ enables it. |
| 419 void UpdateCategoryGroupEnabledFlags(); | 394 void UpdateCategoryGroupEnabledFlags(); |
| 420 void UpdateCategoryGroupEnabledFlag(size_t category_index); | 395 void UpdateCategoryGroupEnabledFlag(size_t category_index); |
| 421 | 396 |
| 422 void CreateFiltersForTraceConfig(); | 397 void CreateFiltersForTraceConfig(); |
| 423 | 398 |
| 424 // Configure synthetic delays based on the values set in the current | 399 // Configure synthetic delays based on the values set in the current |
| 425 // trace config. | 400 // trace config. |
| 426 void UpdateSyntheticDelaysFromTraceConfig(); | 401 void UpdateSyntheticDelaysFromTraceConfig(); |
| 427 | 402 |
| 428 InternalTraceOptions GetInternalOptionsFromTraceConfig( | 403 InternalTraceOptions GetInternalOptionsFromTraceConfig( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 // This lock protects TraceLog member accesses (except for members protected | 472 // This lock protects TraceLog member accesses (except for members protected |
| 498 // by thread_info_lock_) from arbitrary threads. | 473 // by thread_info_lock_) from arbitrary threads. |
| 499 mutable Lock lock_; | 474 mutable Lock lock_; |
| 500 // This lock protects accesses to thread_names_, thread_event_start_times_ | 475 // This lock protects accesses to thread_names_, thread_event_start_times_ |
| 501 // and thread_colors_. | 476 // and thread_colors_. |
| 502 Lock thread_info_lock_; | 477 Lock thread_info_lock_; |
| 503 uint8_t enabled_modes_; // See TraceLog::Mode. | 478 uint8_t enabled_modes_; // See TraceLog::Mode. |
| 504 int num_traces_recorded_; | 479 int num_traces_recorded_; |
| 505 std::unique_ptr<TraceBuffer> logged_events_; | 480 std::unique_ptr<TraceBuffer> logged_events_; |
| 506 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; | 481 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; |
| 507 subtle::AtomicWord /* EventCallback */ event_callback_; | |
| 508 bool dispatching_to_observer_list_; | 482 bool dispatching_to_observer_list_; |
| 509 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 483 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
| 510 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> | 484 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> |
| 511 async_observers_; | 485 async_observers_; |
| 512 | 486 |
| 513 std::string process_name_; | 487 std::string process_name_; |
| 514 base::hash_map<int, std::string> process_labels_; | 488 base::hash_map<int, std::string> process_labels_; |
| 515 int process_sort_index_; | 489 int process_sort_index_; |
| 516 base::hash_map<int, int> thread_sort_indices_; | 490 base::hash_map<int, int> thread_sort_indices_; |
| 517 base::hash_map<int, std::string> thread_names_; | 491 base::hash_map<int, std::string> thread_names_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 530 TimeDelta time_offset_; | 504 TimeDelta time_offset_; |
| 531 | 505 |
| 532 // Allow tests to wake up when certain events occur. | 506 // Allow tests to wake up when certain events occur. |
| 533 WatchEventCallback watch_event_callback_; | 507 WatchEventCallback watch_event_callback_; |
| 534 subtle::AtomicWord /* const unsigned char* */ watch_category_; | 508 subtle::AtomicWord /* const unsigned char* */ watch_category_; |
| 535 std::string watch_event_name_; | 509 std::string watch_event_name_; |
| 536 | 510 |
| 537 subtle::AtomicWord /* Options */ trace_options_; | 511 subtle::AtomicWord /* Options */ trace_options_; |
| 538 | 512 |
| 539 TraceConfig trace_config_; | 513 TraceConfig trace_config_; |
| 540 TraceConfig event_callback_trace_config_; | |
| 541 TraceConfig::EventFilters enabled_event_filters_; | 514 TraceConfig::EventFilters enabled_event_filters_; |
| 542 | 515 |
| 543 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; | 516 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; |
| 544 ThreadLocalBoolean thread_blocks_message_loop_; | 517 ThreadLocalBoolean thread_blocks_message_loop_; |
| 545 ThreadLocalBoolean thread_is_in_trace_event_; | 518 ThreadLocalBoolean thread_is_in_trace_event_; |
| 546 | 519 |
| 547 // Contains the message loops of threads that have had at least one event | 520 // Contains the message loops of threads that have had at least one event |
| 548 // added into the local event buffer. Not using SingleThreadTaskRunner | 521 // added into the local event buffer. Not using SingleThreadTaskRunner |
| 549 // because we need to know the life time of the message loops. | 522 // because we need to know the life time of the message loops. |
| 550 hash_set<MessageLoop*> thread_message_loops_; | 523 hash_set<MessageLoop*> thread_message_loops_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 561 subtle::AtomicWord generation_; | 534 subtle::AtomicWord generation_; |
| 562 bool use_worker_thread_; | 535 bool use_worker_thread_; |
| 563 | 536 |
| 564 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 537 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 565 }; | 538 }; |
| 566 | 539 |
| 567 } // namespace trace_event | 540 } // namespace trace_event |
| 568 } // namespace base | 541 } // namespace base |
| 569 | 542 |
| 570 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ | 543 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ |
| OLD | NEW |