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

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: Fix more compile error 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
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
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/atomicops.h" 15 #include "base/atomicops.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/trace_event/memory_dump_provider.h" 20 #include "base/trace_event/memory_dump_provider.h"
21 #include "base/trace_event/trace_config.h" 21 #include "base/trace_event/trace_config.h"
22 #include "base/trace_event/trace_event_impl.h" 22 #include "base/trace_event/trace_event_impl.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
Primiano Tucci (use gerrit) 2016/05/10 14:20:26 add an explicit include to weak_ptr.h as you are u
24 24
25 namespace base { 25 namespace base {
26 26
27 template <typename Type> 27 template <typename Type>
28 struct DefaultSingletonTraits; 28 struct DefaultSingletonTraits;
29 class RefCountedString; 29 class RefCountedString;
30 30
31 namespace trace_event { 31 namespace trace_event {
32 32
33 class TraceBuffer; 33 class TraceBuffer;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 int GetNumTracesRecorded(); 95 int GetNumTracesRecorded();
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.
Primiano Tucci (use gerrit) 2016/05/10 14:20:26 Please add a comment here saying: Thread safety:
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 the
111 // |lock_|. TraceLog::IsEnabled() is true at this point. 111 // |lock_|. TraceLog::IsEnabled() is true at this point.
112 virtual void OnTraceLogEnabled() = 0; 112 virtual void OnTraceLogEnabled() = 0;
113 113
114 // Called just after the tracing system disables, outside of the |lock_|. 114 // Called just after the tracing system disables, outside of the |lock_|.
115 // TraceLog::IsEnabled() is false at this point. 115 // TraceLog::IsEnabled() is false at this point.
116 virtual void OnTraceLogDisabled() = 0; 116 virtual void OnTraceLogDisabled() = 0;
117 }; 117 };
118 void AddEnabledStateObserver(EnabledStateObserver* listener); 118 void AddEnabledStateObserver(EnabledStateObserver* listener);
119 void RemoveEnabledStateObserver(EnabledStateObserver* listener); 119 void RemoveEnabledStateObserver(EnabledStateObserver* listener);
120 bool HasEnabledStateObserver(EnabledStateObserver* listener) const; 120 bool HasEnabledStateObserver(EnabledStateObserver* listener) const;
121 121
122 // Asynchronous enabled state listeners. When tracing is enabled or disabled,
123 // for each observer, a task for invoking its appropriate callback is posted
124 // to the thread from which AddAsyncEnabledStateObserver() was called.
125 class BASE_EXPORT AsyncEnabledStateObserver {
Primiano Tucci (use gerrit) 2016/05/10 14:20:26 Add: this allows the observer to be safely destroy
Xiaocheng 2016/05/11 05:19:20 Done.
126 public:
127 virtual ~AsyncEnabledStateObserver() = default;
128
129 // Posted just after the tracing system becomes enabled.
130 // TraceLog::IsEnabled() is true at this point.
131 virtual void OnTraceLogEnabled() = 0;
132
133 // Posted just after the tracing system becomes disabled.
134 // TraceLog::IsEnabled() is false at this point.
135 virtual void OnTraceLogDisabled() = 0;
136 };
137 void AddAsyncEnabledStateObserver(
138 WeakPtr<AsyncEnabledStateObserver> listener);
139 void RemoveAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener);
140 bool HasAsyncEnabledStateObserver(AsyncEnabledStateObserver* listener) const;
141
122 TraceLogStatus GetStatus() const; 142 TraceLogStatus GetStatus() const;
123 bool BufferIsFull() const; 143 bool BufferIsFull() const;
124 144
125 // Computes an estimate of the size of the TraceLog including all the retained 145 // Computes an estimate of the size of the TraceLog including all the retained
126 // objects. 146 // objects.
127 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); 147 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead);
128 148
129 // Not using base::Callback because of its limited by 7 parameters. 149 // Not using base::Callback because of its limited by 7 parameters.
130 // Also, using primitive type allows directly passing callback from WebCore. 150 // Also, using primitive type allows directly passing callback from WebCore.
131 // WARNING: It is possible for the previously set callback to be called 151 // 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 378
359 // Configure synthetic delays based on the values set in the current 379 // Configure synthetic delays based on the values set in the current
360 // trace config. 380 // trace config.
361 void UpdateSyntheticDelaysFromTraceConfig(); 381 void UpdateSyntheticDelaysFromTraceConfig();
362 382
363 InternalTraceOptions GetInternalOptionsFromTraceConfig( 383 InternalTraceOptions GetInternalOptionsFromTraceConfig(
364 const TraceConfig& config); 384 const TraceConfig& config);
365 385
366 class ThreadLocalEventBuffer; 386 class ThreadLocalEventBuffer;
367 class OptionalAutoLock; 387 class OptionalAutoLock;
388 struct RegisteredAsyncObserver;
368 389
369 TraceLog(); 390 TraceLog();
370 ~TraceLog() override; 391 ~TraceLog() override;
371 const unsigned char* GetCategoryGroupEnabledInternal(const char* name); 392 const unsigned char* GetCategoryGroupEnabledInternal(const char* name);
372 void AddMetadataEventsWhileLocked(); 393 void AddMetadataEventsWhileLocked();
373 394
374 InternalTraceOptions trace_options() const { 395 InternalTraceOptions trace_options() const {
375 return static_cast<InternalTraceOptions>( 396 return static_cast<InternalTraceOptions>(
376 subtle::NoBarrier_Load(&trace_options_)); 397 subtle::NoBarrier_Load(&trace_options_));
377 } 398 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 static const InternalTraceOptions kInternalRecordContinuously; 447 static const InternalTraceOptions kInternalRecordContinuously;
427 static const InternalTraceOptions kInternalEchoToConsole; 448 static const InternalTraceOptions kInternalEchoToConsole;
428 static const InternalTraceOptions kInternalEnableSampling; 449 static const InternalTraceOptions kInternalEnableSampling;
429 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; 450 static const InternalTraceOptions kInternalRecordAsMuchAsPossible;
430 static const InternalTraceOptions kInternalEnableArgumentFilter; 451 static const InternalTraceOptions kInternalEnableArgumentFilter;
431 452
432 // This lock protects TraceLog member accesses (except for members protected 453 // This lock protects TraceLog member accesses (except for members protected
433 // by thread_info_lock_) from arbitrary threads. 454 // by thread_info_lock_) from arbitrary threads.
434 mutable Lock lock_; 455 mutable Lock lock_;
435 // This lock protects accesses to thread_names_, thread_event_start_times_ 456 // This lock protects accesses to thread_names_, thread_event_start_times_
436 // and thread_colors_. 457 // and thread_colors_.
Primiano Tucci (use gerrit) 2016/05/10 14:20:26 + and observers lists
437 Lock thread_info_lock_; 458 Lock thread_info_lock_;
438 Mode mode_; 459 Mode mode_;
439 int num_traces_recorded_; 460 int num_traces_recorded_;
440 std::unique_ptr<TraceBuffer> logged_events_; 461 std::unique_ptr<TraceBuffer> logged_events_;
441 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; 462 std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
442 subtle::AtomicWord /* EventCallback */ event_callback_; 463 subtle::AtomicWord /* EventCallback */ event_callback_;
443 bool dispatching_to_observer_list_; 464 bool dispatching_to_observer_list_;
444 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 465 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
445 466
Primiano Tucci (use gerrit) 2016/05/10 14:20:26 nit: remove the blank line 466 as this logically s
Xiaocheng 2016/05/11 05:19:20 Done. It's just my personal bad habit of inserting
467 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver>
468 async_observers_;
469
446 std::string process_name_; 470 std::string process_name_;
447 base::hash_map<int, std::string> process_labels_; 471 base::hash_map<int, std::string> process_labels_;
448 int process_sort_index_; 472 int process_sort_index_;
449 base::hash_map<int, int> thread_sort_indices_; 473 base::hash_map<int, int> thread_sort_indices_;
450 base::hash_map<int, std::string> thread_names_; 474 base::hash_map<int, std::string> thread_names_;
451 475
452 // The following two maps are used only when ECHO_TO_CONSOLE. 476 // The following two maps are used only when ECHO_TO_CONSOLE.
453 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_; 477 base::hash_map<int, std::stack<TimeTicks>> thread_event_start_times_;
454 base::hash_map<std::string, int> thread_colors_; 478 base::hash_map<std::string, int> thread_colors_;
455 479
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 subtle::AtomicWord generation_; 521 subtle::AtomicWord generation_;
498 bool use_worker_thread_; 522 bool use_worker_thread_;
499 523
500 DISALLOW_COPY_AND_ASSIGN(TraceLog); 524 DISALLOW_COPY_AND_ASSIGN(TraceLog);
501 }; 525 };
502 526
503 } // namespace trace_event 527 } // namespace trace_event
504 } // namespace base 528 } // namespace base
505 529
506 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ 530 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698