| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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_config.h" | 5 #include "base/trace_event/trace_config.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace base { | 23 namespace base { |
| 24 namespace trace_event { | 24 namespace trace_event { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // String options that can be used to initialize TraceOptions. | 28 // String options that can be used to initialize TraceOptions. |
| 29 const char kRecordUntilFull[] = "record-until-full"; | 29 const char kRecordUntilFull[] = "record-until-full"; |
| 30 const char kRecordContinuously[] = "record-continuously"; | 30 const char kRecordContinuously[] = "record-continuously"; |
| 31 const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible"; | 31 const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible"; |
| 32 const char kTraceToConsole[] = "trace-to-console"; | 32 const char kTraceToConsole[] = "trace-to-console"; |
| 33 const char kEnableSampling[] = "enable-sampling"; | |
| 34 const char kEnableSystrace[] = "enable-systrace"; | 33 const char kEnableSystrace[] = "enable-systrace"; |
| 35 const char kEnableArgumentFilter[] = "enable-argument-filter"; | 34 const char kEnableArgumentFilter[] = "enable-argument-filter"; |
| 36 | 35 |
| 37 // String parameters that can be used to parse the trace config string. | 36 // String parameters that can be used to parse the trace config string. |
| 38 const char kRecordModeParam[] = "record_mode"; | 37 const char kRecordModeParam[] = "record_mode"; |
| 39 const char kEnableSamplingParam[] = "enable_sampling"; | |
| 40 const char kEnableSystraceParam[] = "enable_systrace"; | 38 const char kEnableSystraceParam[] = "enable_systrace"; |
| 41 const char kEnableArgumentFilterParam[] = "enable_argument_filter"; | 39 const char kEnableArgumentFilterParam[] = "enable_argument_filter"; |
| 42 const char kIncludedCategoriesParam[] = "included_categories"; | 40 const char kIncludedCategoriesParam[] = "included_categories"; |
| 43 const char kExcludedCategoriesParam[] = "excluded_categories"; | 41 const char kExcludedCategoriesParam[] = "excluded_categories"; |
| 44 const char kSyntheticDelaysParam[] = "synthetic_delays"; | 42 const char kSyntheticDelaysParam[] = "synthetic_delays"; |
| 45 | 43 |
| 46 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; | 44 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; |
| 47 | 45 |
| 48 // String parameters that is used to parse memory dump config in trace config | 46 // String parameters that is used to parse memory dump config in trace config |
| 49 // string. | 47 // string. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 219 |
| 222 TraceConfig::TraceConfig(StringPiece config_string) { | 220 TraceConfig::TraceConfig(StringPiece config_string) { |
| 223 if (!config_string.empty()) | 221 if (!config_string.empty()) |
| 224 InitializeFromConfigString(config_string); | 222 InitializeFromConfigString(config_string); |
| 225 else | 223 else |
| 226 InitializeDefault(); | 224 InitializeDefault(); |
| 227 } | 225 } |
| 228 | 226 |
| 229 TraceConfig::TraceConfig(const TraceConfig& tc) | 227 TraceConfig::TraceConfig(const TraceConfig& tc) |
| 230 : record_mode_(tc.record_mode_), | 228 : record_mode_(tc.record_mode_), |
| 231 enable_sampling_(tc.enable_sampling_), | |
| 232 enable_systrace_(tc.enable_systrace_), | 229 enable_systrace_(tc.enable_systrace_), |
| 233 enable_argument_filter_(tc.enable_argument_filter_), | 230 enable_argument_filter_(tc.enable_argument_filter_), |
| 234 memory_dump_config_(tc.memory_dump_config_), | 231 memory_dump_config_(tc.memory_dump_config_), |
| 235 included_categories_(tc.included_categories_), | 232 included_categories_(tc.included_categories_), |
| 236 disabled_categories_(tc.disabled_categories_), | 233 disabled_categories_(tc.disabled_categories_), |
| 237 excluded_categories_(tc.excluded_categories_), | 234 excluded_categories_(tc.excluded_categories_), |
| 238 synthetic_delays_(tc.synthetic_delays_), | 235 synthetic_delays_(tc.synthetic_delays_), |
| 239 event_filters_(tc.event_filters_) {} | 236 event_filters_(tc.event_filters_) {} |
| 240 | 237 |
| 241 TraceConfig::~TraceConfig() { | 238 TraceConfig::~TraceConfig() { |
| 242 } | 239 } |
| 243 | 240 |
| 244 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { | 241 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
| 245 if (this == &rhs) | 242 if (this == &rhs) |
| 246 return *this; | 243 return *this; |
| 247 | 244 |
| 248 record_mode_ = rhs.record_mode_; | 245 record_mode_ = rhs.record_mode_; |
| 249 enable_sampling_ = rhs.enable_sampling_; | |
| 250 enable_systrace_ = rhs.enable_systrace_; | 246 enable_systrace_ = rhs.enable_systrace_; |
| 251 enable_argument_filter_ = rhs.enable_argument_filter_; | 247 enable_argument_filter_ = rhs.enable_argument_filter_; |
| 252 memory_dump_config_ = rhs.memory_dump_config_; | 248 memory_dump_config_ = rhs.memory_dump_config_; |
| 253 included_categories_ = rhs.included_categories_; | 249 included_categories_ = rhs.included_categories_; |
| 254 disabled_categories_ = rhs.disabled_categories_; | 250 disabled_categories_ = rhs.disabled_categories_; |
| 255 excluded_categories_ = rhs.excluded_categories_; | 251 excluded_categories_ = rhs.excluded_categories_; |
| 256 synthetic_delays_ = rhs.synthetic_delays_; | 252 synthetic_delays_ = rhs.synthetic_delays_; |
| 257 event_filters_ = rhs.event_filters_; | 253 event_filters_ = rhs.event_filters_; |
| 258 return *this; | 254 return *this; |
| 259 } | 255 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 331 } |
| 336 // If the category group is not excluded, and there are no included patterns | 332 // If the category group is not excluded, and there are no included patterns |
| 337 // we consider this category group enabled, as long as it had categories | 333 // we consider this category group enabled, as long as it had categories |
| 338 // other than disabled-by-default. | 334 // other than disabled-by-default. |
| 339 return !category_group_disabled && had_enabled_by_default && | 335 return !category_group_disabled && had_enabled_by_default && |
| 340 included_categories_.empty(); | 336 included_categories_.empty(); |
| 341 } | 337 } |
| 342 | 338 |
| 343 void TraceConfig::Merge(const TraceConfig& config) { | 339 void TraceConfig::Merge(const TraceConfig& config) { |
| 344 if (record_mode_ != config.record_mode_ | 340 if (record_mode_ != config.record_mode_ |
| 345 || enable_sampling_ != config.enable_sampling_ | |
| 346 || enable_systrace_ != config.enable_systrace_ | 341 || enable_systrace_ != config.enable_systrace_ |
| 347 || enable_argument_filter_ != config.enable_argument_filter_) { | 342 || enable_argument_filter_ != config.enable_argument_filter_) { |
| 348 DLOG(ERROR) << "Attempting to merge trace config with a different " | 343 DLOG(ERROR) << "Attempting to merge trace config with a different " |
| 349 << "set of options."; | 344 << "set of options."; |
| 350 } | 345 } |
| 351 | 346 |
| 352 // Keep included patterns only if both filters have an included entry. | 347 // Keep included patterns only if both filters have an included entry. |
| 353 // Otherwise, one of the filter was specifying "*" and we want to honor the | 348 // Otherwise, one of the filter was specifying "*" and we want to honor the |
| 354 // broadest filter. | 349 // broadest filter. |
| 355 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { | 350 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 370 excluded_categories_.insert(excluded_categories_.end(), | 365 excluded_categories_.insert(excluded_categories_.end(), |
| 371 config.excluded_categories_.begin(), | 366 config.excluded_categories_.begin(), |
| 372 config.excluded_categories_.end()); | 367 config.excluded_categories_.end()); |
| 373 synthetic_delays_.insert(synthetic_delays_.end(), | 368 synthetic_delays_.insert(synthetic_delays_.end(), |
| 374 config.synthetic_delays_.begin(), | 369 config.synthetic_delays_.begin(), |
| 375 config.synthetic_delays_.end()); | 370 config.synthetic_delays_.end()); |
| 376 } | 371 } |
| 377 | 372 |
| 378 void TraceConfig::Clear() { | 373 void TraceConfig::Clear() { |
| 379 record_mode_ = RECORD_UNTIL_FULL; | 374 record_mode_ = RECORD_UNTIL_FULL; |
| 380 enable_sampling_ = false; | |
| 381 enable_systrace_ = false; | 375 enable_systrace_ = false; |
| 382 enable_argument_filter_ = false; | 376 enable_argument_filter_ = false; |
| 383 included_categories_.clear(); | 377 included_categories_.clear(); |
| 384 disabled_categories_.clear(); | 378 disabled_categories_.clear(); |
| 385 excluded_categories_.clear(); | 379 excluded_categories_.clear(); |
| 386 synthetic_delays_.clear(); | 380 synthetic_delays_.clear(); |
| 387 memory_dump_config_.Clear(); | 381 memory_dump_config_.Clear(); |
| 388 event_filters_.clear(); | 382 event_filters_.clear(); |
| 389 } | 383 } |
| 390 | 384 |
| 391 void TraceConfig::InitializeDefault() { | 385 void TraceConfig::InitializeDefault() { |
| 392 record_mode_ = RECORD_UNTIL_FULL; | 386 record_mode_ = RECORD_UNTIL_FULL; |
| 393 enable_sampling_ = false; | |
| 394 enable_systrace_ = false; | 387 enable_systrace_ = false; |
| 395 enable_argument_filter_ = false; | 388 enable_argument_filter_ = false; |
| 396 } | 389 } |
| 397 | 390 |
| 398 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { | 391 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { |
| 399 record_mode_ = RECORD_UNTIL_FULL; | 392 record_mode_ = RECORD_UNTIL_FULL; |
| 400 std::string record_mode; | 393 std::string record_mode; |
| 401 if (dict.GetString(kRecordModeParam, &record_mode)) { | 394 if (dict.GetString(kRecordModeParam, &record_mode)) { |
| 402 if (record_mode == kRecordUntilFull) { | 395 if (record_mode == kRecordUntilFull) { |
| 403 record_mode_ = RECORD_UNTIL_FULL; | 396 record_mode_ = RECORD_UNTIL_FULL; |
| 404 } else if (record_mode == kRecordContinuously) { | 397 } else if (record_mode == kRecordContinuously) { |
| 405 record_mode_ = RECORD_CONTINUOUSLY; | 398 record_mode_ = RECORD_CONTINUOUSLY; |
| 406 } else if (record_mode == kTraceToConsole) { | 399 } else if (record_mode == kTraceToConsole) { |
| 407 record_mode_ = ECHO_TO_CONSOLE; | 400 record_mode_ = ECHO_TO_CONSOLE; |
| 408 } else if (record_mode == kRecordAsMuchAsPossible) { | 401 } else if (record_mode == kRecordAsMuchAsPossible) { |
| 409 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; | 402 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
| 410 } | 403 } |
| 411 } | 404 } |
| 412 | 405 |
| 413 bool val; | 406 bool val; |
| 414 enable_sampling_ = dict.GetBoolean(kEnableSamplingParam, &val) ? val : false; | |
| 415 enable_systrace_ = dict.GetBoolean(kEnableSystraceParam, &val) ? val : false; | 407 enable_systrace_ = dict.GetBoolean(kEnableSystraceParam, &val) ? val : false; |
| 416 enable_argument_filter_ = | 408 enable_argument_filter_ = |
| 417 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; | 409 dict.GetBoolean(kEnableArgumentFilterParam, &val) ? val : false; |
| 418 | 410 |
| 419 const ListValue* category_list = nullptr; | 411 const ListValue* category_list = nullptr; |
| 420 if (dict.GetList(kIncludedCategoriesParam, &category_list)) | 412 if (dict.GetList(kIncludedCategoriesParam, &category_list)) |
| 421 SetCategoriesFromIncludedList(*category_list); | 413 SetCategoriesFromIncludedList(*category_list); |
| 422 if (dict.GetList(kExcludedCategoriesParam, &category_list)) | 414 if (dict.GetList(kExcludedCategoriesParam, &category_list)) |
| 423 SetCategoriesFromExcludedList(*category_list); | 415 SetCategoriesFromExcludedList(*category_list); |
| 424 if (dict.GetList(kSyntheticDelaysParam, &category_list)) | 416 if (dict.GetList(kSyntheticDelaysParam, &category_list)) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), | 467 } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), |
| 476 TRACE_DISABLED_BY_DEFAULT("")) == 0) { | 468 TRACE_DISABLED_BY_DEFAULT("")) == 0) { |
| 477 disabled_categories_.push_back(category); | 469 disabled_categories_.push_back(category); |
| 478 } else { | 470 } else { |
| 479 included_categories_.push_back(category); | 471 included_categories_.push_back(category); |
| 480 } | 472 } |
| 481 } | 473 } |
| 482 } | 474 } |
| 483 | 475 |
| 484 record_mode_ = RECORD_UNTIL_FULL; | 476 record_mode_ = RECORD_UNTIL_FULL; |
| 485 enable_sampling_ = false; | |
| 486 enable_systrace_ = false; | 477 enable_systrace_ = false; |
| 487 enable_argument_filter_ = false; | 478 enable_argument_filter_ = false; |
| 488 if (!trace_options_string.empty()) { | 479 if (!trace_options_string.empty()) { |
| 489 std::vector<std::string> split = | 480 std::vector<std::string> split = |
| 490 SplitString(trace_options_string, ",", TRIM_WHITESPACE, SPLIT_WANT_ALL); | 481 SplitString(trace_options_string, ",", TRIM_WHITESPACE, SPLIT_WANT_ALL); |
| 491 for (const std::string& token : split) { | 482 for (const std::string& token : split) { |
| 492 if (token == kRecordUntilFull) { | 483 if (token == kRecordUntilFull) { |
| 493 record_mode_ = RECORD_UNTIL_FULL; | 484 record_mode_ = RECORD_UNTIL_FULL; |
| 494 } else if (token == kRecordContinuously) { | 485 } else if (token == kRecordContinuously) { |
| 495 record_mode_ = RECORD_CONTINUOUSLY; | 486 record_mode_ = RECORD_CONTINUOUSLY; |
| 496 } else if (token == kTraceToConsole) { | 487 } else if (token == kTraceToConsole) { |
| 497 record_mode_ = ECHO_TO_CONSOLE; | 488 record_mode_ = ECHO_TO_CONSOLE; |
| 498 } else if (token == kRecordAsMuchAsPossible) { | 489 } else if (token == kRecordAsMuchAsPossible) { |
| 499 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; | 490 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
| 500 } else if (token == kEnableSampling) { | |
| 501 enable_sampling_ = true; | |
| 502 } else if (token == kEnableSystrace) { | 491 } else if (token == kEnableSystrace) { |
| 503 enable_systrace_ = true; | 492 enable_systrace_ = true; |
| 504 } else if (token == kEnableArgumentFilter) { | 493 } else if (token == kEnableArgumentFilter) { |
| 505 enable_argument_filter_ = true; | 494 enable_argument_filter_ = true; |
| 506 } | 495 } |
| 507 } | 496 } |
| 508 } | 497 } |
| 509 | 498 |
| 510 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 499 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 511 SetDefaultMemoryDumpConfig(); | 500 SetDefaultMemoryDumpConfig(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 case RECORD_AS_MUCH_AS_POSSIBLE: | 692 case RECORD_AS_MUCH_AS_POSSIBLE: |
| 704 dict->SetString(kRecordModeParam, kRecordAsMuchAsPossible); | 693 dict->SetString(kRecordModeParam, kRecordAsMuchAsPossible); |
| 705 break; | 694 break; |
| 706 case ECHO_TO_CONSOLE: | 695 case ECHO_TO_CONSOLE: |
| 707 dict->SetString(kRecordModeParam, kTraceToConsole); | 696 dict->SetString(kRecordModeParam, kTraceToConsole); |
| 708 break; | 697 break; |
| 709 default: | 698 default: |
| 710 NOTREACHED(); | 699 NOTREACHED(); |
| 711 } | 700 } |
| 712 | 701 |
| 713 dict->SetBoolean(kEnableSamplingParam, enable_sampling_); | |
| 714 dict->SetBoolean(kEnableSystraceParam, enable_systrace_); | 702 dict->SetBoolean(kEnableSystraceParam, enable_systrace_); |
| 715 dict->SetBoolean(kEnableArgumentFilterParam, enable_argument_filter_); | 703 dict->SetBoolean(kEnableArgumentFilterParam, enable_argument_filter_); |
| 716 | 704 |
| 717 StringList categories(included_categories_); | 705 StringList categories(included_categories_); |
| 718 categories.insert(categories.end(), | 706 categories.insert(categories.end(), |
| 719 disabled_categories_.begin(), | 707 disabled_categories_.begin(), |
| 720 disabled_categories_.end()); | 708 disabled_categories_.end()); |
| 721 AddCategoryToDict(dict.get(), kIncludedCategoriesParam, categories); | 709 AddCategoryToDict(dict.get(), kIncludedCategoriesParam, categories); |
| 722 AddCategoryToDict(dict.get(), kExcludedCategoriesParam, excluded_categories_); | 710 AddCategoryToDict(dict.get(), kExcludedCategoriesParam, excluded_categories_); |
| 723 AddCategoryToDict(dict.get(), kSyntheticDelaysParam, synthetic_delays_); | 711 AddCategoryToDict(dict.get(), kSyntheticDelaysParam, synthetic_delays_); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 break; | 791 break; |
| 804 case RECORD_AS_MUCH_AS_POSSIBLE: | 792 case RECORD_AS_MUCH_AS_POSSIBLE: |
| 805 ret = kRecordAsMuchAsPossible; | 793 ret = kRecordAsMuchAsPossible; |
| 806 break; | 794 break; |
| 807 case ECHO_TO_CONSOLE: | 795 case ECHO_TO_CONSOLE: |
| 808 ret = kTraceToConsole; | 796 ret = kTraceToConsole; |
| 809 break; | 797 break; |
| 810 default: | 798 default: |
| 811 NOTREACHED(); | 799 NOTREACHED(); |
| 812 } | 800 } |
| 813 if (enable_sampling_) | |
| 814 ret = ret + "," + kEnableSampling; | |
| 815 if (enable_systrace_) | 801 if (enable_systrace_) |
| 816 ret = ret + "," + kEnableSystrace; | 802 ret = ret + "," + kEnableSystrace; |
| 817 if (enable_argument_filter_) | 803 if (enable_argument_filter_) |
| 818 ret = ret + "," + kEnableArgumentFilter; | 804 ret = ret + "," + kEnableArgumentFilter; |
| 819 return ret; | 805 return ret; |
| 820 } | 806 } |
| 821 | 807 |
| 822 void TraceConfig::WriteCategoryFilterString(const StringList& values, | 808 void TraceConfig::WriteCategoryFilterString(const StringList& values, |
| 823 std::string* out, | 809 std::string* out, |
| 824 bool included) const { | 810 bool included) const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 StringPiece str) { | 854 StringPiece str) { |
| 869 return str.empty() || str.front() == ' ' || str.back() == ' '; | 855 return str.empty() || str.front() == ' ' || str.back() == ' '; |
| 870 } | 856 } |
| 871 | 857 |
| 872 bool TraceConfig::HasIncludedPatterns() const { | 858 bool TraceConfig::HasIncludedPatterns() const { |
| 873 return !included_categories_.empty(); | 859 return !included_categories_.empty(); |
| 874 } | 860 } |
| 875 | 861 |
| 876 } // namespace trace_event | 862 } // namespace trace_event |
| 877 } // namespace base | 863 } // namespace base |
| OLD | NEW |