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

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: 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 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 #include <utility> 13 #include <utility>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
19 #include "base/location.h" 19 #include "base/location.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/ptr_util.h"
21 #include "base/memory/ref_counted_memory.h" 22 #include "base/memory/ref_counted_memory.h"
22 #include "base/memory/singleton.h" 23 #include "base/memory/singleton.h"
23 #include "base/process/process_handle.h" 24 #include "base/process/process_handle.h"
24 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
25 #include "base/stl_util.h" 26 #include "base/stl_util.h"
26 #include "base/strings/pattern.h" 27 #include "base/strings/pattern.h"
27 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
28 #include "base/synchronization/waitable_event.h" 29 #include "base/synchronization/waitable_event.h"
29 #include "base/threading/platform_thread.h" 30 #include "base/threading/platform_thread.h"
30 #include "base/threading/thread.h" 31 #include "base/threading/thread.h"
(...skipping 3179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 config1.Merge(config2); 3211 config1.Merge(config2);
3211 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size()); 3212 EXPECT_EQ(2u, config1.GetSyntheticDelayValues().size());
3212 } 3213 }
3213 3214
3214 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 3215 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
3215 const char filter[] = "DELAY(test.Delay;16;oneshot)"; 3216 const char filter[] = "DELAY(test.Delay;16;oneshot)";
3216 TraceConfig config(filter, ""); 3217 TraceConfig config(filter, "");
3217 EXPECT_EQ(filter, config.ToCategoryFilterString()); 3218 EXPECT_EQ(filter, config.ToCategoryFilterString());
3218 } 3219 }
3219 3220
3221 class TestEventFilter : public TraceLog::TraceEventFilter {
3222 public:
3223 bool FilterTraceEvent(const TraceEvent& trace_event) const override {
3224 filter_trace_event_hit_count_++;
3225 return true;
3226 }
3227
3228 void EndEvent(const char* category_group, const char* name) override {
3229 end_event_hit_count_++;
3230 }
3231
3232 static size_t filter_trace_event_hit_count() {
3233 return filter_trace_event_hit_count_;
3234 }
3235 static size_t end_event_hit_count() { return end_event_hit_count_; }
3236
3237 private:
3238 static size_t filter_trace_event_hit_count_;
3239 static size_t end_event_hit_count_;
3240 };
3241
3242 size_t TestEventFilter::filter_trace_event_hit_count_ = 0;
3243 size_t TestEventFilter::end_event_hit_count_ = 0;
3244
3245 std::unique_ptr<TraceLog::TraceEventFilter> ConstructTestEventFilter() {
3246 return WrapUnique(new TestEventFilter);
3247 }
3248
3249 TEST_F(TraceEventTestFixture, EventFiltering) {
3250 const char config_json[] =
3251 "{"
3252 " \"included_categories\": ["
3253 " \"filtered_cat\","
3254 " \"unfiltered_cat\"],"
3255 " \"event_filters\": ["
3256 " {"
3257 " \"filter_predicate\": \"testing_predicate\", "
3258 " \"included_categories\": [\"*\"]"
3259 " }"
3260 " "
3261 " ]"
3262 "}";
3263
3264 TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter);
3265 TraceConfig trace_config(config_json);
3266 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3267 ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled());
3268
3269 TRACE_EVENT0("a cat", "a snake");
3270 TRACE_EVENT0("a cat", "a mushroom");
3271
3272 // This is scoped so we can test the end event being filtered.
3273 { TRACE_EVENT0("a cat", "another cat whoa"); }
3274
3275 EndTraceAndFlush();
3276
3277 EXPECT_EQ(TestEventFilter::filter_trace_event_hit_count(), 3u);
3278 EXPECT_EQ(TestEventFilter::end_event_hit_count(), 1u);
3279 }
3280
3281 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) {
3282 const char config_json[] =
3283 "{"
3284 " \"included_categories\": ["
3285 " \"filtered_cat\","
3286 " \"unfiltered_cat\"],"
3287 " \"event_filters\": ["
3288 " {"
3289 " \"filter_predicate\": \"event_whitelist_predicate\", "
3290 " \"included_categories\": [\"*\"], "
3291 " \"excluded_categories\": [\"unfiltered_cat\"], "
3292 " \"filter_args\": {"
3293 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]"
3294 " }"
3295 " }"
3296 " "
3297 " ]"
3298 "}";
3299
3300 TraceConfig trace_config(config_json);
3301 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3302 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3303
3304 TRACE_EVENT0("filtered_cat", "a snake");
3305 TRACE_EVENT0("filtered_cat", "a mushroom");
3306 TRACE_EVENT0("unfiltered_cat", "a cat");
3307
3308 EndTraceAndFlush();
3309
3310 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3311 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3312 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3313 }
3314
3220 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { 3315 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {
3221 BeginSpecificTrace("-*"); 3316 BeginSpecificTrace("-*");
3222 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); 3317 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1);
3223 EndTraceAndFlush(); 3318 EndTraceAndFlush();
3224 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); 3319 EXPECT_TRUE(FindNamePhase("clock_sync", "c"));
3225 } 3320 }
3226 3321
3227 } // namespace trace_event 3322 } // namespace trace_event
3228 } // namespace base 3323 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698