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

Side by Side Diff: base/trace_event/trace_event_unittest.cc

Issue 2259493003: [tracing] Add trace events filtering predicate for heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@heap_prof_filter
Patch Set: Primiano's comments. Created 4 years, 3 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
« no previous file with comments | « base/trace_event/trace_event.h ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 3262 matching lines...) Expand 10 before | Expand all | Expand 10 after
3273 // This is scoped so we can test the end event being filtered. 3273 // This is scoped so we can test the end event being filtered.
3274 { TRACE_EVENT0("filtered_cat", "another cat whoa"); } 3274 { TRACE_EVENT0("filtered_cat", "another cat whoa"); }
3275 3275
3276 EndTraceAndFlush(); 3276 EndTraceAndFlush();
3277 3277
3278 EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count()); 3278 EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count());
3279 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count()); 3279 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count());
3280 } 3280 }
3281 3281
3282 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) { 3282 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) {
3283 const char config_json[] = 3283 std::string config_json = StringPrintf(
3284 "{" 3284 "{"
3285 " \"included_categories\": [" 3285 " \"included_categories\": ["
3286 " \"filtered_cat\"," 3286 " \"filtered_cat\","
3287 " \"unfiltered_cat\"]," 3287 " \"unfiltered_cat\"],"
3288 " \"event_filters\": [" 3288 " \"event_filters\": ["
3289 " {" 3289 " {"
3290 " \"filter_predicate\": \"event_whitelist_predicate\", " 3290 " \"filter_predicate\": \"%s\", "
3291 " \"included_categories\": [\"*\"], " 3291 " \"included_categories\": [\"*\"], "
3292 " \"excluded_categories\": [\"unfiltered_cat\"], " 3292 " \"excluded_categories\": [\"unfiltered_cat\"], "
3293 " \"filter_args\": {" 3293 " \"filter_args\": {"
3294 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]" 3294 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]"
3295 " }" 3295 " }"
3296 " }" 3296 " }"
3297 " " 3297 " "
3298 " ]" 3298 " ]"
3299 "}"; 3299 "}",
3300 TraceLog::TraceEventFilter::kEventWhitelistPredicate);
3300 3301
3301 TraceConfig trace_config(config_json); 3302 TraceConfig trace_config(config_json);
3302 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); 3303 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3303 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); 3304 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3304 3305
3305 TRACE_EVENT0("filtered_cat", "a snake"); 3306 TRACE_EVENT0("filtered_cat", "a snake");
3306 TRACE_EVENT0("filtered_cat", "a mushroom"); 3307 TRACE_EVENT0("filtered_cat", "a mushroom");
3307 TRACE_EVENT0("unfiltered_cat", "a cat"); 3308 TRACE_EVENT0("unfiltered_cat", "a cat");
3308 3309
3309 EndTraceAndFlush(); 3310 EndTraceAndFlush();
3310 3311
3311 EXPECT_TRUE(FindMatchingValue("name", "a snake")); 3312 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3312 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); 3313 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3313 EXPECT_TRUE(FindMatchingValue("name", "a cat")); 3314 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3314 } 3315 }
3315 3316
3317 TEST_F(TraceEventTestFixture, HeapProfilerFiltering) {
3318 std::string config_json = StringPrintf(
3319 "{"
3320 " \"included_categories\": ["
3321 " \"filtered_cat\","
3322 " \"unfiltered_cat\"],"
3323 " \"excluded_categories\": [\"excluded_cat\"],"
3324 " \"event_filters\": ["
3325 " {"
3326 " \"filter_predicate\": \"%s\", "
3327 " \"included_categories\": [\"*\"]"
3328 " }"
3329 " ]"
3330 "}",
3331 TraceLog::TraceEventFilter::kHeapProfilerPredicate);
3332
3333 TraceConfig trace_config(config_json);
3334 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE);
3335 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3336
3337 TRACE_EVENT0("filtered_cat", "a snake");
3338 TRACE_EVENT0("excluded_cat", "a mushroom");
3339 TRACE_EVENT0("unfiltered_cat", "a cat");
3340
3341 EndTraceAndFlush();
3342
3343 // The predicate should not change behavior of the trace events.
3344 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3345 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3346 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3347 }
3348
3316 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { 3349 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {
3317 BeginSpecificTrace("-*"); 3350 BeginSpecificTrace("-*");
3318 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); 3351 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1);
3319 EndTraceAndFlush(); 3352 EndTraceAndFlush();
3320 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); 3353 EXPECT_TRUE(FindNamePhase("clock_sync", "c"));
3321 } 3354 }
3322 3355
3323 } // namespace trace_event 3356 } // namespace trace_event
3324 } // namespace base 3357 } // namespace base
OLDNEW
« 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