1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ 6 #define BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ 7 8 #include <memory> 9 10 #include "base/base_export.h" 11 #include "base/macros.h" 12 13 namespace base { 14 namespace trace_event { 15 16 class TraceEvent; 17 18 // TraceEventFilter is like iptables for TRACE_EVENT macros. Filters can be 19 // enabled on a per-category basis, hence a single filter instance can serve 20 // more than a TraceCategory. There are two use cases for filters: 21 // 1. Snooping TRACE_EVENT macros without adding them to the TraceLog. This is 22 // possible by setting the ENABLED_FOR_FILTERING flag on a category w/o 23 // ENABLED_FOR_RECORDING (see TraceConfig for user-facing configuration). 24 // 2. Filtering TRACE_EVENT macros before they are added to the TraceLog. This 25 // requires both the ENABLED_FOR_FILTERING and ENABLED_FOR_RECORDING flags 26 // on the category. 27 // More importantly, filters must be thread-safe. The FilterTraceEvent and 28 // EndEvent methods can be called concurrently as trace macros are hit on 29 // different threads. 30 class BASE_EXPORT TraceEventFilter { 31 public: 32 TraceEventFilter(); 33 virtual ~TraceEventFilter(); 34 35 // If the category is ENABLED_FOR_RECORDING, the event is added iff all the 36 // filters enabled for the category return true. false causes the event to be 37 // discarded. 38 virtual bool FilterTraceEvent(const TraceEvent& trace_event) const = 0; 39 40 // Notifies the end of a duration event when the RAII macro goes out of scope. 41 virtual void EndEvent(const char* category_name, 42 const char* event_name) const; 43 44 private: 45 DISALLOW_COPY_AND_ASSIGN(TraceEventFilter); 46 }; 47 48 } // namespace trace_event 49 } // namespace base 50 51 #endif // BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ 52