| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 struct BASE_EXPORT TraceLogStatus { | 38 struct BASE_EXPORT TraceLogStatus { |
| 39 TraceLogStatus(); | 39 TraceLogStatus(); |
| 40 ~TraceLogStatus(); | 40 ~TraceLogStatus(); |
| 41 uint32_t event_capacity; | 41 uint32_t event_capacity; |
| 42 uint32_t event_count; | 42 uint32_t event_count; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 class BASE_EXPORT TraceLog : public MemoryDumpProvider { | 45 class BASE_EXPORT TraceLog : public MemoryDumpProvider { |
| 46 public: | 46 public: |
| 47 enum Mode { | 47 // Argument passed to TraceLog::SetEnabled. |
| 48 DISABLED = 0, | 48 enum Mode : uint8_t { |
| 49 RECORDING_MODE | 49 // Enables normal tracing (recording trace events in the trace buffer). |
| 50 RECORDING_MODE = 1 << 0, |
| 51 |
| 52 // Trace events are enabled just for filtering but not for recording. Only |
| 53 // event filters config of |trace_config| argument is used. |
| 54 FILTERING_MODE = 1 << 1 |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 // The pointer returned from GetCategoryGroupEnabledInternal() points to a | 57 // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
| 53 // 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. |
| 54 // 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. |
| 55 // 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. |
| 56 enum CategoryGroupEnabledFlags { | 61 enum CategoryGroupEnabledFlags { |
| 57 // Category group enabled for the recording mode. | 62 // Category group enabled for the recording mode. |
| 58 ENABLED_FOR_RECORDING = 1 << 0, | 63 ENABLED_FOR_RECORDING = 1 << 0, |
| 59 // Category group enabled by SetEventCallbackEnabled(). | 64 // Category group enabled by SetEventCallbackEnabled(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 // reached. The known category groups are inserted into |category_groups|. | 75 // reached. The known category groups are inserted into |category_groups|. |
| 71 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); | 76 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); |
| 72 | 77 |
| 73 // Retrieves a copy (for thread-safety) of the current TraceConfig. | 78 // Retrieves a copy (for thread-safety) of the current TraceConfig. |
| 74 TraceConfig GetCurrentTraceConfig() const; | 79 TraceConfig GetCurrentTraceConfig() const; |
| 75 | 80 |
| 76 // Initializes the thread-local event buffer, if not already initialized and | 81 // Initializes the thread-local event buffer, if not already initialized and |
| 77 // if the current thread supports that (has a message loop). | 82 // if the current thread supports that (has a message loop). |
| 78 void InitializeThreadLocalEventBufferIfSupported(); | 83 void InitializeThreadLocalEventBufferIfSupported(); |
| 79 | 84 |
| 80 // Enables normal tracing (recording trace events in the trace buffer). | 85 // See TraceConfig comments for details on how to control which categories |
| 81 // See TraceConfig comments for details on how to control what categories | 86 // will be traced. SetDisabled must be called distinctly for each mode that is |
| 82 // will be traced. If tracing has already been enabled, |category_filter| will | 87 // enabled. If tracing has already been enabled for recording, category filter |
| 83 // be merged into the current category filter. | 88 // (enabled and disabled categories) will be merged into the current category |
| 84 void SetEnabled(const TraceConfig& trace_config, Mode mode); | 89 // filter. Enabling RECORDING_MODE does not enable filters. Trace event |
| 90 // filters will be used only if FILTERING_MODE is set on |modes_to_enable|. |
| 91 // Conversely to RECORDING_MODE, FILTERING_MODE doesn't support upgrading, |
| 92 // i.e. filters can only be enabled if not previously enabled. |
| 93 void SetEnabled(const TraceConfig& trace_config, uint8_t modes_to_enable); |
| 85 | 94 |
| 86 // Disables normal tracing for all categories. | 95 // TODO(ssid): Remove the default SetEnabled and IsEnabled. They should take |
| 96 // Mode as argument. |
| 97 |
| 98 // Disables tracing for all categories for the specified |modes_to_disable| |
| 99 // only. Only RECORDING_MODE is taken as default |modes_to_disable|. |
| 87 void SetDisabled(); | 100 void SetDisabled(); |
| 101 void SetDisabled(uint8_t modes_to_disable); |
| 88 | 102 |
| 89 bool IsEnabled() { return mode_ != DISABLED; } | 103 // Returns true if TraceLog is enabled on recording mode. |
| 104 // Note: Returns false even if FILTERING_MODE is enabled. |
| 105 bool IsEnabled() { return enabled_modes_ & RECORDING_MODE; } |
| 106 |
| 107 // Returns a bitmap of enabled modes from TraceLog::Mode. |
| 108 uint8_t enabled_modes() { return enabled_modes_; } |
| 90 | 109 |
| 91 // The number of times we have begun recording traces. If tracing is off, | 110 // The number of times we have begun recording traces. If tracing is off, |
| 92 // returns -1. If tracing is on, then it returns the number of times we have | 111 // returns -1. If tracing is on, then it returns the number of times we have |
| 93 // recorded a trace. By watching for this number to increment, you can | 112 // recorded a trace. By watching for this number to increment, you can |
| 94 // passively discover when a new trace has begun. This is then used to | 113 // passively discover when a new trace has begun. This is then used to |
| 95 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. | 114 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. |
| 96 int GetNumTracesRecorded(); | 115 int GetNumTracesRecorded(); |
| 97 | 116 |
| 98 #if defined(OS_ANDROID) | 117 #if defined(OS_ANDROID) |
| 99 void StartATrace(); | 118 void StartATrace(); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 TraceBuffer* trace_buffer() const { return logged_events_.get(); } | 445 TraceBuffer* trace_buffer() const { return logged_events_.get(); } |
| 427 TraceBuffer* CreateTraceBuffer(); | 446 TraceBuffer* CreateTraceBuffer(); |
| 428 | 447 |
| 429 std::string EventToConsoleMessage(unsigned char phase, | 448 std::string EventToConsoleMessage(unsigned char phase, |
| 430 const TimeTicks& timestamp, | 449 const TimeTicks& timestamp, |
| 431 TraceEvent* trace_event); | 450 TraceEvent* trace_event); |
| 432 | 451 |
| 433 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, | 452 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, |
| 434 bool check_buffer_is_full); | 453 bool check_buffer_is_full); |
| 435 void CheckIfBufferIsFullWhileLocked(); | 454 void CheckIfBufferIsFullWhileLocked(); |
| 436 void SetDisabledWhileLocked(); | 455 void SetDisabledWhileLocked(uint8_t modes); |
| 437 | 456 |
| 438 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, | 457 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, |
| 439 OptionalAutoLock* lock); | 458 OptionalAutoLock* lock); |
| 440 | 459 |
| 441 void FlushInternal(const OutputCallback& cb, | 460 void FlushInternal(const OutputCallback& cb, |
| 442 bool use_worker_thread, | 461 bool use_worker_thread, |
| 443 bool discard_events); | 462 bool discard_events); |
| 444 | 463 |
| 445 // |generation| is used in the following callbacks to check if the callback | 464 // |generation| is used in the following callbacks to check if the callback |
| 446 // is called for the flush of the current |logged_events_|. | 465 // is called for the flush of the current |logged_events_|. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 474 static const InternalTraceOptions kInternalEchoToConsole; | 493 static const InternalTraceOptions kInternalEchoToConsole; |
| 475 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; | 494 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; |
| 476 static const InternalTraceOptions kInternalEnableArgumentFilter; | 495 static const InternalTraceOptions kInternalEnableArgumentFilter; |
| 477 | 496 |
| 478 // This lock protects TraceLog member accesses (except for members protected | 497 // This lock protects TraceLog member accesses (except for members protected |
| 479 // by thread_info_lock_) from arbitrary threads. | 498 // by thread_info_lock_) from arbitrary threads. |
| 480 mutable Lock lock_; | 499 mutable Lock lock_; |
| 481 // This lock protects accesses to thread_names_, thread_event_start_times_ | 500 // This lock protects accesses to thread_names_, thread_event_start_times_ |
| 482 // and thread_colors_. | 501 // and thread_colors_. |
| 483 Lock thread_info_lock_; | 502 Lock thread_info_lock_; |
| 484 Mode mode_; | 503 uint8_t enabled_modes_; // See TraceLog::Mode. |
| 485 int num_traces_recorded_; | 504 int num_traces_recorded_; |
| 486 std::unique_ptr<TraceBuffer> logged_events_; | 505 std::unique_ptr<TraceBuffer> logged_events_; |
| 487 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; | 506 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; |
| 488 subtle::AtomicWord /* EventCallback */ event_callback_; | 507 subtle::AtomicWord /* EventCallback */ event_callback_; |
| 489 bool dispatching_to_observer_list_; | 508 bool dispatching_to_observer_list_; |
| 490 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 509 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
| 491 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> | 510 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> |
| 492 async_observers_; | 511 async_observers_; |
| 493 | 512 |
| 494 std::string process_name_; | 513 std::string process_name_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 512 | 531 |
| 513 // Allow tests to wake up when certain events occur. | 532 // Allow tests to wake up when certain events occur. |
| 514 WatchEventCallback watch_event_callback_; | 533 WatchEventCallback watch_event_callback_; |
| 515 subtle::AtomicWord /* const unsigned char* */ watch_category_; | 534 subtle::AtomicWord /* const unsigned char* */ watch_category_; |
| 516 std::string watch_event_name_; | 535 std::string watch_event_name_; |
| 517 | 536 |
| 518 subtle::AtomicWord /* Options */ trace_options_; | 537 subtle::AtomicWord /* Options */ trace_options_; |
| 519 | 538 |
| 520 TraceConfig trace_config_; | 539 TraceConfig trace_config_; |
| 521 TraceConfig event_callback_trace_config_; | 540 TraceConfig event_callback_trace_config_; |
| 541 TraceConfig::EventFilters enabled_event_filters_; |
| 522 | 542 |
| 523 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; | 543 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; |
| 524 ThreadLocalBoolean thread_blocks_message_loop_; | 544 ThreadLocalBoolean thread_blocks_message_loop_; |
| 525 ThreadLocalBoolean thread_is_in_trace_event_; | 545 ThreadLocalBoolean thread_is_in_trace_event_; |
| 526 | 546 |
| 527 // Contains the message loops of threads that have had at least one event | 547 // Contains the message loops of threads that have had at least one event |
| 528 // added into the local event buffer. Not using SingleThreadTaskRunner | 548 // added into the local event buffer. Not using SingleThreadTaskRunner |
| 529 // because we need to know the life time of the message loops. | 549 // because we need to know the life time of the message loops. |
| 530 hash_set<MessageLoop*> thread_message_loops_; | 550 hash_set<MessageLoop*> thread_message_loops_; |
| 531 | 551 |
| 532 // For events which can't be added into the thread local buffer, e.g. events | 552 // For events which can't be added into the thread local buffer, e.g. events |
| 533 // from threads without a message loop. | 553 // from threads without a message loop. |
| 534 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_; | 554 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_; |
| 535 size_t thread_shared_chunk_index_; | 555 size_t thread_shared_chunk_index_; |
| 536 | 556 |
| 537 // Set when asynchronous Flush is in progress. | 557 // Set when asynchronous Flush is in progress. |
| 538 OutputCallback flush_output_callback_; | 558 OutputCallback flush_output_callback_; |
| 539 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_; | 559 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_; |
| 540 ArgumentFilterPredicate argument_filter_predicate_; | 560 ArgumentFilterPredicate argument_filter_predicate_; |
| 541 subtle::AtomicWord generation_; | 561 subtle::AtomicWord generation_; |
| 542 bool use_worker_thread_; | 562 bool use_worker_thread_; |
| 543 | 563 |
| 544 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 564 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 545 }; | 565 }; |
| 546 | 566 |
| 547 } // namespace trace_event | 567 } // namespace trace_event |
| 548 } // namespace base | 568 } // namespace base |
| 549 | 569 |
| 550 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ | 570 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ |
| OLD | NEW |