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