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

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

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

Powered by Google App Engine
This is Rietveld 408576698