Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: base/trace_event/trace_log.h

Issue 1956323002: Introduce TraceLog::AsyncEnabledStateObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_log.cc » ('j') | base/trace_event/trace_log.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 #if defined(OS_ANDROID) 97 #if defined(OS_ANDROID)
98 void StartATrace(); 98 void StartATrace();
99 void StopATrace(); 99 void StopATrace();
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 // TODO(xiaochengh): Deprecate this class. Migrate all its subclasses under
Primiano Tucci (use gerrit) 2016/05/09 17:18:29 I will be happy if we can remove all callers to th
Xiaocheng 2016/05/10 09:33:35 Yeah, a deprecation of this class seems too much.
107 // ThreadSafeEnabledStateObserver.
106 class BASE_EXPORT EnabledStateObserver { 108 class BASE_EXPORT EnabledStateObserver {
107 public: 109 public:
108 virtual ~EnabledStateObserver() = default; 110 virtual ~EnabledStateObserver() = default;
109 111
110 // Called just after the tracing system becomes enabled, outside of the 112 // Called just after the tracing system becomes enabled, outside of the
111 // |lock_|. TraceLog::IsEnabled() is true at this point. 113 // |lock_|. TraceLog::IsEnabled() is true at this point.
112 virtual void OnTraceLogEnabled() = 0; 114 virtual void OnTraceLogEnabled() = 0;
113 115
114 // Called just after the tracing system disables, outside of the |lock_|. 116 // Called just after the tracing system disables, outside of the |lock_|.
115 // TraceLog::IsEnabled() is false at this point. 117 // TraceLog::IsEnabled() is false at this point.
116 virtual void OnTraceLogDisabled() = 0; 118 virtual void OnTraceLogDisabled() = 0;
117 }; 119 };
118 void AddEnabledStateObserver(EnabledStateObserver* listener); 120 void AddEnabledStateObserver(EnabledStateObserver* listener);
119 void RemoveEnabledStateObserver(EnabledStateObserver* listener); 121 void RemoveEnabledStateObserver(EnabledStateObserver* listener);
120 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; 122 bool HasEnabledStateObserver(EnabledStateObserver* listener) const;
121 123
124 // Enabled state listeners give a callback when tracing is enabled or
125 // disabled. This can be used to tie into other library's tracing systems
126 // on-demand.
Primiano Tucci (use gerrit) 2016/05/09 17:18:29 I think the important information to convey to thi
Xiaocheng 2016/05/10 09:33:34 Done.
127 class BASE_EXPORT ThreadSafeEnabledStateObserver {
128 public:
129 virtual ~ThreadSafeEnabledStateObserver() = default;
130
131 // Called just after the tracing system becomes enabled.
132 // TraceLog::IsEnabled() is true at this point.
133 virtual void OnTraceLogEnabled() = 0;
134
135 // Called just after the tracing system becomes disabled.
136 // TraceLog::IsEnabled() is false at this point.
137 virtual void OnTraceLogDisabled() = 0;
138 };
139 // Assigns a unique id to the listener, and returns the id to the caller.
140 int AddThreadSafeEnabledStateObserver(
Primiano Tucci (use gerrit) 2016/05/09 17:18:29 instea of returning an int, can we just make the T
Xiaocheng 2016/05/10 09:33:35 That's neat. Done.
141 WeakPtr<ThreadSafeEnabledStateObserver> listener);
142 void RemoveThreadSafeEnabledStateObserver(int listener_id);
143 bool HasThreadSafeEnabledStateObserver(int listener_id) const;
144 size_t GetThreadSafeObserverCountForTest() const;
Primiano Tucci (use gerrit) 2016/05/09 17:18:29 this doesn't seem to be used in the current CL
Xiaocheng 2016/05/10 09:33:35 Removed. It's not even useful in test.
145
122 TraceLogStatus GetStatus() const; 146 TraceLogStatus GetStatus() const;
123 bool BufferIsFull() const; 147 bool BufferIsFull() const;
124 148
125 // Computes an estimate of the size of the TraceLog including all the retained 149 // Computes an estimate of the size of the TraceLog including all the retained
126 // objects. 150 // objects.
127 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); 151 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead);
128 152
129 // Not using base::Callback because of its limited by 7 parameters. 153 // Not using base::Callback because of its limited by 7 parameters.
130 // Also, using primitive type allows directly passing callback from WebCore. 154 // Also, using primitive type allows directly passing callback from WebCore.
131 // WARNING: It is possible for the previously set callback to be called 155 // WARNING: It is possible for the previously set callback to be called
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 382
359 // Configure synthetic delays based on the values set in the current 383 // Configure synthetic delays based on the values set in the current
360 // trace config. 384 // trace config.
361 void UpdateSyntheticDelaysFromTraceConfig(); 385 void UpdateSyntheticDelaysFromTraceConfig();
362 386
363 InternalTraceOptions GetInternalOptionsFromTraceConfig( 387 InternalTraceOptions GetInternalOptionsFromTraceConfig(
364 const TraceConfig& config); 388 const TraceConfig& config);
365 389
366 class ThreadLocalEventBuffer; 390 class ThreadLocalEventBuffer;
367 class OptionalAutoLock; 391 class OptionalAutoLock;
392 struct RegisteredThreadSafeObserver;
368 393
369 TraceLog(); 394 TraceLog();
370 ~TraceLog() override; 395 ~TraceLog() override;
371 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); 396 const unsigned char* GetCategoryGroupEnabledInternal(const char* name);
372 void AddMetadataEventsWhileLocked(); 397 void AddMetadataEventsWhileLocked();
373 398
374 InternalTraceOptions trace_options() const { 399 InternalTraceOptions trace_options() const {
375 return static_cast<InternalTraceOptions>( 400 return static_cast<InternalTraceOptions>(
376 subtle::NoBarrier_Load(&trace_options_)); 401 subtle::NoBarrier_Load(&trace_options_));
377 } 402 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // and thread_colors_. 461 // and thread_colors_.
437 Lock thread_info_lock_; 462 Lock thread_info_lock_;
438 Mode mode_; 463 Mode mode_;
439 int num_traces_recorded_; 464 int num_traces_recorded_;
440 std::unique_ptr<TraceBuffer> logged_events_; 465 std::unique_ptr<TraceBuffer> logged_events_;
441 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; 466 std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
442 subtle::AtomicWord /* EventCallback */ event_callback_; 467 subtle::AtomicWord /* EventCallback */ event_callback_;
443 bool dispatching_to_observer_list_; 468 bool dispatching_to_observer_list_;
444 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 469 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
445 470
471 std::map<int, RegisteredThreadSafeObserver> thread_safe_observers_;
472
446 std::string process_name_; 473 std::string process_name_;
447 base::hash_map<int, std::string> process_labels_; 474 base::hash_map<int, std::string> process_labels_;
448 int process_sort_index_; 475 int process_sort_index_;
449 base::hash_map<int, int> thread_sort_indices_; 476 base::hash_map<int, int> thread_sort_indices_;
450 base::hash_map<int, std::string> thread_names_; 477 base::hash_map<int, std::string> thread_names_;
451 478
452 // The following two maps are used only when ECHO_TO_CONSOLE. 479 // The following two maps are used only when ECHO_TO_CONSOLE.
453 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; 480 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_;
454 base::hash_map<std::string, int> thread_colors_; 481 base::hash_map<std::string, int> thread_colors_;
455 482
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 subtle::AtomicWord generation_; 524 subtle::AtomicWord generation_;
498 bool use_worker_thread_; 525 bool use_worker_thread_;
499 526
500 DISALLOW_COPY_AND_ASSIGN(TraceLog); 527 DISALLOW_COPY_AND_ASSIGN(TraceLog);
501 }; 528 };
502 529
503 } // namespace trace_event 530 } // namespace trace_event
504 } // namespace base 531 } // namespace base
505 532
506 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ 533 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_log.cc » ('j') | base/trace_event/trace_log.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698