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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; | 45 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; |
46 | 46 |
47 // String parameters that is used to parse memory dump config in trace config | 47 // String parameters that is used to parse memory dump config in trace config |
48 // string. | 48 // string. |
49 const char kMemoryDumpConfigParam[] = "memory_dump_config"; | 49 const char kMemoryDumpConfigParam[] = "memory_dump_config"; |
50 const char kTriggersParam[] = "triggers"; | 50 const char kTriggersParam[] = "triggers"; |
51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; | 51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
52 const char kModeParam[] = "mode"; | 52 const char kModeParam[] = "mode"; |
53 | 53 |
| 54 // String parameters used to parse category event filters. |
| 55 const char kCategoryEventFilterParam[] = "category_event_filters"; |
| 56 const char kPredicateParam[] = "predicate"; |
| 57 const char kArgsParam[] = "args"; |
| 58 |
54 // Default configuration of memory dumps. | 59 // Default configuration of memory dumps. |
55 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { | 60 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { |
56 2000, // periodic_interval_ms | 61 2000, // periodic_interval_ms |
57 MemoryDumpLevelOfDetail::DETAILED}; | 62 MemoryDumpLevelOfDetail::DETAILED}; |
58 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { | 63 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { |
59 250, // periodic_interval_ms | 64 250, // periodic_interval_ms |
60 MemoryDumpLevelOfDetail::LIGHT}; | 65 MemoryDumpLevelOfDetail::LIGHT}; |
61 | 66 |
62 class ConvertableTraceConfigToTraceFormat | 67 class ConvertableTraceConfigToTraceFormat |
63 : public base::trace_event::ConvertableToTraceFormat { | 68 : public base::trace_event::ConvertableToTraceFormat { |
64 public: | 69 public: |
65 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) | 70 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) |
66 : trace_config_(trace_config) {} | 71 : trace_config_(trace_config) {} |
67 ~ConvertableTraceConfigToTraceFormat() override {} | 72 ~ConvertableTraceConfigToTraceFormat() override {} |
68 void AppendAsTraceFormat(std::string* out) const override { | 73 void AppendAsTraceFormat(std::string* out) const override { |
69 out->append(trace_config_.ToString()); | 74 out->append(trace_config_.ToString()); |
70 } | 75 } |
71 | 76 |
72 private: | 77 private: |
73 const TraceConfig trace_config_; | 78 const TraceConfig trace_config_; |
74 }; | 79 }; |
75 | 80 |
76 } // namespace | 81 } // namespace |
77 | 82 |
| 83 TraceConfig::CategoryEventFilterConfig::CategoryEventFilterConfig( |
| 84 const std::string& predicate_name) |
| 85 : predicate_name_(predicate_name) {} |
| 86 TraceConfig::CategoryEventFilterConfig::~CategoryEventFilterConfig() {} |
| 87 |
| 88 TraceConfig::CategoryEventFilterConfig::CategoryEventFilterConfig( |
| 89 const CategoryEventFilterConfig& tc) |
| 90 : predicate_name_(tc.predicate_name_), |
| 91 included_categories_(tc.included_categories_), |
| 92 excluded_categories_(tc.excluded_categories_) { |
| 93 if (tc.args_) |
| 94 args_ = tc.args_->CreateDeepCopy(); |
| 95 } |
| 96 |
| 97 TraceConfig::CategoryEventFilterConfig& TraceConfig::CategoryEventFilterConfig:: |
| 98 operator=(const TraceConfig::CategoryEventFilterConfig& rhs) { |
| 99 if (this == &rhs) |
| 100 return *this; |
| 101 |
| 102 predicate_name_ = rhs.predicate_name_; |
| 103 included_categories_ = rhs.included_categories_; |
| 104 excluded_categories_ = rhs.excluded_categories_; |
| 105 if (rhs.args_) |
| 106 args_ = rhs.args_->CreateDeepCopy(); |
| 107 |
| 108 return *this; |
| 109 } |
| 110 |
| 111 void TraceConfig::CategoryEventFilterConfig::AddIncludedCategory( |
| 112 const std::string& category) { |
| 113 included_categories_.push_back(category); |
| 114 } |
| 115 |
| 116 void TraceConfig::CategoryEventFilterConfig::AddExcludedCategory( |
| 117 const std::string& category) { |
| 118 excluded_categories_.push_back(category); |
| 119 } |
| 120 |
| 121 void TraceConfig::CategoryEventFilterConfig::SetArgs( |
| 122 std::unique_ptr<base::DictionaryValue> args) { |
| 123 args_ = std::move(args); |
| 124 } |
| 125 |
| 126 bool TraceConfig::CategoryEventFilterConfig::IsCategoryGroupEnabled( |
| 127 const char* category_group_name) const { |
| 128 CStringTokenizer category_group_tokens( |
| 129 category_group_name, category_group_name + strlen(category_group_name), |
| 130 ","); |
| 131 while (category_group_tokens.GetNext()) { |
| 132 std::string category_group_token = category_group_tokens.token(); |
| 133 |
| 134 for (const auto& excluded_category : excluded_categories_) { |
| 135 if (base::MatchPattern(category_group_token.c_str(), |
| 136 excluded_category.c_str())) { |
| 137 return false; |
| 138 } |
| 139 } |
| 140 |
| 141 for (const auto& included_category : included_categories_) { |
| 142 if (base::MatchPattern(category_group_token.c_str(), |
| 143 included_category.c_str())) { |
| 144 return true; |
| 145 } |
| 146 } |
| 147 } |
| 148 |
| 149 return false; |
| 150 } |
| 151 |
78 TraceConfig::TraceConfig() { | 152 TraceConfig::TraceConfig() { |
79 InitializeDefault(); | 153 InitializeDefault(); |
80 } | 154 } |
81 | 155 |
82 TraceConfig::TraceConfig(const std::string& category_filter_string, | 156 TraceConfig::TraceConfig(const std::string& category_filter_string, |
83 const std::string& trace_options_string) { | 157 const std::string& trace_options_string) { |
84 InitializeFromStrings(category_filter_string, trace_options_string); | 158 InitializeFromStrings(category_filter_string, trace_options_string); |
85 } | 159 } |
86 | 160 |
87 TraceConfig::TraceConfig(const std::string& category_filter_string, | 161 TraceConfig::TraceConfig(const std::string& category_filter_string, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 193 |
120 TraceConfig::TraceConfig(const TraceConfig& tc) | 194 TraceConfig::TraceConfig(const TraceConfig& tc) |
121 : record_mode_(tc.record_mode_), | 195 : record_mode_(tc.record_mode_), |
122 enable_sampling_(tc.enable_sampling_), | 196 enable_sampling_(tc.enable_sampling_), |
123 enable_systrace_(tc.enable_systrace_), | 197 enable_systrace_(tc.enable_systrace_), |
124 enable_argument_filter_(tc.enable_argument_filter_), | 198 enable_argument_filter_(tc.enable_argument_filter_), |
125 memory_dump_config_(tc.memory_dump_config_), | 199 memory_dump_config_(tc.memory_dump_config_), |
126 included_categories_(tc.included_categories_), | 200 included_categories_(tc.included_categories_), |
127 disabled_categories_(tc.disabled_categories_), | 201 disabled_categories_(tc.disabled_categories_), |
128 excluded_categories_(tc.excluded_categories_), | 202 excluded_categories_(tc.excluded_categories_), |
129 synthetic_delays_(tc.synthetic_delays_) {} | 203 synthetic_delays_(tc.synthetic_delays_), |
| 204 category_event_filters_(tc.category_event_filters_) {} |
130 | 205 |
131 TraceConfig::~TraceConfig() { | 206 TraceConfig::~TraceConfig() { |
132 } | 207 } |
133 | 208 |
134 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { | 209 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
135 if (this == &rhs) | 210 if (this == &rhs) |
136 return *this; | 211 return *this; |
137 | 212 |
138 record_mode_ = rhs.record_mode_; | 213 record_mode_ = rhs.record_mode_; |
139 enable_sampling_ = rhs.enable_sampling_; | 214 enable_sampling_ = rhs.enable_sampling_; |
140 enable_systrace_ = rhs.enable_systrace_; | 215 enable_systrace_ = rhs.enable_systrace_; |
141 enable_argument_filter_ = rhs.enable_argument_filter_; | 216 enable_argument_filter_ = rhs.enable_argument_filter_; |
142 memory_dump_config_ = rhs.memory_dump_config_; | 217 memory_dump_config_ = rhs.memory_dump_config_; |
143 included_categories_ = rhs.included_categories_; | 218 included_categories_ = rhs.included_categories_; |
144 disabled_categories_ = rhs.disabled_categories_; | 219 disabled_categories_ = rhs.disabled_categories_; |
145 excluded_categories_ = rhs.excluded_categories_; | 220 excluded_categories_ = rhs.excluded_categories_; |
146 synthetic_delays_ = rhs.synthetic_delays_; | 221 synthetic_delays_ = rhs.synthetic_delays_; |
| 222 category_event_filters_ = rhs.category_event_filters_; |
147 return *this; | 223 return *this; |
148 } | 224 } |
149 | 225 |
150 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { | 226 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { |
151 return synthetic_delays_; | 227 return synthetic_delays_; |
152 } | 228 } |
153 | 229 |
154 std::string TraceConfig::ToString() const { | 230 std::string TraceConfig::ToString() const { |
155 base::DictionaryValue dict; | 231 base::DictionaryValue dict; |
156 ToDict(dict); | 232 ToDict(dict); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 void TraceConfig::Clear() { | 351 void TraceConfig::Clear() { |
276 record_mode_ = RECORD_UNTIL_FULL; | 352 record_mode_ = RECORD_UNTIL_FULL; |
277 enable_sampling_ = false; | 353 enable_sampling_ = false; |
278 enable_systrace_ = false; | 354 enable_systrace_ = false; |
279 enable_argument_filter_ = false; | 355 enable_argument_filter_ = false; |
280 included_categories_.clear(); | 356 included_categories_.clear(); |
281 disabled_categories_.clear(); | 357 disabled_categories_.clear(); |
282 excluded_categories_.clear(); | 358 excluded_categories_.clear(); |
283 synthetic_delays_.clear(); | 359 synthetic_delays_.clear(); |
284 memory_dump_config_.clear(); | 360 memory_dump_config_.clear(); |
| 361 category_event_filters_.clear(); |
285 } | 362 } |
286 | 363 |
287 void TraceConfig::InitializeDefault() { | 364 void TraceConfig::InitializeDefault() { |
288 record_mode_ = RECORD_UNTIL_FULL; | 365 record_mode_ = RECORD_UNTIL_FULL; |
289 enable_sampling_ = false; | 366 enable_sampling_ = false; |
290 enable_systrace_ = false; | 367 enable_systrace_ = false; |
291 enable_argument_filter_ = false; | 368 enable_argument_filter_ = false; |
292 excluded_categories_.push_back("*Debug"); | 369 excluded_categories_.push_back("*Debug"); |
293 excluded_categories_.push_back("*Test"); | 370 excluded_categories_.push_back("*Test"); |
294 } | 371 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 413 |
337 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 414 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
338 // If dump triggers not set, the client is using the legacy with just | 415 // If dump triggers not set, the client is using the legacy with just |
339 // category enabled. So, use the default periodic dump config. | 416 // category enabled. So, use the default periodic dump config. |
340 const base::DictionaryValue* memory_dump_config = nullptr; | 417 const base::DictionaryValue* memory_dump_config = nullptr; |
341 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 418 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
342 SetMemoryDumpConfig(*memory_dump_config); | 419 SetMemoryDumpConfig(*memory_dump_config); |
343 else | 420 else |
344 SetDefaultMemoryDumpConfig(); | 421 SetDefaultMemoryDumpConfig(); |
345 } | 422 } |
| 423 |
| 424 const base::ListValue* category_event_filters = nullptr; |
| 425 if (dict.GetList(kCategoryEventFilterParam, &category_event_filters)) |
| 426 SetCategoryEventFilters(*category_event_filters); |
346 } | 427 } |
347 | 428 |
348 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { | 429 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
349 std::unique_ptr<Value> value(JSONReader::Read(config_string)); | 430 std::unique_ptr<Value> value(JSONReader::Read(config_string)); |
350 if (!value) | 431 if (!value) |
351 return InitializeDefault(); | 432 return InitializeDefault(); |
352 | 433 |
353 const DictionaryValue* dict = nullptr; | 434 const DictionaryValue* dict = nullptr; |
354 bool is_dict = value->GetAsDictionary(&dict); | 435 bool is_dict = value->GetAsDictionary(&dict); |
355 | 436 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 memory_dump_config_.push_back(dump_config); | 598 memory_dump_config_.push_back(dump_config); |
518 } | 599 } |
519 } | 600 } |
520 | 601 |
521 void TraceConfig::SetDefaultMemoryDumpConfig() { | 602 void TraceConfig::SetDefaultMemoryDumpConfig() { |
522 memory_dump_config_.clear(); | 603 memory_dump_config_.clear(); |
523 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); | 604 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); |
524 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); | 605 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); |
525 } | 606 } |
526 | 607 |
| 608 void TraceConfig::SetCategoryEventFilters( |
| 609 const base::ListValue& category_event_filters) { |
| 610 category_event_filters_.clear(); |
| 611 |
| 612 for (size_t i = 0; i < category_event_filters.GetSize(); ++i) { |
| 613 const base::DictionaryValue* event_filter = nullptr; |
| 614 if (!category_event_filters.GetDictionary(i, &event_filter)) |
| 615 continue; |
| 616 |
| 617 std::string predicate_name; |
| 618 if (!event_filter->GetString(kPredicateParam, &predicate_name)) { |
| 619 LOG(ERROR) << "Invalid predicate name in category event filter."; |
| 620 continue; |
| 621 } |
| 622 |
| 623 CategoryEventFilterConfig new_config(predicate_name); |
| 624 const base::ListValue* included_list = nullptr; |
| 625 if (!event_filter->GetList(kIncludedCategoriesParam, &included_list)) { |
| 626 LOG(ERROR) << "Missing included_categories in category event filter."; |
| 627 continue; |
| 628 } |
| 629 |
| 630 for (size_t i = 0; i < included_list->GetSize(); ++i) { |
| 631 std::string category; |
| 632 if (included_list->GetString(i, &category)) |
| 633 new_config.AddIncludedCategory(category); |
| 634 } |
| 635 |
| 636 const base::ListValue* excluded_list = nullptr; |
| 637 if (event_filter->GetList(kExcludedCategoriesParam, &excluded_list)) { |
| 638 for (size_t i = 0; i < excluded_list->GetSize(); ++i) { |
| 639 std::string category; |
| 640 if (excluded_list->GetString(i, &category)) |
| 641 new_config.AddExcludedCategory(category); |
| 642 } |
| 643 } |
| 644 |
| 645 const base::DictionaryValue* args_dict = nullptr; |
| 646 if (event_filter->GetDictionary(kArgsParam, &args_dict)) |
| 647 new_config.SetArgs(args_dict->CreateDeepCopy()); |
| 648 |
| 649 category_event_filters_.push_back(new_config); |
| 650 } |
| 651 } |
| 652 |
527 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 653 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
528 switch (record_mode_) { | 654 switch (record_mode_) { |
529 case RECORD_UNTIL_FULL: | 655 case RECORD_UNTIL_FULL: |
530 dict.SetString(kRecordModeParam, kRecordUntilFull); | 656 dict.SetString(kRecordModeParam, kRecordUntilFull); |
531 break; | 657 break; |
532 case RECORD_CONTINUOUSLY: | 658 case RECORD_CONTINUOUSLY: |
533 dict.SetString(kRecordModeParam, kRecordContinuously); | 659 dict.SetString(kRecordModeParam, kRecordContinuously); |
534 break; | 660 break; |
535 case RECORD_AS_MUCH_AS_POSSIBLE: | 661 case RECORD_AS_MUCH_AS_POSSIBLE: |
536 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); | 662 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); |
(...skipping 21 matching lines...) Expand all Loading... |
558 dict.SetBoolean(kEnableArgumentFilterParam, false); | 684 dict.SetBoolean(kEnableArgumentFilterParam, false); |
559 | 685 |
560 StringList categories(included_categories_); | 686 StringList categories(included_categories_); |
561 categories.insert(categories.end(), | 687 categories.insert(categories.end(), |
562 disabled_categories_.begin(), | 688 disabled_categories_.begin(), |
563 disabled_categories_.end()); | 689 disabled_categories_.end()); |
564 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 690 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
565 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 691 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
566 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 692 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
567 | 693 |
| 694 if (!category_event_filters_.empty()) { |
| 695 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
| 696 for (const CategoryEventFilterConfig& filter : category_event_filters_) { |
| 697 std::unique_ptr<base::DictionaryValue> filter_dict( |
| 698 new base::DictionaryValue()); |
| 699 filter_dict->SetString(kPredicateParam, filter.predicate_name()); |
| 700 |
| 701 std::unique_ptr<base::ListValue> included_categories_list( |
| 702 new base::ListValue()); |
| 703 for (const std::string& included_category : filter.included_categories()) |
| 704 included_categories_list->AppendString(included_category); |
| 705 |
| 706 filter_dict->Set(kIncludedCategoriesParam, |
| 707 std::move(included_categories_list)); |
| 708 |
| 709 if (!filter.excluded_categories().empty()) { |
| 710 std::unique_ptr<base::ListValue> excluded_categories_list( |
| 711 new base::ListValue()); |
| 712 for (const std::string& excluded_category : |
| 713 filter.excluded_categories()) |
| 714 excluded_categories_list->AppendString(excluded_category); |
| 715 |
| 716 filter_dict->Set(kExcludedCategoriesParam, |
| 717 std::move(excluded_categories_list)); |
| 718 } |
| 719 |
| 720 if (filter.args()) |
| 721 filter_dict->Set(kArgsParam, filter.args()->CreateDeepCopy()); |
| 722 |
| 723 filter_list->Append(std::move(filter_dict)); |
| 724 } |
| 725 dict.Set(kCategoryEventFilterParam, std::move(filter_list)); |
| 726 } |
| 727 |
568 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 728 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
569 std::unique_ptr<base::DictionaryValue> memory_dump_config( | 729 std::unique_ptr<base::DictionaryValue> memory_dump_config( |
570 new base::DictionaryValue()); | 730 new base::DictionaryValue()); |
571 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); | 731 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
572 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { | 732 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { |
573 std::unique_ptr<base::DictionaryValue> trigger_dict( | 733 std::unique_ptr<base::DictionaryValue> trigger_dict( |
574 new base::DictionaryValue()); | 734 new base::DictionaryValue()); |
575 trigger_dict->SetInteger(kPeriodicIntervalParam, | 735 trigger_dict->SetInteger(kPeriodicIntervalParam, |
576 static_cast<int>(config.periodic_interval_ms)); | 736 static_cast<int>(config.periodic_interval_ms)); |
577 trigger_dict->SetString( | 737 trigger_dict->SetString( |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 str.at(0) == ' ' || | 832 str.at(0) == ' ' || |
673 str.at(str.length() - 1) == ' '; | 833 str.at(str.length() - 1) == ' '; |
674 } | 834 } |
675 | 835 |
676 bool TraceConfig::HasIncludedPatterns() const { | 836 bool TraceConfig::HasIncludedPatterns() const { |
677 return !included_categories_.empty(); | 837 return !included_categories_.empty(); |
678 } | 838 } |
679 | 839 |
680 } // namespace trace_event | 840 } // namespace trace_event |
681 } // namespace base | 841 } // namespace base |
OLD | NEW |