Chromium Code Reviews| Index: base/trace_event/trace_event_filter.h |
| diff --git a/base/trace_event/trace_event_filter.h b/base/trace_event/trace_event_filter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3dd87f58cd171c576ccf1f6d93158144d44268dc |
| --- /dev/null |
| +++ b/base/trace_event/trace_event_filter.h |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ |
| +#define BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/base_export.h" |
| +#include "base/macros.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +class TraceEvent; |
| + |
| +// TraceEventFilter is iptables for TRACE_EVENT macros. Filters can be enabled |
| +// on a per-category basis. There are two use cases for filters: |
| +// 1. Snooping TRACE_EVENT macros without adding them to the TraceLog. This is |
| +// possible by setting the ENABLED_FOR_FILTERING flag on a category w/o |
| +// ENABLED_FOR_RECORDING (see TraceConfig for user-facing configuration). |
| +// 2. Filtering TRACE_EVENT macros before they are added to the TraceLog. This |
| +// requiers both the ENABLED_FOR_FILTERING and ENABLED_FOR_RECORDING flags |
| +// on the category. |
| +// TraceEventFilter instances are undefinitely lived: once created are leaked |
|
ssid
2016/11/16 10:19:44
indefinitely
|
| +// forever, although don't have to be necessarily enabled. |
|
ssid
2016/11/16 10:19:44
A reference to event_filter_registry would be nice
|
| +// More importantly, filters must be thread-safe as the FilterTraceEvent and |
| +// EndEvent methods can be called concurrently as trace macros are hit on |
| +// different threads. |
| +class BASE_EXPORT TraceEventFilter { |
| + public: |
| + TraceEventFilter() {} |
| + virtual ~TraceEventFilter() {} |
| + |
| + // If the category is ENABLED_FOR_RECORDING, the event is added iff all the |
| + // filters enabled for the category return true. false causes the event to be |
| + // dropped on the floor. |
| + virtual bool FilterTraceEvent(const TraceEvent& trace_event) const = 0; |
| + |
| + // Notifies the end of a duration event when the RAII macro goes out of scope. |
| + virtual void EndEvent(const char* category_name, |
|
DmitrySkiba
2016/11/29 17:55:46
What is the difference between FilterTraceEvent(TR
|
| + const char* event_name) const {} |
| + |
| + // Unique predicate name for the filter, as used in the TraceConfig. |
| + virtual const char* name() const = 0; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TraceEventFilter); |
| +}; |
| + |
| +} // namespace trace_event |
| +} // namespace base |
| + |
| +#endif // BASE_TRACE_EVENT_TRACE_EVENT_FILTER_H_ |