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