| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void AddClockSyncMetadataEvent(); | 100 void AddClockSyncMetadataEvent(); |
| 101 #endif | 101 #endif |
| 102 | 102 |
| 103 // Enabled state listeners give a callback when tracing is enabled or | 103 // Enabled state listeners give a callback when tracing is enabled or |
| 104 // disabled. This can be used to tie into other library's tracing systems | 104 // disabled. This can be used to tie into other library's tracing systems |
| 105 // on-demand. | 105 // on-demand. |
| 106 class BASE_EXPORT EnabledStateObserver { | 106 class BASE_EXPORT EnabledStateObserver { |
| 107 public: | 107 public: |
| 108 virtual ~EnabledStateObserver() = default; | 108 virtual ~EnabledStateObserver() = default; |
| 109 | 109 |
| 110 // Called just after the tracing system becomes enabled, outside of the | 110 // Called just after the tracing system becomes enabled, outside of |lock_| |
| 111 // |lock_|. TraceLog::IsEnabled() is true at this point. | 111 // but inside of |observer_list_lock_|. TraceLog::IsEnabled() is true at |
| 112 // this point. Any subclass MUST NOT access |enabled_state_observer_list_| |
| 113 // in the callback (e.g., via any |TraceLog::FooEnabledStateObserver()|), |
| 114 // which would otherwise cause a deadlock. |
| 112 virtual void OnTraceLogEnabled() = 0; | 115 virtual void OnTraceLogEnabled() = 0; |
| 113 | 116 |
| 114 // Called just after the tracing system disables, outside of the |lock_|. | 117 // Called just after the tracing system disables, outside of |lock_| but |
| 115 // TraceLog::IsEnabled() is false at this point. | 118 // inside of |observer_list_lock_|. TraceLog::IsEnabled() is false at this |
| 119 // point. Any subclass MUST NOT access |enabled_state_observer_list_| in the |
| 120 // callback (e.g., via any |TraceLog::FooEnabledStateObserver()|), which |
| 121 // would otherwise cause a deadlock. |
| 116 virtual void OnTraceLogDisabled() = 0; | 122 virtual void OnTraceLogDisabled() = 0; |
| 117 }; | 123 }; |
| 118 void AddEnabledStateObserver(EnabledStateObserver* listener); | 124 void AddEnabledStateObserver(EnabledStateObserver* listener); |
| 119 void RemoveEnabledStateObserver(EnabledStateObserver* listener); | 125 void RemoveEnabledStateObserver(EnabledStateObserver* listener); |
| 120 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; | 126 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; |
| 121 | 127 |
| 122 TraceLogStatus GetStatus() const; | 128 TraceLogStatus GetStatus() const; |
| 123 bool BufferIsFull() const; | 129 bool BufferIsFull() const; |
| 124 | 130 |
| 125 // Computes an estimate of the size of the TraceLog including all the retained | 131 // Computes an estimate of the size of the TraceLog including all the retained |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // trace option as an AtomicWord. | 429 // trace option as an AtomicWord. |
| 424 static const InternalTraceOptions kInternalNone; | 430 static const InternalTraceOptions kInternalNone; |
| 425 static const InternalTraceOptions kInternalRecordUntilFull; | 431 static const InternalTraceOptions kInternalRecordUntilFull; |
| 426 static const InternalTraceOptions kInternalRecordContinuously; | 432 static const InternalTraceOptions kInternalRecordContinuously; |
| 427 static const InternalTraceOptions kInternalEchoToConsole; | 433 static const InternalTraceOptions kInternalEchoToConsole; |
| 428 static const InternalTraceOptions kInternalEnableSampling; | 434 static const InternalTraceOptions kInternalEnableSampling; |
| 429 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; | 435 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; |
| 430 static const InternalTraceOptions kInternalEnableArgumentFilter; | 436 static const InternalTraceOptions kInternalEnableArgumentFilter; |
| 431 | 437 |
| 432 // This lock protects TraceLog member accesses (except for members protected | 438 // This lock protects TraceLog member accesses (except for members protected |
| 433 // by thread_info_lock_) from arbitrary threads. | 439 // by thread_info_lock_ or observer_list_lock_) from arbitrary threads. |
| 434 mutable Lock lock_; | 440 mutable Lock lock_; |
| 435 // This lock protects accesses to thread_names_, thread_event_start_times_ | 441 // This lock protects accesses to thread_names_, thread_event_start_times_ |
| 436 // and thread_colors_. | 442 // and thread_colors_. |
| 437 Lock thread_info_lock_; | 443 Lock thread_info_lock_; |
| 438 Mode mode_; | 444 Mode mode_; |
| 439 int num_traces_recorded_; | 445 int num_traces_recorded_; |
| 440 std::unique_ptr<TraceBuffer> logged_events_; | 446 std::unique_ptr<TraceBuffer> logged_events_; |
| 441 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; | 447 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; |
| 442 subtle::AtomicWord /* EventCallback */ event_callback_; | 448 subtle::AtomicWord /* EventCallback */ event_callback_; |
| 449 |
| 450 // This lock protects accesses to enabled_state_observer_list_. |
| 451 mutable Lock observer_list_lock_; |
| 443 bool dispatching_to_observer_list_; | 452 bool dispatching_to_observer_list_; |
| 453 // TODO(xiaochengh): Replace these raw pointers by weak pointers and direct |
| 454 // callbacks by task posting, so that we can get rid of the current nasty |
| 455 // and complicated handling of threading issues. |
| 444 std::vector<EnabledStateObserver*> enabled_state_observer_list_; | 456 std::vector<EnabledStateObserver*> enabled_state_observer_list_; |
| 445 | 457 |
| 446 std::string process_name_; | 458 std::string process_name_; |
| 447 base::hash_map<int, std::string> process_labels_; | 459 base::hash_map<int, std::string> process_labels_; |
| 448 int process_sort_index_; | 460 int process_sort_index_; |
| 449 base::hash_map<int, int> thread_sort_indices_; | 461 base::hash_map<int, int> thread_sort_indices_; |
| 450 base::hash_map<int, std::string> thread_names_; | 462 base::hash_map<int, std::string> thread_names_; |
| 451 | 463 |
| 452 // The following two maps are used only when ECHO_TO_CONSOLE. | 464 // The following two maps are used only when ECHO_TO_CONSOLE. |
| 453 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; | 465 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 subtle::AtomicWord generation_; | 509 subtle::AtomicWord generation_; |
| 498 bool use_worker_thread_; | 510 bool use_worker_thread_; |
| 499 | 511 |
| 500 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 512 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 501 }; | 513 }; |
| 502 | 514 |
| 503 } // namespace trace_event | 515 } // namespace trace_event |
| 504 } // namespace base | 516 } // namespace base |
| 505 | 517 |
| 506 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ | 518 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ |
| OLD | NEW |