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

Unified Diff: base/trace_event/trace_event_unittest.cc

Issue 1923533004: Tracing pre-filtering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/trace_event.h ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_event_unittest.cc
diff --git a/base/trace_event/trace_event_unittest.cc b/base/trace_event/trace_event_unittest.cc
index ad3fe92baace2dd598443e495454e8782bfd3e16..bfcbd2fe2528de97dce90e5f08657c8fa254f733 100644
--- a/base/trace_event/trace_event_unittest.cc
+++ b/base/trace_event/trace_event_unittest.cc
@@ -18,6 +18,7 @@
#include "base/json/json_writer.h"
#include "base/location.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
#include "base/process/process_handle.h"
@@ -3217,6 +3218,101 @@ TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
EXPECT_EQ(filter, config.ToCategoryFilterString());
}
+class TestEventFilter : public TraceLog::TraceEventFilter {
+ public:
+ bool FilterTraceEvent(const TraceEvent& trace_event) const override {
+ filter_trace_event_hit_count_++;
+ return true;
+ }
+
+ void EndEvent(const char* category_group, const char* name) override {
+ end_event_hit_count_++;
+ }
+
+ static size_t filter_trace_event_hit_count() {
+ return filter_trace_event_hit_count_;
+ }
+ static size_t end_event_hit_count() { return end_event_hit_count_; }
+
+ private:
+ static size_t filter_trace_event_hit_count_;
+ static size_t end_event_hit_count_;
+};
+
+size_t TestEventFilter::filter_trace_event_hit_count_ = 0;
+size_t TestEventFilter::end_event_hit_count_ = 0;
+
+std::unique_ptr<TraceLog::TraceEventFilter> ConstructTestEventFilter() {
+ return WrapUnique(new TestEventFilter);
+}
+
+TEST_F(TraceEventTestFixture, EventFiltering) {
+ const char config_json[] =
+ "{"
+ " \"included_categories\": ["
+ " \"filtered_cat\","
+ " \"unfiltered_cat\"],"
+ " \"event_filters\": ["
+ " {"
+ " \"filter_predicate\": \"testing_predicate\", "
+ " \"included_categories\": [\"filtered_cat\"]"
+ " }"
+ " "
+ " ]"
+ "}";
+
+ TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter);
+ TraceConfig trace_config(config_json);
+ TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
+ ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled());
+
+ TRACE_EVENT0("filtered_cat", "a snake");
+ TRACE_EVENT0("filtered_cat", "a mushroom");
+ TRACE_EVENT0("unfiltered_cat", "a horse");
+
+ // This is scoped so we can test the end event being filtered.
+ { TRACE_EVENT0("filtered_cat", "another cat whoa"); }
+
+ EndTraceAndFlush();
+
+ EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count());
+ EXPECT_EQ(1u, TestEventFilter::end_event_hit_count());
+}
+
+TEST_F(TraceEventTestFixture, EventWhitelistFiltering) {
+ const char config_json[] =
+ "{"
+ " \"included_categories\": ["
+ " \"filtered_cat\","
+ " \"unfiltered_cat\"],"
+ " \"event_filters\": ["
+ " {"
+ " \"filter_predicate\": \"event_whitelist_predicate\", "
+ " \"included_categories\": [\"*\"], "
+ " \"excluded_categories\": [\"unfiltered_cat\"], "
+ " \"filter_args\": {"
+ " \"event_name_whitelist\": [\"a snake\", \"a dog\"]"
+ " }"
+ " }"
+ " "
+ " ]"
+ "}";
+
+ TraceConfig trace_config(config_json);
+ TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
+ EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
+
+ TRACE_EVENT0("filtered_cat", "a snake");
+ TRACE_EVENT0("filtered_cat", "a mushroom");
+ TRACE_EVENT0("unfiltered_cat", "a cat");
+
+ EndTraceAndFlush();
+
+ EXPECT_TRUE(FindMatchingValue("name", "a snake"));
+ EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
+ EXPECT_TRUE(FindMatchingValue("name", "a cat"));
+}
+
TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {
BeginSpecificTrace("-*");
TRACE_EVENT_CLOCK_SYNC_RECEIVER(1);
« no previous file with comments | « base/trace_event/trace_event.h ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698