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

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

Issue 2739163004: [tracing] Use same code path for category filtering for recording and event filtering (Closed)
Patch Set: InitalizeWithString. Created 3 years, 9 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_config_unittest.cc ('k') | no next file » | 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 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 EXPECT_EQ(1u, filter_hits_counter.filter_trace_event_hit_count); 3080 EXPECT_EQ(1u, filter_hits_counter.filter_trace_event_hit_count);
3081 EXPECT_EQ(1u, filter_hits_counter.end_event_hit_count); 3081 EXPECT_EQ(1u, filter_hits_counter.end_event_hit_count);
3082 Clear(); 3082 Clear();
3083 } 3083 }
3084 3084
3085 TEST_F(TraceEventTestFixture, EventFiltering) { 3085 TEST_F(TraceEventTestFixture, EventFiltering) {
3086 const char config_json[] = 3086 const char config_json[] =
3087 "{" 3087 "{"
3088 " \"included_categories\": [" 3088 " \"included_categories\": ["
3089 " \"filtered_cat\"," 3089 " \"filtered_cat\","
3090 " \"unfiltered_cat\"]," 3090 " \"unfiltered_cat\","
3091 " \"" TRACE_DISABLED_BY_DEFAULT("filtered_cat") "\","
3092 " \"" TRACE_DISABLED_BY_DEFAULT("unfiltered_cat") "\"],"
3091 " \"event_filters\": [" 3093 " \"event_filters\": ["
3092 " {" 3094 " {"
3093 " \"filter_predicate\": \"testing_predicate\", " 3095 " \"filter_predicate\": \"testing_predicate\", "
3094 " \"included_categories\": [\"filtered_cat\"]" 3096 " \"included_categories\": ["
3097 " \"filtered_cat\","
3098 " \"" TRACE_DISABLED_BY_DEFAULT("filtered_cat") "\"]"
3095 " }" 3099 " }"
3096 " " 3100 " "
3097 " ]" 3101 " ]"
3098 "}"; 3102 "}";
3099 3103
3100 TestEventFilter::HitsCounter filter_hits_counter; 3104 TestEventFilter::HitsCounter filter_hits_counter;
3101 TestEventFilter::set_filter_return_value(true); 3105 TestEventFilter::set_filter_return_value(true);
3102 TraceLog::GetInstance()->SetFilterFactoryForTesting(TestEventFilter::Factory); 3106 TraceLog::GetInstance()->SetFilterFactoryForTesting(TestEventFilter::Factory);
3103 3107
3104 TraceConfig trace_config(config_json); 3108 TraceConfig trace_config(config_json);
3105 TraceLog::GetInstance()->SetEnabled( 3109 TraceLog::GetInstance()->SetEnabled(
3106 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); 3110 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE);
3107 ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled()); 3111 ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled());
3108 3112
3109 TRACE_EVENT0("filtered_cat", "a snake"); 3113 TRACE_EVENT0("filtered_cat", "a snake");
3110 TRACE_EVENT0("filtered_cat", "a mushroom"); 3114 TRACE_EVENT0("filtered_cat", "a mushroom");
3111 TRACE_EVENT0("unfiltered_cat", "a horse"); 3115 TRACE_EVENT0("unfiltered_cat", "a horse");
3112 3116
3117 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("filtered_cat"), "a dog");
3118 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("unfiltered_cat"), "a pony");
3119
3113 // This is scoped so we can test the end event being filtered. 3120 // This is scoped so we can test the end event being filtered.
3114 { TRACE_EVENT0("filtered_cat", "another cat whoa"); } 3121 { TRACE_EVENT0("filtered_cat", "another cat whoa"); }
3115 3122
3116 EndTraceAndFlush(); 3123 EndTraceAndFlush();
3117 3124
3118 EXPECT_EQ(3u, filter_hits_counter.filter_trace_event_hit_count); 3125 EXPECT_EQ(4u, filter_hits_counter.filter_trace_event_hit_count);
3119 EXPECT_EQ(1u, filter_hits_counter.end_event_hit_count); 3126 EXPECT_EQ(1u, filter_hits_counter.end_event_hit_count);
3120 } 3127 }
3121 3128
3122 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) { 3129 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) {
3123 std::string config_json = StringPrintf( 3130 std::string config_json = StringPrintf(
3124 "{" 3131 "{"
3125 " \"included_categories\": [" 3132 " \"included_categories\": ["
3126 " \"filtered_cat\"," 3133 " \"filtered_cat\","
3127 " \"unfiltered_cat\"]," 3134 " \"unfiltered_cat\","
3135 " \"" TRACE_DISABLED_BY_DEFAULT("filtered_cat") "\"],"
3128 " \"event_filters\": [" 3136 " \"event_filters\": ["
3129 " {" 3137 " {"
3130 " \"filter_predicate\": \"%s\", " 3138 " \"filter_predicate\": \"%s\", "
3131 " \"included_categories\": [\"*\"], " 3139 " \"included_categories\": ["
3132 " \"excluded_categories\": [\"unfiltered_cat\"], " 3140 " \"filtered_cat\","
3141 " \"" TRACE_DISABLED_BY_DEFAULT("*") "\"], "
3133 " \"filter_args\": {" 3142 " \"filter_args\": {"
3134 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]" 3143 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]"
3135 " }" 3144 " }"
3136 " }" 3145 " }"
3137 " " 3146 " "
3138 " ]" 3147 " ]"
3139 "}", 3148 "}",
3140 EventNameFilter::kName); 3149 EventNameFilter::kName);
3141 3150
3142 TraceConfig trace_config(config_json); 3151 TraceConfig trace_config(config_json);
3143 TraceLog::GetInstance()->SetEnabled( 3152 TraceLog::GetInstance()->SetEnabled(
3144 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); 3153 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE);
3145 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); 3154 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3146 3155
3147 TRACE_EVENT0("filtered_cat", "a snake"); 3156 TRACE_EVENT0("filtered_cat", "a snake");
3148 TRACE_EVENT0("filtered_cat", "a mushroom"); 3157 TRACE_EVENT0("filtered_cat", "a mushroom");
3149 TRACE_EVENT0("unfiltered_cat", "a cat"); 3158 TRACE_EVENT0("unfiltered_cat", "a cat");
3159 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("filtered_cat"), "a dog");
3160 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("filtered_cat"), "a pony");
3150 3161
3151 EndTraceAndFlush(); 3162 EndTraceAndFlush();
3152 3163
3153 EXPECT_TRUE(FindMatchingValue("name", "a snake")); 3164 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3154 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); 3165 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3155 EXPECT_TRUE(FindMatchingValue("name", "a cat")); 3166 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3167 EXPECT_TRUE(FindMatchingValue("name", "a dog"));
3168 EXPECT_FALSE(FindMatchingValue("name", "a pony"));
3156 } 3169 }
3157 3170
3158 TEST_F(TraceEventTestFixture, HeapProfilerFiltering) { 3171 TEST_F(TraceEventTestFixture, HeapProfilerFiltering) {
3159 std::string config_json = StringPrintf( 3172 std::string config_json = StringPrintf(
3160 "{" 3173 "{"
3161 " \"included_categories\": [" 3174 " \"included_categories\": ["
3162 " \"filtered_cat\"," 3175 " \"filtered_cat\","
3163 " \"unfiltered_cat\"]," 3176 " \"unfiltered_cat\","
3177 " \"" TRACE_DISABLED_BY_DEFAULT("filtered_cat") "\","
3178 " \"" TRACE_DISABLED_BY_DEFAULT("unfiltered_cat") "\"],"
3164 " \"excluded_categories\": [\"excluded_cat\"]," 3179 " \"excluded_categories\": [\"excluded_cat\"],"
3165 " \"event_filters\": [" 3180 " \"event_filters\": ["
3166 " {" 3181 " {"
3167 " \"filter_predicate\": \"%s\", " 3182 " \"filter_predicate\": \"%s\", "
3168 " \"included_categories\": [\"*\"]" 3183 " \"included_categories\": ["
3184 " \"*\","
3185 " \"" TRACE_DISABLED_BY_DEFAULT("filtered_cat") "\"]"
3169 " }" 3186 " }"
3170 " ]" 3187 " ]"
3171 "}", 3188 "}",
3172 HeapProfilerEventFilter::kName); 3189 HeapProfilerEventFilter::kName);
3173 3190
3174 TraceConfig trace_config(config_json); 3191 TraceConfig trace_config(config_json);
3175 TraceLog::GetInstance()->SetEnabled( 3192 TraceLog::GetInstance()->SetEnabled(
3176 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); 3193 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE);
3177 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); 3194 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled());
3178 3195
3179 TRACE_EVENT0("filtered_cat", "a snake"); 3196 TRACE_EVENT0("filtered_cat", "a snake");
3180 TRACE_EVENT0("excluded_cat", "a mushroom"); 3197 TRACE_EVENT0("excluded_cat", "a mushroom");
3181 TRACE_EVENT0("unfiltered_cat", "a cat"); 3198 TRACE_EVENT0("unfiltered_cat", "a cat");
3199 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("filtered_cat"), "a dog");
3200 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("unfiltered_cat"), "a pony");
3182 3201
3183 EndTraceAndFlush(); 3202 EndTraceAndFlush();
3184 3203
3185 // The predicate should not change behavior of the trace events. 3204 // The predicate should not change behavior of the trace events.
3186 EXPECT_TRUE(FindMatchingValue("name", "a snake")); 3205 EXPECT_TRUE(FindMatchingValue("name", "a snake"));
3187 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); 3206 EXPECT_FALSE(FindMatchingValue("name", "a mushroom"));
3188 EXPECT_TRUE(FindMatchingValue("name", "a cat")); 3207 EXPECT_TRUE(FindMatchingValue("name", "a cat"));
3208 EXPECT_TRUE(FindMatchingValue("name", "a dog"));
3209 EXPECT_TRUE(FindMatchingValue("name", "a pony"));
3189 } 3210 }
3190 3211
3191 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { 3212 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) {
3192 BeginSpecificTrace("-*"); 3213 BeginSpecificTrace("-*");
3193 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); 3214 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1);
3194 EndTraceAndFlush(); 3215 EndTraceAndFlush();
3195 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); 3216 EXPECT_TRUE(FindNamePhase("clock_sync", "c"));
3196 } 3217 }
3197 3218
3198 } // namespace trace_event 3219 } // namespace trace_event
3199 } // namespace base 3220 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_config_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698