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/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 } | 2351 } |
2352 } | 2352 } |
2353 | 2353 |
2354 bool CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( | 2354 bool CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
2355 const std::string& str) { | 2355 const std::string& str) { |
2356 return str.empty() || | 2356 return str.empty() || |
2357 str.at(0) == ' ' || | 2357 str.at(0) == ' ' || |
2358 str.at(str.length() - 1) == ' '; | 2358 str.at(str.length() - 1) == ' '; |
2359 } | 2359 } |
2360 | 2360 |
2361 bool CategoryFilter::DoesCategoryGroupContainCategory( | |
2362 const char* category_group, | |
2363 const char* category) const { | |
2364 DCHECK(category); | |
2365 CStringTokenizer category_group_tokens(category_group, | |
2366 category_group + strlen(category_group), ","); | |
2367 while (category_group_tokens.GetNext()) { | |
2368 std::string category_group_token = category_group_tokens.token(); | |
2369 // Don't allow empty tokens, nor tokens with leading or trailing space. | |
2370 DCHECK(!CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( | |
2371 category_group_token)) | |
2372 << "Disallowed category string"; | |
2373 if (MatchPattern(category_group_token.c_str(), category)) | |
2374 return true; | |
2375 } | |
2376 return false; | |
2377 } | |
2378 | |
2379 CategoryFilter::CategoryFilter(const std::string& filter_string) { | 2361 CategoryFilter::CategoryFilter(const std::string& filter_string) { |
2380 if (!filter_string.empty()) | 2362 if (!filter_string.empty()) |
2381 Initialize(filter_string); | 2363 Initialize(filter_string); |
2382 else | 2364 else |
2383 Initialize(CategoryFilter::kDefaultCategoryFilterString); | 2365 Initialize(CategoryFilter::kDefaultCategoryFilterString); |
2384 } | 2366 } |
2385 | 2367 |
2386 CategoryFilter::CategoryFilter() { | 2368 CategoryFilter::CategoryFilter() { |
2387 Initialize(CategoryFilter::kDefaultCategoryFilterString); | 2369 Initialize(CategoryFilter::kDefaultCategoryFilterString); |
2388 } | 2370 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2476 WriteString(disabled_, &filter_string, true); | 2458 WriteString(disabled_, &filter_string, true); |
2477 WriteString(excluded_, &filter_string, false); | 2459 WriteString(excluded_, &filter_string, false); |
2478 WriteString(delays_, &filter_string); | 2460 WriteString(delays_, &filter_string); |
2479 return filter_string; | 2461 return filter_string; |
2480 } | 2462 } |
2481 | 2463 |
2482 bool CategoryFilter::IsCategoryGroupEnabled( | 2464 bool CategoryFilter::IsCategoryGroupEnabled( |
2483 const char* category_group_name) const { | 2465 const char* category_group_name) const { |
2484 // TraceLog should call this method only as part of enabling/disabling | 2466 // TraceLog should call this method only as part of enabling/disabling |
2485 // categories. | 2467 // categories. |
| 2468 |
| 2469 bool had_enabled_by_default = false; |
| 2470 DCHECK(category_group_name); |
| 2471 CStringTokenizer category_group_tokens( |
| 2472 category_group_name, category_group_name + strlen(category_group_name), |
| 2473 ","); |
| 2474 while (category_group_tokens.GetNext()) { |
| 2475 std::string category_group_token = category_group_tokens.token(); |
| 2476 // Don't allow empty tokens, nor tokens with leading or trailing space. |
| 2477 DCHECK(!CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| 2478 category_group_token)) |
| 2479 << "Disallowed category string"; |
| 2480 if (IsCategoryEnabled(category_group_token.c_str())) { |
| 2481 return true; |
| 2482 } |
| 2483 if (!MatchPattern(category_group_token.c_str(), |
| 2484 TRACE_DISABLED_BY_DEFAULT("*"))) |
| 2485 had_enabled_by_default = true; |
| 2486 } |
| 2487 // Do a second pass to check for explicitly disabled categories |
| 2488 // (those explicitly enabled have priority due to first pass). |
| 2489 category_group_tokens.Reset(); |
| 2490 while (category_group_tokens.GetNext()) { |
| 2491 std::string category_group_token = category_group_tokens.token(); |
| 2492 for (StringList::const_iterator ci = excluded_.begin(); |
| 2493 ci != excluded_.end(); ++ci) { |
| 2494 if (MatchPattern(category_group_token.c_str(), ci->c_str())) |
| 2495 return false; |
| 2496 } |
| 2497 } |
| 2498 // If the category group is not excluded, and there are no included patterns |
| 2499 // we consider this category group enabled, as long as it had categories |
| 2500 // other than disabled-by-default. |
| 2501 return included_.empty() && had_enabled_by_default; |
| 2502 } |
| 2503 |
| 2504 bool CategoryFilter::IsCategoryEnabled(const char* category_name) const { |
2486 StringList::const_iterator ci; | 2505 StringList::const_iterator ci; |
2487 | 2506 |
2488 // Check the disabled- filters and the disabled-* wildcard first so that a | 2507 // Check the disabled- filters and the disabled-* wildcard first so that a |
2489 // "*" filter does not include the disabled. | 2508 // "*" filter does not include the disabled. |
2490 for (ci = disabled_.begin(); ci != disabled_.end(); ++ci) { | 2509 for (ci = disabled_.begin(); ci != disabled_.end(); ++ci) { |
2491 if (DoesCategoryGroupContainCategory(category_group_name, ci->c_str())) | 2510 if (MatchPattern(category_name, ci->c_str())) |
2492 return true; | 2511 return true; |
2493 } | 2512 } |
2494 if (DoesCategoryGroupContainCategory(category_group_name, | 2513 |
2495 TRACE_DISABLED_BY_DEFAULT("*"))) | 2514 if (MatchPattern(category_name, TRACE_DISABLED_BY_DEFAULT("*"))) |
2496 return false; | 2515 return false; |
2497 | 2516 |
2498 for (ci = included_.begin(); ci != included_.end(); ++ci) { | 2517 for (ci = included_.begin(); ci != included_.end(); ++ci) { |
2499 if (DoesCategoryGroupContainCategory(category_group_name, ci->c_str())) | 2518 if (MatchPattern(category_name, ci->c_str())) |
2500 return true; | 2519 return true; |
2501 } | 2520 } |
2502 | 2521 |
2503 for (ci = excluded_.begin(); ci != excluded_.end(); ++ci) { | 2522 return false; |
2504 if (DoesCategoryGroupContainCategory(category_group_name, ci->c_str())) | |
2505 return false; | |
2506 } | |
2507 // If the category group is not excluded, and there are no included patterns | |
2508 // we consider this pattern enabled. | |
2509 return included_.empty(); | |
2510 } | 2523 } |
2511 | 2524 |
2512 bool CategoryFilter::HasIncludedPatterns() const { | 2525 bool CategoryFilter::HasIncludedPatterns() const { |
2513 return !included_.empty(); | 2526 return !included_.empty(); |
2514 } | 2527 } |
2515 | 2528 |
2516 void CategoryFilter::Merge(const CategoryFilter& nested_filter) { | 2529 void CategoryFilter::Merge(const CategoryFilter& nested_filter) { |
2517 // Keep included patterns only if both filters have an included entry. | 2530 // Keep included patterns only if both filters have an included entry. |
2518 // Otherwise, one of the filter was specifying "*" and we want to honour the | 2531 // Otherwise, one of the filter was specifying "*" and we want to honour the |
2519 // broadest filter. | 2532 // broadest filter. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2572 } | 2585 } |
2573 | 2586 |
2574 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2587 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2575 if (*category_group_enabled_) { | 2588 if (*category_group_enabled_) { |
2576 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2589 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2577 name_, event_handle_); | 2590 name_, event_handle_); |
2578 } | 2591 } |
2579 } | 2592 } |
2580 | 2593 |
2581 } // namespace trace_event_internal | 2594 } // namespace trace_event_internal |
OLD | NEW |