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 |
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 Loading... |
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\": [\"filtered_cat\"]" |
| 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("filtered_cat", "a snake"); |
| 3270 TRACE_EVENT0("filtered_cat", "a mushroom"); |
| 3271 TRACE_EVENT0("unfiltered_cat", "a horse"); |
| 3272 |
| 3273 // This is scoped so we can test the end event being filtered. |
| 3274 { TRACE_EVENT0("filtered_cat", "another cat whoa"); } |
| 3275 |
| 3276 EndTraceAndFlush(); |
| 3277 |
| 3278 EXPECT_EQ(3u, TestEventFilter::filter_trace_event_hit_count()); |
| 3279 EXPECT_EQ(1u, TestEventFilter::end_event_hit_count()); |
| 3280 } |
| 3281 |
| 3282 TEST_F(TraceEventTestFixture, EventWhitelistFiltering) { |
| 3283 const char config_json[] = |
| 3284 "{" |
| 3285 " \"included_categories\": [" |
| 3286 " \"filtered_cat\"," |
| 3287 " \"unfiltered_cat\"]," |
| 3288 " \"event_filters\": [" |
| 3289 " {" |
| 3290 " \"filter_predicate\": \"event_whitelist_predicate\", " |
| 3291 " \"included_categories\": [\"*\"], " |
| 3292 " \"excluded_categories\": [\"unfiltered_cat\"], " |
| 3293 " \"filter_args\": {" |
| 3294 " \"event_name_whitelist\": [\"a snake\", \"a dog\"]" |
| 3295 " }" |
| 3296 " }" |
| 3297 " " |
| 3298 " ]" |
| 3299 "}"; |
| 3300 |
| 3301 TraceConfig trace_config(config_json); |
| 3302 TraceLog::GetInstance()->SetEnabled(trace_config, TraceLog::RECORDING_MODE); |
| 3303 EXPECT_TRUE(TraceLog::GetInstance()->IsEnabled()); |
| 3304 |
| 3305 TRACE_EVENT0("filtered_cat", "a snake"); |
| 3306 TRACE_EVENT0("filtered_cat", "a mushroom"); |
| 3307 TRACE_EVENT0("unfiltered_cat", "a cat"); |
| 3308 |
| 3309 EndTraceAndFlush(); |
| 3310 |
| 3311 EXPECT_TRUE(FindMatchingValue("name", "a snake")); |
| 3312 EXPECT_FALSE(FindMatchingValue("name", "a mushroom")); |
| 3313 EXPECT_TRUE(FindMatchingValue("name", "a cat")); |
| 3314 } |
| 3315 |
3220 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3316 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
3221 BeginSpecificTrace("-*"); | 3317 BeginSpecificTrace("-*"); |
3222 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3318 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
3223 EndTraceAndFlush(); | 3319 EndTraceAndFlush(); |
3224 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3320 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
3225 } | 3321 } |
3226 | 3322 |
3227 } // namespace trace_event | 3323 } // namespace trace_event |
3228 } // namespace base | 3324 } // namespace base |
OLD | NEW |