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

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

Issue 2323483005: [tracing] Add filtering mode in TraceLog (Closed)
Patch Set: 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
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »
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 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 };
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 mode_ & RECORDING_MODE; }
oystein (OOO til 10th of July) 2016/09/22 19:21:06 I think we should rename this to IsEnabledForRecor
ssid 2016/09/22 19:37:43 Do you mind if I do this as a separate clean up CL
oystein (OOO til 10th of July) 2016/09/22 20:16:42 Yep that's fine.
100
101 // Returns true if filters are enabled, irrespective of the recording mode.
102 bool IsFilteringEnabled();
oystein (OOO til 10th of July) 2016/09/22 19:21:06 What's the reason for not just checking for filter
ssid 2016/09/22 19:37:43 So, I really need to check if filters are enabled
oystein (OOO til 10th of July) 2016/09/22 20:16:42 Okay, that makes sense.I think I'd avoid "Enabled"
91 103
92 // The number of times we have begun recording traces. If tracing is off, 104 // 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 105 // 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 106 // 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 107 // passively discover when a new trace has begun. This is then used to
96 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive. 108 // implement the TRACE_EVENT_IS_NEW_TRACE() primitive.
97 int GetNumTracesRecorded(); 109 int GetNumTracesRecorded();
98 110
99 #if defined(OS_ANDROID) 111 #if defined(OS_ANDROID)
100 void StartATrace(); 112 void StartATrace();
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 389
378 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 390 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
379 TraceBufferRingBufferGetReturnChunk); 391 TraceBufferRingBufferGetReturnChunk);
380 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 392 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
381 TraceBufferRingBufferHalfIteration); 393 TraceBufferRingBufferHalfIteration);
382 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 394 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
383 TraceBufferRingBufferFullIteration); 395 TraceBufferRingBufferFullIteration);
384 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, TraceBufferVectorReportFull); 396 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, TraceBufferVectorReportFull);
385 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 397 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
386 ConvertTraceConfigToInternalOptions); 398 ConvertTraceConfigToInternalOptions);
399 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, TraceFilteringMode);
387 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, 400 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture,
388 TraceRecordAsMuchAsPossibleMode); 401 TraceRecordAsMuchAsPossibleMode);
389 402
390 // This allows constructor and destructor to be private and usable only 403 // This allows constructor and destructor to be private and usable only
391 // by the Singleton class. 404 // by the Singleton class.
392 friend struct DefaultSingletonTraits<TraceLog>; 405 friend struct DefaultSingletonTraits<TraceLog>;
393 406
394 // MemoryDumpProvider implementation. 407 // MemoryDumpProvider implementation.
395 bool OnMemoryDump(const MemoryDumpArgs& args, 408 bool OnMemoryDump(const MemoryDumpArgs& args,
396 ProcessMemoryDump* pmd) override; 409 ProcessMemoryDump* pmd) override;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 TraceBuffer* trace_buffer() const { return logged_events_.get(); } 442 TraceBuffer* trace_buffer() const { return logged_events_.get(); }
430 TraceBuffer* CreateTraceBuffer(); 443 TraceBuffer* CreateTraceBuffer();
431 444
432 std::string EventToConsoleMessage(unsigned char phase, 445 std::string EventToConsoleMessage(unsigned char phase,
433 const TimeTicks& timestamp, 446 const TimeTicks& timestamp,
434 TraceEvent* trace_event); 447 TraceEvent* trace_event);
435 448
436 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle, 449 TraceEvent* AddEventToThreadSharedChunkWhileLocked(TraceEventHandle* handle,
437 bool check_buffer_is_full); 450 bool check_buffer_is_full);
438 void CheckIfBufferIsFullWhileLocked(); 451 void CheckIfBufferIsFullWhileLocked();
439 void SetDisabledWhileLocked(); 452 void SetDisabledWhileLocked(Mode mode);
440 453
441 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle, 454 TraceEvent* GetEventByHandleInternal(TraceEventHandle handle,
442 OptionalAutoLock* lock); 455 OptionalAutoLock* lock);
443 456
444 void FlushInternal(const OutputCallback& cb, 457 void FlushInternal(const OutputCallback& cb,
445 bool use_worker_thread, 458 bool use_worker_thread,
446 bool discard_events); 459 bool discard_events);
447 460
448 // |generation| is used in the following callbacks to check if the callback 461 // |generation| is used in the following callbacks to check if the callback
449 // is called for the flush of the current |logged_events_|. 462 // is called for the flush of the current |logged_events_|.
(...skipping 28 matching lines...) Expand all
478 static const InternalTraceOptions kInternalEnableSampling; 491 static const InternalTraceOptions kInternalEnableSampling;
479 static const InternalTraceOptions kInternalRecordAsMuchAsPossible; 492 static const InternalTraceOptions kInternalRecordAsMuchAsPossible;
480 static const InternalTraceOptions kInternalEnableArgumentFilter; 493 static const InternalTraceOptions kInternalEnableArgumentFilter;
481 494
482 // This lock protects TraceLog member accesses (except for members protected 495 // This lock protects TraceLog member accesses (except for members protected
483 // by thread_info_lock_) from arbitrary threads. 496 // by thread_info_lock_) from arbitrary threads.
484 mutable Lock lock_; 497 mutable Lock lock_;
485 // This lock protects accesses to thread_names_, thread_event_start_times_ 498 // This lock protects accesses to thread_names_, thread_event_start_times_
486 // and thread_colors_. 499 // and thread_colors_.
487 Lock thread_info_lock_; 500 Lock thread_info_lock_;
488 Mode mode_; 501 int mode_; // See TraceLog::Mode.
oystein (OOO til 10th of July) 2016/09/22 19:21:06 nit: Since this is now a bitmask it should probabl
ssid 2016/09/22 19:37:44 Done.
489 int num_traces_recorded_; 502 int num_traces_recorded_;
490 std::unique_ptr<TraceBuffer> logged_events_; 503 std::unique_ptr<TraceBuffer> logged_events_;
491 std::vector<std::unique_ptr<TraceEvent>> metadata_events_; 504 std::vector<std::unique_ptr<TraceEvent>> metadata_events_;
492 subtle::AtomicWord /* EventCallback */ event_callback_; 505 subtle::AtomicWord /* EventCallback */ event_callback_;
493 bool dispatching_to_observer_list_; 506 bool dispatching_to_observer_list_;
494 std::vector<EnabledStateObserver*> enabled_state_observer_list_; 507 std::vector<EnabledStateObserver*> enabled_state_observer_list_;
495 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> 508 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver>
496 async_observers_; 509 async_observers_;
497 510
498 std::string process_name_; 511 std::string process_name_;
(...skipping 21 matching lines...) Expand all
520 std::string watch_event_name_; 533 std::string watch_event_name_;
521 534
522 subtle::AtomicWord /* Options */ trace_options_; 535 subtle::AtomicWord /* Options */ trace_options_;
523 536
524 // Sampling thread handles. 537 // Sampling thread handles.
525 std::unique_ptr<TraceSamplingThread> sampling_thread_; 538 std::unique_ptr<TraceSamplingThread> sampling_thread_;
526 PlatformThreadHandle sampling_thread_handle_; 539 PlatformThreadHandle sampling_thread_handle_;
527 540
528 TraceConfig trace_config_; 541 TraceConfig trace_config_;
529 TraceConfig event_callback_trace_config_; 542 TraceConfig event_callback_trace_config_;
543 TraceConfig::EventFilters event_filters_enabled_;
530 544
531 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_; 545 ThreadLocalPointer<ThreadLocalEventBuffer> thread_local_event_buffer_;
532 ThreadLocalBoolean thread_blocks_message_loop_; 546 ThreadLocalBoolean thread_blocks_message_loop_;
533 ThreadLocalBoolean thread_is_in_trace_event_; 547 ThreadLocalBoolean thread_is_in_trace_event_;
534 548
535 // Contains the message loops of threads that have had at least one event 549 // Contains the message loops of threads that have had at least one event
536 // added into the local event buffer. Not using SingleThreadTaskRunner 550 // added into the local event buffer. Not using SingleThreadTaskRunner
537 // because we need to know the life time of the message loops. 551 // because we need to know the life time of the message loops.
538 hash_set<MessageLoop*> thread_message_loops_; 552 hash_set<MessageLoop*> thread_message_loops_;
539 553
540 // For events which can't be added into the thread local buffer, e.g. events 554 // For events which can't be added into the thread local buffer, e.g. events
541 // from threads without a message loop. 555 // from threads without a message loop.
542 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_; 556 std::unique_ptr<TraceBufferChunk> thread_shared_chunk_;
543 size_t thread_shared_chunk_index_; 557 size_t thread_shared_chunk_index_;
544 558
545 // Set when asynchronous Flush is in progress. 559 // Set when asynchronous Flush is in progress.
546 OutputCallback flush_output_callback_; 560 OutputCallback flush_output_callback_;
547 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_; 561 scoped_refptr<SingleThreadTaskRunner> flush_task_runner_;
548 ArgumentFilterPredicate argument_filter_predicate_; 562 ArgumentFilterPredicate argument_filter_predicate_;
549 subtle::AtomicWord generation_; 563 subtle::AtomicWord generation_;
550 bool use_worker_thread_; 564 bool use_worker_thread_;
551 565
552 DISALLOW_COPY_AND_ASSIGN(TraceLog); 566 DISALLOW_COPY_AND_ASSIGN(TraceLog);
553 }; 567 };
554 568
555 } // namespace trace_event 569 } // namespace trace_event
556 } // namespace base 570 } // namespace base
557 571
558 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_ 572 #endif // BASE_TRACE_EVENT_TRACE_LOG_H_
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_unittest.cc ('k') | base/trace_event/trace_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698