Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CancelTraceAsync(WaitableEvent* flush_complete_event) { | 131 void CancelTraceAsync(WaitableEvent* flush_complete_event) { |
| 132 TraceLog::GetInstance()->CancelTracing( | 132 TraceLog::GetInstance()->CancelTracing( |
| 133 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, | 133 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| 134 base::Unretained(static_cast<TraceEventTestFixture*>(this)), | 134 base::Unretained(static_cast<TraceEventTestFixture*>(this)), |
| 135 base::Unretained(flush_complete_event))); | 135 base::Unretained(flush_complete_event))); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void EndTraceAndFlushAsync(WaitableEvent* flush_complete_event) { | 138 void EndTraceAndFlushAsync(WaitableEvent* flush_complete_event) { |
| 139 TraceLog::GetInstance()->SetDisabled(); | 139 TraceLog::GetInstance()->SetDisabled(TraceLog::RECORDING_MODE | |
| 140 TraceLog::FILTERING_MODE); | |
| 140 TraceLog::GetInstance()->Flush( | 141 TraceLog::GetInstance()->Flush( |
| 141 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, | 142 base::Bind(&TraceEventTestFixture::OnTraceDataCollected, |
| 142 base::Unretained(static_cast<TraceEventTestFixture*>(this)), | 143 base::Unretained(static_cast<TraceEventTestFixture*>(this)), |
| 143 base::Unretained(flush_complete_event))); | 144 base::Unretained(flush_complete_event))); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void SetUp() override { | 147 void SetUp() override { |
| 147 const char* name = PlatformThread::GetName(); | 148 const char* name = PlatformThread::GetName(); |
| 148 old_thread_name_ = name ? strdup(name) : NULL; | 149 old_thread_name_ = name ? strdup(name) : NULL; |
| 149 | 150 |
| (...skipping 3049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3199 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { | 3200 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { |
| 3200 const char filter[] = "DELAY(test.Delay;16;oneshot)"; | 3201 const char filter[] = "DELAY(test.Delay;16;oneshot)"; |
| 3201 TraceConfig config(filter, ""); | 3202 TraceConfig config(filter, ""); |
| 3202 EXPECT_EQ(filter, config.ToCategoryFilterString()); | 3203 EXPECT_EQ(filter, config.ToCategoryFilterString()); |
| 3203 } | 3204 } |
| 3204 | 3205 |
| 3205 class TestEventFilter : public TraceLog::TraceEventFilter { | 3206 class TestEventFilter : public TraceLog::TraceEventFilter { |
| 3206 public: | 3207 public: |
| 3207 bool FilterTraceEvent(const TraceEvent& trace_event) const override { | 3208 bool FilterTraceEvent(const TraceEvent& trace_event) const override { |
| 3208 filter_trace_event_hit_count_++; | 3209 filter_trace_event_hit_count_++; |
| 3209 return true; | 3210 return filter_return_value_; |
| 3210 } | 3211 } |
| 3211 | 3212 |
| 3212 void EndEvent(const char* category_group, const char* name) override { | 3213 void EndEvent(const char* category_group, const char* name) override { |
| 3213 end_event_hit_count_++; | 3214 end_event_hit_count_++; |
| 3214 } | 3215 } |
| 3215 | 3216 |
| 3217 static void set_filter_return_value(bool value) { | |
| 3218 filter_return_value_ = value; | |
| 3219 } | |
| 3220 | |
| 3216 static size_t filter_trace_event_hit_count() { | 3221 static size_t filter_trace_event_hit_count() { |
| 3217 return filter_trace_event_hit_count_; | 3222 return filter_trace_event_hit_count_; |
| 3218 } | 3223 } |
| 3219 static size_t end_event_hit_count() { return end_event_hit_count_; } | 3224 static size_t end_event_hit_count() { return end_event_hit_count_; } |
| 3220 | 3225 |
| 3226 static void clear_counts() { | |
| 3227 filter_trace_event_hit_count_ = 0; | |
| 3228 end_event_hit_count_ = 0; | |
| 3229 } | |
| 3230 | |
| 3221 private: | 3231 private: |
| 3222 static size_t filter_trace_event_hit_count_; | 3232 static size_t filter_trace_event_hit_count_; |
| 3223 static size_t end_event_hit_count_; | 3233 static size_t end_event_hit_count_; |
| 3234 static bool filter_return_value_; | |
| 3224 }; | 3235 }; |
| 3225 | 3236 |
| 3226 size_t TestEventFilter::filter_trace_event_hit_count_ = 0; | 3237 size_t TestEventFilter::filter_trace_event_hit_count_ = 0; |
| 3227 size_t TestEventFilter::end_event_hit_count_ = 0; | 3238 size_t TestEventFilter::end_event_hit_count_ = 0; |
| 3239 bool TestEventFilter::filter_return_value_ = false; | |
| 3228 | 3240 |
| 3229 std::unique_ptr<TraceLog::TraceEventFilter> ConstructTestEventFilter() { | 3241 std::unique_ptr<TraceLog::TraceEventFilter> ConstructTestEventFilter() { |
| 3230 return WrapUnique(new TestEventFilter); | 3242 return WrapUnique(new TestEventFilter); |
| 3231 } | 3243 } |
| 3232 | 3244 |
| 3245 TEST_F(TraceEventTestFixture, TraceFilteringMode) { | |
| 3246 const char config_json[] = | |
| 3247 "{" | |
| 3248 " \"event_filters\": [" | |
| 3249 " {" | |
| 3250 " \"filter_predicate\": \"testing_predicate\", " | |
| 3251 " \"included_categories\": [\"*\"]" | |
| 3252 " }" | |
| 3253 " ]" | |
| 3254 "}"; | |
| 3255 | |
| 3256 // Run RECORDING_MODE within FILTERING_MODE. | |
| 3257 TestEventFilter::set_filter_return_value(true); | |
| 3258 TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter); | |
| 3259 TraceLog::GetInstance()->SetEnabled(TraceConfig(config_json), | |
| 3260 TraceLog::FILTERING_MODE); | |
| 3261 EXPECT_EQ(TraceLog::FILTERING_MODE, TraceLog::GetInstance()->enabled_modes()); | |
|
Primiano Tucci (use gerrit)
2016/10/12 17:50:17
can you add some comments every time you do setena
ssid
2016/10/12 19:04:43
Done.
| |
| 3262 { | |
|
Primiano Tucci (use gerrit)
2016/10/12 17:50:17
why there are scope enclosers here? is it just for
ssid
2016/10/12 19:04:43
I am measuring the end_event_hit_count. To check t
| |
| 3263 void* ptr = this; | |
| 3264 TRACE_EVENT0("c0", "name0"); | |
| 3265 TRACE_EVENT_ASYNC_BEGIN0("c1", "name1", ptr); | |
| 3266 TRACE_EVENT_INSTANT0("c0", "name0", TRACE_EVENT_SCOPE_THREAD); | |
| 3267 TRACE_EVENT_ASYNC_END0("c1", "name1", ptr); | |
| 3268 } | |
| 3269 TraceLog::GetInstance()->SetEnabled(TraceConfig("", ""), | |
| 3270 TraceLog::RECORDING_MODE); | |
| 3271 EXPECT_EQ(TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE, | |
| 3272 TraceLog::GetInstance()->enabled_modes()); | |
| 3273 { TRACE_EVENT0("c2", "name2"); } | |
|
Primiano Tucci (use gerrit)
2016/10/12 17:50:17
here either use newlines (e.g. {\nTRACE...\n}) or
ssid
2016/10/12 19:04:43
Um, this is a fight against git cl format :(
| |
| 3274 TraceLog::GetInstance()->SetDisabled(); | |
| 3275 EXPECT_EQ(TraceLog::FILTERING_MODE, TraceLog::GetInstance()->enabled_modes()); | |
| 3276 { TRACE_EVENT0("c0", "name0"); } | |
| 3277 TraceLog::GetInstance()->SetDisabled(TraceLog::FILTERING_MODE); | |
| 3278 EXPECT_EQ(0, TraceLog::GetInstance()->enabled_modes()); | |
| 3279 | |
| 3280 EndTraceAndFlush(); | |
| 3281 EXPECT_FALSE(FindMatchingValue("cat", "c0")); | |
| 3282 EXPECT_FALSE(FindMatchingValue("cat", "c1")); | |
| 3283 EXPECT_FALSE(FindMatchingValue("name", "name0")); | |
| 3284 EXPECT_FALSE(FindMatchingValue("name", "name1")); | |
| 3285 EXPECT_TRUE(FindMatchingValue("cat", "c2")); | |
| 3286 EXPECT_TRUE(FindMatchingValue("name", "name2")); | |
| 3287 EXPECT_EQ(6u, TestEventFilter::filter_trace_event_hit_count()); | |
| 3288 EXPECT_EQ(3u, TestEventFilter::end_event_hit_count()); | |
| 3289 Clear(); | |
| 3290 TestEventFilter::clear_counts(); | |
| 3291 | |
| 3292 // Run FILTERING_MODE within RECORDING_MODE. | |
| 3293 TestEventFilter::set_filter_return_value(false); | |
| 3294 TraceLog::GetInstance()->SetEnabled(TraceConfig("", ""), | |
| 3295 TraceLog::RECORDING_MODE); | |
| 3296 EXPECT_EQ(TraceLog::RECORDING_MODE, TraceLog::GetInstance()->enabled_modes()); | |
| 3297 { TRACE_EVENT0("c0", "name0"); } | |
| 3298 TraceLog::GetInstance()->SetEnabled(TraceConfig(config_json), | |
| 3299 TraceLog::FILTERING_MODE); | |
| 3300 EXPECT_EQ(TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE, | |
| 3301 TraceLog::GetInstance()->enabled_modes()); | |
| 3302 { TRACE_EVENT0("c1", "name1"); } | |
| 3303 TraceLog::GetInstance()->SetDisabled(TraceLog::FILTERING_MODE); | |
| 3304 EXPECT_EQ(TraceLog::RECORDING_MODE, TraceLog::GetInstance()->enabled_modes()); | |
| 3305 { TRACE_EVENT0("c2", "name2"); } | |
| 3306 TraceLog::GetInstance()->SetDisabled(); | |
| 3307 EXPECT_EQ(0, TraceLog::GetInstance()->enabled_modes()); | |
| 3308 | |
| 3309 EndTraceAndFlush(); | |
| 3310 EXPECT_TRUE(FindMatchingValue("cat", "c0")); | |
| 3311 EXPECT_TRUE(FindMatchingValue("cat", "c2")); | |
| 3312 EXPECT_TRUE(FindMatchingValue("name", "name0")); | |
| 3313 EXPECT_TRUE(FindMatchingValue("name", "name2")); | |
| 3314 EXPECT_FALSE(FindMatchingValue("cat", "c1")); | |
| 3315 EXPECT_FALSE(FindMatchingValue("name", "name1")); | |
| 3316 EXPECT_EQ(1u, TestEventFilter::filter_trace_event_hit_count()); | |
| 3317 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count()); | |
| 3318 Clear(); | |
| 3319 TestEventFilter::clear_counts(); | |
| 3320 } | |
| 3321 | |
| 3233 TEST_F(TraceEventTestFixture, EventFiltering) { | 3322 TEST_F(TraceEventTestFixture, EventFiltering) { |
| 3234 const char config_json[] = | 3323 const char config_json[] = |
| 3235 "{" | 3324 "{" |
| 3236 " \"included_categories\": [" | 3325 " \"included_categories\": [" |
| 3237 " \"filtered_cat\"," | 3326 " \"filtered_cat\"," |
| 3238 " \"unfiltered_cat\"]," | 3327 " \"unfiltered_cat\"]," |
| 3239 " \"event_filters\": [" | 3328 " \"event_filters\": [" |
| 3240 " {" | 3329 " {" |
| 3241 " \"filter_predicate\": \"testing_predicate\", " | 3330 " \"filter_predicate\": \"testing_predicate\", " |
| 3242 " \"included_categories\": [\"filtered_cat\"]" | 3331 " \"included_categories\": [\"filtered_cat\"]" |
| 3243 " }" | 3332 " }" |
| 3244 " " | 3333 " " |
| 3245 " ]" | 3334 " ]" |
| 3246 "}"; | 3335 "}"; |
| 3247 | 3336 |
| 3337 TestEventFilter::set_filter_return_value(true); | |
| 3248 TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter); | 3338 TraceLog::SetTraceEventFilterConstructorForTesting(ConstructTestEventFilter); |
| 3249 TraceConfig trace_config(config_json); | 3339 TraceConfig trace_config(config_json); |
| 3250 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); | 3340 TraceLog::GetInstance()->SetEnabled( |
| 3341 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); | |
| 3251 ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled()); | 3342 ASSERT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 3252 | 3343 |
| 3253 TRACE_EVENT0("filtered_cat", "a snake"); | 3344 TRACE_EVENT0("filtered_cat", "a snake"); |
| 3254 TRACE_EVENT0("filtered_cat", "a mushroom"); | 3345 TRACE_EVENT0("filtered_cat", "a mushroom"); |
| 3255 TRACE_EVENT0("unfiltered_cat", "a horse"); | 3346 TRACE_EVENT0("unfiltered_cat", "a horse"); |
| 3256 | 3347 |
| 3257 // This is scoped so we can test the end event being filtered. | 3348 // This is scoped so we can test the end event being filtered. |
| 3258 { TRACE_EVENT0("filtered_cat", "another cat whoa"); } | 3349 { TRACE_EVENT0("filtered_cat", "another cat whoa"); } |
| 3259 | 3350 |
| 3260 EndTraceAndFlush(); | 3351 EndTraceAndFlush(); |
| 3261 | 3352 |
| 3262 EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count()); | 3353 EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count()); |
| 3263 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count()); | 3354 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count()); |
| 3355 TestEventFilter::clear_counts(); | |
| 3264 } | 3356 } |
| 3265 | 3357 |
| 3266 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) { | 3358 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) { |
| 3267 std::string config_json = StringPrintf( | 3359 std::string config_json = StringPrintf( |
| 3268 "{" | 3360 "{" |
| 3269 " \"included_categories\": [" | 3361 " \"included_categories\": [" |
| 3270 " \"filtered_cat\"," | 3362 " \"filtered_cat\"," |
| 3271 " \"unfiltered_cat\"]," | 3363 " \"unfiltered_cat\"]," |
| 3272 " \"event_filters\": [" | 3364 " \"event_filters\": [" |
| 3273 " {" | 3365 " {" |
| 3274 " \"filter_predicate\": \"%s\", " | 3366 " \"filter_predicate\": \"%s\", " |
| 3275 " \"included_categories\": [\"*\"], " | 3367 " \"included_categories\": [\"*\"], " |
| 3276 " \"excluded_categories\": [\"unfiltered_cat\"], " | 3368 " \"excluded_categories\": [\"unfiltered_cat\"], " |
| 3277 " \"filter_args\": {" | 3369 " \"filter_args\": {" |
| 3278 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]" | 3370 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]" |
| 3279 " }" | 3371 " }" |
| 3280 " }" | 3372 " }" |
| 3281 " " | 3373 " " |
| 3282 " ]" | 3374 " ]" |
| 3283 "}", | 3375 "}", |
| 3284 TraceLog::TraceEventFilter::kEventWhitelistPredicate); | 3376 TraceLog::TraceEventFilter::kEventWhitelistPredicate); |
| 3285 | 3377 |
| 3286 TraceConfig trace_config(config_json); | 3378 TraceConfig trace_config(config_json); |
| 3287 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); | 3379 TraceLog::GetInstance()->SetEnabled( |
| 3380 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); | |
| 3288 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); | 3381 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 3289 | 3382 |
| 3290 TRACE_EVENT0("filtered_cat", "a snake"); | 3383 TRACE_EVENT0("filtered_cat", "a snake"); |
| 3291 TRACE_EVENT0("filtered_cat", "a mushroom"); | 3384 TRACE_EVENT0("filtered_cat", "a mushroom"); |
| 3292 TRACE_EVENT0("unfiltered_cat", "a cat"); | 3385 TRACE_EVENT0("unfiltered_cat", "a cat"); |
| 3293 | 3386 |
| 3294 EndTraceAndFlush(); | 3387 EndTraceAndFlush(); |
| 3295 | 3388 |
| 3296 EXPECT_TRUE(FindMatchingValue("name", "a snake")); | 3389 EXPECT_TRUE(FindMatchingValue("name", "a snake")); |
| 3297 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); | 3390 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 3308 " \"event_filters\": [" | 3401 " \"event_filters\": [" |
| 3309 " {" | 3402 " {" |
| 3310 " \"filter_predicate\": \"%s\", " | 3403 " \"filter_predicate\": \"%s\", " |
| 3311 " \"included_categories\": [\"*\"]" | 3404 " \"included_categories\": [\"*\"]" |
| 3312 " }" | 3405 " }" |
| 3313 " ]" | 3406 " ]" |
| 3314 "}", | 3407 "}", |
| 3315 TraceLog::TraceEventFilter::kHeapProfilerPredicate); | 3408 TraceLog::TraceEventFilter::kHeapProfilerPredicate); |
| 3316 | 3409 |
| 3317 TraceConfig trace_config(config_json); | 3410 TraceConfig trace_config(config_json); |
| 3318 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); | 3411 TraceLog::GetInstance()->SetEnabled( |
| 3412 trace_config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); | |
| 3319 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); | 3413 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 3320 | 3414 |
| 3321 TRACE_EVENT0("filtered_cat", "a snake"); | 3415 TRACE_EVENT0("filtered_cat", "a snake"); |
| 3322 TRACE_EVENT0("excluded_cat", "a mushroom"); | 3416 TRACE_EVENT0("excluded_cat", "a mushroom"); |
| 3323 TRACE_EVENT0("unfiltered_cat", "a cat"); | 3417 TRACE_EVENT0("unfiltered_cat", "a cat"); |
| 3324 | 3418 |
| 3325 EndTraceAndFlush(); | 3419 EndTraceAndFlush(); |
| 3326 | 3420 |
| 3327 // The predicate should not change behavior of the trace events. | 3421 // The predicate should not change behavior of the trace events. |
| 3328 EXPECT_TRUE(FindMatchingValue("name", "a snake")); | 3422 EXPECT_TRUE(FindMatchingValue("name", "a snake")); |
| 3329 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); | 3423 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); |
| 3330 EXPECT_TRUE(FindMatchingValue("name", "a cat")); | 3424 EXPECT_TRUE(FindMatchingValue("name", "a cat")); |
| 3331 } | 3425 } |
| 3332 | 3426 |
| 3333 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3427 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
| 3334 BeginSpecificTrace("-*"); | 3428 BeginSpecificTrace("-*"); |
| 3335 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3429 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
| 3336 EndTraceAndFlush(); | 3430 EndTraceAndFlush(); |
| 3337 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3431 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
| 3338 } | 3432 } |
| 3339 | 3433 |
| 3340 } // namespace trace_event | 3434 } // namespace trace_event |
| 3341 } // namespace base | 3435 } // namespace base |
| OLD | NEW |