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

Side by Side 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: Added test Created 4 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/trace_event/trace_event.h" 5 #include "base/trace_event/trace_event.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <cstdlib> 11 #include <cstdlib>
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
17 #include "base/json/json_writer.h" 17 #include "base/json/json_writer.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h"
20 #include "base/memory/ref_counted_memory.h" 21 #include "base/memory/ref_counted_memory.h"
21 #include "base/memory/singleton.h" 22 #include "base/memory/singleton.h"
22 #include "base/process/process_handle.h" 23 #include "base/process/process_handle.h"
23 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
24 #include "base/stl_util.h" 25 #include "base/stl_util.h"
25 #include "base/strings/pattern.h" 26 #include "base/strings/pattern.h"
26 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
27 #include "base/synchronization/waitable_event.h" 28 #include "base/synchronization/waitable_event.h"
28 #include "base/threading/platform_thread.h" 29 #include "base/threading/platform_thread.h"
29 #include "base/threading/thread.h" 30 #include "base/threading/thread.h"
(...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 config1.Merge(config2); 3093 config1.Merge(config2);
3093 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size()); 3094 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size());
3094 } 3095 }
3095 3096
3096 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 3097 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
3097 const char filter[] = "DELAY(test.Delay;16;oneshot)"; 3098 const char filter[] = "DELAY(test.Delay;16;oneshot)";
3098 TraceConfig config(filter, ""); 3099 TraceConfig config(filter, "");
3099 EXPECT_EQ(filter, config.ToCategoryFilterString()); 3100 EXPECT_EQ(filter, config.ToCategoryFilterString());
3100 } 3101 }
3101 3102
3103 class TestEventFilter : public TraceLog::TraceEventFilter {
3104 public:
3105 bool FilterTraceEvent(const TraceEvent& trace_event) const override {
3106 filter_trace_event_hit_count_++;
3107 return true;
3108 }
3109
3110 void EndEvent(const char* category_group, const char* name) override {
3111 end_event_hit_count_++;
3112 }
3113
3114 static size_t filter_trace_event_hit_count() {
3115 return filter_trace_event_hit_count_;
3116 }
3117 static size_t end_event_hit_count() { return end_event_hit_count_; }
3118
3119 private:
3120 static size_t filter_trace_event_hit_count_;
3121 static size_t end_event_hit_count_;
3122 };
3123
3124 size_t TestEventFilter::filter_trace_event_hit_count_ = 0;
3125 size_t TestEventFilter::end_event_hit_count_ = 0;
3126
3127 std::unique_ptr<TraceLog::TraceEventFilter> ConstructTestEventFilter() {
3128 return WrapUnique(new TestEventFilter);
3129 }
3130
3131 TEST_F(TraceEventTestFixture, EventFiltering) {
3132 const char config_json[] =
3133 "{"
3134 " \"included_categories\": ["
3135 " \"filtered_cat\","
3136 " \"unfiltered_cat\"],"
3137 " \"event_filters\": ["
3138 " {"
3139 " \"filter_predicate\": \"testing_predicate\", "
3140 " \"included_categories\": [\"*\"]"
3141 " }"
3142 " "
3143 " ]"
3144 "}";
3145
3146 TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter);
3147 TraceConfig trace_config(config_json);
3148 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3149 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
Primiano Tucci (use gerrit) 2016/05/31 15:41:23 I think you want this to be an ASSERT_TRUE. the co
oystein (OOO til 10th of July) 2016/08/01 13:39:49 Done.
3150
3151 TRACE_EVENT0("a cat", "a snake");
Primiano Tucci (use gerrit) 2016/05/31 15:41:23 Add a comment here explaining that these trace eve
oystein (OOO til 10th of July) 2016/08/01 13:39:49 Done.
3152 TRACE_EVENT0("a cat", "a mushroom");
3153
3154 {
3155 TRACE_EVENT0("a cat", "another cat whoa");
3156 }
3157
3158 EndTraceAndFlush();
3159
3160 EXPECT_EQ(TestEventFilter::filter_trace_event_hit_count(), 3u);
3161 EXPECT_EQ(TestEventFilter::end_event_hit_count(), 1u);
3162 }
3163
3164 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) {
3165 const char config_json[] =
3166 "{"
3167 " \"included_categories\": ["
3168 " \"filtered_cat\","
3169 " \"unfiltered_cat\"],"
3170 " \"event_filters\": ["
3171 " {"
3172 " \"filter_predicate\": \"event_whitelist_predicate\", "
3173 " \"included_categories\": [\"*\"], "
3174 " \"excluded_categories\": [\"unfiltered_cat\"], "
3175 " \"filter_args\": {"
3176 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]"
3177 " }"
3178 " }"
3179 " "
3180 " ]"
3181 "}";
3182
3183 TraceConfig trace_config(config_json);
3184 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3185 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3186
3187 TRACE_EVENT0("filtered_cat", "a snake");
3188 TRACE_EVENT0("filtered_cat", "a mushroom");
3189 TRACE_EVENT0("unfiltered_cat", "a cat");
3190
3191 EndTraceAndFlush();
3192
3193 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3194 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3195 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3196 }
3197
3102 } // namespace trace_event 3198 } // namespace trace_event
3103 } // namespace base 3199 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698