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

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

Issue 2323483005: [tracing] Add filtering mode in TraceLog (Closed)
Patch Set: Fixes. Created 4 years, 3 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
(...skipping 27 matching lines...) Expand all
38 38
39 struct BASE_EXPORT TraceLogStatus { 39 struct BASE_EXPORT TraceLogStatus {
40 TraceLogStatus(); 40 TraceLogStatus();
41 ~TraceLogStatus(); 41 ~TraceLogStatus();
42 uint32_t event_capacity; 42 uint32_t event_capacity;
43 uint32_t event_count; 43 uint32_t event_count;
44 }; 44 };
45 45
46 class BASE_EXPORT TraceLog : public MemoryDumpProvider { 46 class BASE_EXPORT TraceLog : public MemoryDumpProvider {
47 public: 47 public:
48 enum Mode { 48 // Argument passed to TrcaeLog::SetEnabled.
49 DISABLED = 0, 49 enum Mode { RECORDING_MODE = 1 << 0, FILTERING_MODE = 1 << 1 };
Primiano Tucci (use gerrit) 2016/09/23 18:34:32 enum Mode : uint8_t { ... } to match the uint8_t b
ssid 2016/09/26 18:39:53 Done.
50 RECORDING_MODE
51 };
52 50
53 // The pointer returned from GetCategoryGroupEnabledInternal() points to a 51 // The pointer returned from GetCategoryGroupEnabledInternal() points to a
54 // value with zero or more of the following bits. Used in this class only. 52 // value with zero or more of the following bits. Used in this class only.
55 // The TRACE_EVENT macros should only use the value as a bool. 53 // The TRACE_EVENT macros should only use the value as a bool.
56 // These values must be in sync with macro values in TraceEvent.h in Blink. 54 // These values must be in sync with macro values in TraceEvent.h in Blink.
57 enum CategoryGroupEnabledFlags { 55 enum CategoryGroupEnabledFlags {
58 // Category group enabled for the recording mode. 56 // Category group enabled for the recording mode.
59 ENABLED_FOR_RECORDING = 1 << 0, 57 ENABLED_FOR_RECORDING = 1 << 0,
60 // Category group enabled by SetEventCallbackEnabled(). 58 // Category group enabled by SetEventCallbackEnabled().
61 ENABLED_FOR_EVENT_CALLBACK = 1 << 2, 59 ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
62 // Category group enabled to export events to ETW. 60 // Category group enabled to export events to ETW.
63 ENABLED_FOR_ETW_EXPORT = 1 << 3, 61 ENABLED_FOR_ETW_EXPORT = 1 << 3,
64 // Category group being filtered before logged. 62 // Category group being filtered before logged.
65 ENABLED_FOR_FILTERING = 1 << 4 63 ENABLED_FOR_FILTERING = 1 << 4
66 }; 64 };
67 65
68 static TraceLog* GetInstance(); 66 static TraceLog* GetInstance();
69 67
70 // Get set of known category groups. This can change as new code paths are 68 // Get set of known category groups. This can change as new code paths are
71 // reached. The known category groups are inserted into |category_groups|. 69 // reached. The known category groups are inserted into |category_groups|.
72 void GetKnownCategoryGroups(std::vector<std::string>* category_groups); 70 void GetKnownCategoryGroups(std::vector<std::string>* category_groups);
73 71
74 // Retrieves a copy (for thread-safety) of the current TraceConfig. 72 // Retrieves a copy (for thread-safety) of the current TraceConfig.
75 TraceConfig GetCurrentTraceConfig() const; 73 TraceConfig GetCurrentTraceConfig() const;
76 74
77 // Initializes the thread-local event buffer, if not already initialized and 75 // Initializes the thread-local event buffer, if not already initialized and
78 // if the current thread supports that (has a message loop). 76 // if the current thread supports that (has a message loop).
79 void InitializeThreadLocalEventBufferIfSupported(); 77 void InitializeThreadLocalEventBufferIfSupported();
80 78
81 // Enables normal tracing (recording trace events in the trace buffer).
82 // See TraceConfig comments for details on how to control what categories 79 // See TraceConfig comments for details on how to control what categories
83 // will be traced. If tracing has already been enabled, |category_filter| will 80 // will be traced. SetDisabled must be called for each mode that is enabled.
84 // be merged into the current category filter. 81 // RECORDING_MODE: Enables normal tracing (recording trace events in the trace
85 void SetEnabled(const TraceConfig& trace_config, Mode mode); 82 // buffer).
83 // FILTERING_MODE: Trace events are enabled just for filtering but not for
84 // recording. TraceLog::IsEnabled still returns false when
85 // running in this mode. Only event filters config of
86 // |trace_config| argument is used.
87 // If tracing has already been enabled, category filter (enabled and disabled
88 // categories) will be merged into the current category filter, and trace
89 // event filters will be used only if filtering was not enabled already.
90 void SetEnabled(const TraceConfig& trace_config, Mode new_mode);
86 91
87 // Disables normal tracing for all categories. 92 // Disables tracing for all categories for the specified |mode| only. Default
93 // |mode| is taken as RECORDING_MODE.
88 void SetDisabled(); 94 void SetDisabled();
95 void SetDisabled(Mode mode);
89 96
90 bool IsEnabled() { return mode_ != DISABLED; } 97 // Returns true if TraceLog is enabled on recording mode.
98 // Note: Returns false even if FILTERING_MODE is enabled.
99 bool IsEnabled() { return enabled_modes_ & RECORDING_MODE; }
100
101 // Returns a bitmap of enabled modes from TraceLog::Mode.
102 uint8_t enabled_modes() { return enabled_modes_; }
103
104 // Returns true if filters are enabled, irrespective of the recording mode.
105 bool HaveActiveFilters();
91 106
92 // The number of times we have begun recording traces. If tracing is off, 107 // The number of times we have begun recording traces. If tracing is off,
93 // returns -1. If tracing is on, then it returns the number of times we have 108 // returns -1. If tracing is on, then it returns the number of times we have
94 // recorded a trace. By watching for this number to increment, you can 109 // recorded a trace. By watching for this number to increment, you can
95 // passively discover when a new trace has begun. This is then used to 110 // passively discover when a new trace has begun. This is then used to
96 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. 111 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive.
97 int GetNumTracesRecorded(); 112 int GetNumTracesRecorded();
98 113
99 #if defined(OS_ANDROID) 114 #if defined(OS_ANDROID)
100 void StartATrace(); 115 void StartATrace();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 TraceBuffer* trace_buffer() const { return logged_events_.get(); } 444 TraceBuffer* trace_buffer() const { return logged_events_.get(); }
430 TraceBuffer* CreateTraceBuffer(); 445 TraceBuffer* CreateTraceBuffer();
431 446
432 std::string EventToConsoleMessage(unsigned char phase, 447 std::string EventToConsoleMessage(unsigned char phase,
433 const TimeTicks& timestamp, 448 const TimeTicks& timestamp,
434 TraceEvent* trace_event); 449 TraceEvent* trace_event);
435 450
436 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, 451 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle,
437 bool check_buffer_is_full); 452 bool check_buffer_is_full);
438 void CheckIfBufferIsFullWhileLocked(); 453 void CheckIfBufferIsFullWhileLocked();
439 void SetDisabledWhileLocked(); 454 void SetDisabledWhileLocked(Mode mode);
440 455
441 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, 456 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle,
442 OptionalAutoLock* lock); 457 OptionalAutoLock* lock);
443 458
444 void FlushInternal(const OutputCallback& cb, 459 void FlushInternal(const OutputCallback& cb,
445 bool use_worker_thread, 460 bool use_worker_thread,
446 bool discard_events); 461 bool discard_events);
447 462
448 // |generation| is used in the following callbacks to check if the callback 463 // |generation| is used in the following callbacks to check if the callback
449 // is called for the flush of the current |logged_events_|. 464 // is called for the flush of the current |logged_events_|.
(...skipping 28 matching lines...) Expand all
478 static const InternalTraceOptions kInternalEnableSampling; 493 static const InternalTraceOptions kInternalEnableSampling;
479 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; 494 static const InternalTraceOptions kInternalRecordAsMuchAsPossible;
480 static const InternalTraceOptions kInternalEnableArgumentFilter; 495 static const InternalTraceOptions kInternalEnableArgumentFilter;
481 496
482 // This lock protects TraceLog member accesses (except for members protected 497 // This lock protects TraceLog member accesses (except for members protected
483 // by thread_info_lock_) from arbitrary threads. 498 // by thread_info_lock_) from arbitrary threads.
484 mutable Lock lock_; 499 mutable Lock lock_;
485 // This lock protects accesses to thread_names_, thread_event_start_times_ 500 // This lock protects accesses to thread_names_, thread_event_start_times_
486 // and thread_colors_. 501 // and thread_colors_.
487 Lock thread_info_lock_; 502 Lock thread_info_lock_;
488 Mode mode_; 503 uint8_t enabled_modes_; // See TraceLog::Mode.
489 int num_traces_recorded_; 504 int num_traces_recorded_;
490 std::unique_ptr<TraceBuffer> logged_events_; 505 std::unique_ptr<TraceBuffer> logged_events_;
491 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; 506 std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
492 subtle::AtomicWord /* EventCallback */ event_callback_; 507 subtle::AtomicWord /* EventCallback */ event_callback_;
493 bool dispatching_to_observer_list_; 508 bool dispatching_to_observer_list_;
494 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 509 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
495 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> 510 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver>
496 async_observers_; 511 async_observers_;
497 512
498 std::string process_name_; 513 std::string process_name_;
(...skipping 21 matching lines...) Expand all
520 std::string watch_event_name_; 535 std::string watch_event_name_;
521 536
522 subtle::AtomicWord /* Options */ trace_options_; 537 subtle::AtomicWord /* Options */ trace_options_;
523 538
524 // Sampling thread handles. 539 // Sampling thread handles.
525 std::unique_ptr<TraceSamplingThread> sampling_thread_; 540 std::unique_ptr<TraceSamplingThread> sampling_thread_;
526 PlatformThreadHandle sampling_thread_handle_; 541 PlatformThreadHandle sampling_thread_handle_;
527 542
528 TraceConfig trace_config_; 543 TraceConfig trace_config_;
529 TraceConfig event_callback_trace_config_; 544 TraceConfig event_callback_trace_config_;
545 TraceConfig::EventFilters event_filters_enabled_;
530 546
531 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; 547 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
532 ThreadLocalBoolean thread_blocks_message_loop_; 548 ThreadLocalBoolean thread_blocks_message_loop_;
533 ThreadLocalBoolean thread_is_in_trace_event_; 549 ThreadLocalBoolean thread_is_in_trace_event_;
534 550
535 // Contains the message loops of threads that have had at least one event 551 // Contains the message loops of threads that have had at least one event
536 // added into the local event buffer. Not using SingleThreadTaskRunner 552 // added into the local event buffer. Not using SingleThreadTaskRunner
537 // because we need to know the life time of the message loops. 553 // because we need to know the life time of the message loops.
538 hash_set<MessageLoop*> thread_message_loops_; 554 hash_set<MessageLoop*> thread_message_loops_;
539 555
540 // For events which can't be added into the thread local buffer, e.g. events 556 // For events which can't be added into the thread local buffer, e.g. events
541 // from threads without a message loop. 557 // from threads without a message loop.
542 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_; 558 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_;
543 size_t thread_shared_chunk_index_; 559 size_t thread_shared_chunk_index_;
544 560
545 // Set when asynchronous Flush is in progress. 561 // Set when asynchronous Flush is in progress.
546 OutputCallback flush_output_callback_; 562 OutputCallback flush_output_callback_;
547 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_; 563 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_;
548 ArgumentFilterPredicate argument_filter_predicate_; 564 ArgumentFilterPredicate argument_filter_predicate_;
549 subtle::AtomicWord generation_; 565 subtle::AtomicWord generation_;
550 bool use_worker_thread_; 566 bool use_worker_thread_;
551 567
552 DISALLOW_COPY_AND_ASSIGN(TraceLog); 568 DISALLOW_COPY_AND_ASSIGN(TraceLog);
553 }; 569 };
554 570
555 } // namespace trace_event 571 } // namespace trace_event
556 } // namespace base 572 } // namespace base
557 573
558 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ 574 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698