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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 const char kHeapProfilerOptions[] = "heap_profiler_options"; | 53 const char kHeapProfilerOptions[] = "heap_profiler_options"; |
54 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; | 54 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; |
55 | 55 |
| 56 // String parameters used to parse category event filters. |
| 57 const char kEventFiltersParam[] = "event_filters"; |
| 58 const char kFilterPredicateParam[] = "filter_predicate"; |
| 59 const char kFilterArgsParam[] = "filter_args"; |
| 60 |
56 // Default configuration of memory dumps. | 61 // Default configuration of memory dumps. |
57 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { | 62 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { |
58 2000, // periodic_interval_ms | 63 2000, // periodic_interval_ms |
59 MemoryDumpLevelOfDetail::DETAILED}; | 64 MemoryDumpLevelOfDetail::DETAILED}; |
60 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { | 65 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { |
61 250, // periodic_interval_ms | 66 250, // periodic_interval_ms |
62 MemoryDumpLevelOfDetail::LIGHT}; | 67 MemoryDumpLevelOfDetail::LIGHT}; |
63 | 68 |
64 class ConvertableTraceConfigToTraceFormat | 69 class ConvertableTraceConfigToTraceFormat |
65 : public base::trace_event::ConvertableToTraceFormat { | 70 : public base::trace_event::ConvertableToTraceFormat { |
(...skipping 24 matching lines...) Expand all Loading... |
90 TraceConfig::MemoryDumpConfig::MemoryDumpConfig( | 95 TraceConfig::MemoryDumpConfig::MemoryDumpConfig( |
91 const MemoryDumpConfig& other) = default; | 96 const MemoryDumpConfig& other) = default; |
92 | 97 |
93 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; | 98 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; |
94 | 99 |
95 void TraceConfig::MemoryDumpConfig::Clear() { | 100 void TraceConfig::MemoryDumpConfig::Clear() { |
96 triggers.clear(); | 101 triggers.clear(); |
97 heap_profiler_options.Clear(); | 102 heap_profiler_options.Clear(); |
98 } | 103 } |
99 | 104 |
| 105 TraceConfig::EventFilterConfig::EventFilterConfig( |
| 106 const std::string& predicate_name) |
| 107 : predicate_name_(predicate_name) {} |
| 108 TraceConfig::EventFilterConfig::~EventFilterConfig() {} |
| 109 |
| 110 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) |
| 111 : predicate_name_(tc.predicate_name_), |
| 112 included_categories_(tc.included_categories_), |
| 113 excluded_categories_(tc.excluded_categories_) { |
| 114 if (tc.args_) |
| 115 args_ = tc.args_->CreateDeepCopy(); |
| 116 } |
| 117 |
| 118 TraceConfig::EventFilterConfig& TraceConfig::EventFilterConfig::operator=( |
| 119 const TraceConfig::EventFilterConfig& rhs) { |
| 120 if (this == &rhs) |
| 121 return *this; |
| 122 |
| 123 predicate_name_ = rhs.predicate_name_; |
| 124 included_categories_ = rhs.included_categories_; |
| 125 excluded_categories_ = rhs.excluded_categories_; |
| 126 if (rhs.args_) |
| 127 args_ = rhs.args_->CreateDeepCopy(); |
| 128 |
| 129 return *this; |
| 130 } |
| 131 |
| 132 void TraceConfig::EventFilterConfig::AddIncludedCategory( |
| 133 const std::string& category) { |
| 134 included_categories_.push_back(category); |
| 135 } |
| 136 |
| 137 void TraceConfig::EventFilterConfig::AddExcludedCategory( |
| 138 const std::string& category) { |
| 139 excluded_categories_.push_back(category); |
| 140 } |
| 141 |
| 142 void TraceConfig::EventFilterConfig::SetArgs( |
| 143 std::unique_ptr<base::DictionaryValue> args) { |
| 144 args_ = std::move(args); |
| 145 } |
| 146 |
| 147 bool TraceConfig::EventFilterConfig::IsCategoryGroupEnabled( |
| 148 const char* category_group_name) const { |
| 149 CStringTokenizer category_group_tokens( |
| 150 category_group_name, category_group_name + strlen(category_group_name), |
| 151 ","); |
| 152 while (category_group_tokens.GetNext()) { |
| 153 std::string category_group_token = category_group_tokens.token(); |
| 154 |
| 155 for (const auto& excluded_category : excluded_categories_) { |
| 156 if (base::MatchPattern(category_group_token.c_str(), |
| 157 excluded_category.c_str())) { |
| 158 return false; |
| 159 } |
| 160 } |
| 161 |
| 162 for (const auto& included_category : included_categories_) { |
| 163 if (base::MatchPattern(category_group_token.c_str(), |
| 164 included_category.c_str())) { |
| 165 return true; |
| 166 } |
| 167 } |
| 168 } |
| 169 |
| 170 return false; |
| 171 } |
| 172 |
100 TraceConfig::TraceConfig() { | 173 TraceConfig::TraceConfig() { |
101 InitializeDefault(); | 174 InitializeDefault(); |
102 } | 175 } |
103 | 176 |
104 TraceConfig::TraceConfig(const std::string& category_filter_string, | 177 TraceConfig::TraceConfig(const std::string& category_filter_string, |
105 const std::string& trace_options_string) { | 178 const std::string& trace_options_string) { |
106 InitializeFromStrings(category_filter_string, trace_options_string); | 179 InitializeFromStrings(category_filter_string, trace_options_string); |
107 } | 180 } |
108 | 181 |
109 TraceConfig::TraceConfig(const std::string& category_filter_string, | 182 TraceConfig::TraceConfig(const std::string& category_filter_string, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 214 |
142 TraceConfig::TraceConfig(const TraceConfig& tc) | 215 TraceConfig::TraceConfig(const TraceConfig& tc) |
143 : record_mode_(tc.record_mode_), | 216 : record_mode_(tc.record_mode_), |
144 enable_sampling_(tc.enable_sampling_), | 217 enable_sampling_(tc.enable_sampling_), |
145 enable_systrace_(tc.enable_systrace_), | 218 enable_systrace_(tc.enable_systrace_), |
146 enable_argument_filter_(tc.enable_argument_filter_), | 219 enable_argument_filter_(tc.enable_argument_filter_), |
147 memory_dump_config_(tc.memory_dump_config_), | 220 memory_dump_config_(tc.memory_dump_config_), |
148 included_categories_(tc.included_categories_), | 221 included_categories_(tc.included_categories_), |
149 disabled_categories_(tc.disabled_categories_), | 222 disabled_categories_(tc.disabled_categories_), |
150 excluded_categories_(tc.excluded_categories_), | 223 excluded_categories_(tc.excluded_categories_), |
151 synthetic_delays_(tc.synthetic_delays_) {} | 224 synthetic_delays_(tc.synthetic_delays_), |
| 225 event_filters_(tc.event_filters_) {} |
152 | 226 |
153 TraceConfig::~TraceConfig() { | 227 TraceConfig::~TraceConfig() { |
154 } | 228 } |
155 | 229 |
156 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { | 230 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
157 if (this == &rhs) | 231 if (this == &rhs) |
158 return *this; | 232 return *this; |
159 | 233 |
160 record_mode_ = rhs.record_mode_; | 234 record_mode_ = rhs.record_mode_; |
161 enable_sampling_ = rhs.enable_sampling_; | 235 enable_sampling_ = rhs.enable_sampling_; |
162 enable_systrace_ = rhs.enable_systrace_; | 236 enable_systrace_ = rhs.enable_systrace_; |
163 enable_argument_filter_ = rhs.enable_argument_filter_; | 237 enable_argument_filter_ = rhs.enable_argument_filter_; |
164 memory_dump_config_ = rhs.memory_dump_config_; | 238 memory_dump_config_ = rhs.memory_dump_config_; |
165 included_categories_ = rhs.included_categories_; | 239 included_categories_ = rhs.included_categories_; |
166 disabled_categories_ = rhs.disabled_categories_; | 240 disabled_categories_ = rhs.disabled_categories_; |
167 excluded_categories_ = rhs.excluded_categories_; | 241 excluded_categories_ = rhs.excluded_categories_; |
168 synthetic_delays_ = rhs.synthetic_delays_; | 242 synthetic_delays_ = rhs.synthetic_delays_; |
| 243 event_filters_ = rhs.event_filters_; |
169 return *this; | 244 return *this; |
170 } | 245 } |
171 | 246 |
172 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { | 247 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { |
173 return synthetic_delays_; | 248 return synthetic_delays_; |
174 } | 249 } |
175 | 250 |
176 std::string TraceConfig::ToString() const { | 251 std::string TraceConfig::ToString() const { |
177 base::DictionaryValue dict; | 252 base::DictionaryValue dict; |
178 ToDict(dict); | 253 ToDict(dict); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void TraceConfig::Clear() { | 372 void TraceConfig::Clear() { |
298 record_mode_ = RECORD_UNTIL_FULL; | 373 record_mode_ = RECORD_UNTIL_FULL; |
299 enable_sampling_ = false; | 374 enable_sampling_ = false; |
300 enable_systrace_ = false; | 375 enable_systrace_ = false; |
301 enable_argument_filter_ = false; | 376 enable_argument_filter_ = false; |
302 included_categories_.clear(); | 377 included_categories_.clear(); |
303 disabled_categories_.clear(); | 378 disabled_categories_.clear(); |
304 excluded_categories_.clear(); | 379 excluded_categories_.clear(); |
305 synthetic_delays_.clear(); | 380 synthetic_delays_.clear(); |
306 memory_dump_config_.Clear(); | 381 memory_dump_config_.Clear(); |
| 382 event_filters_.clear(); |
307 } | 383 } |
308 | 384 |
309 void TraceConfig::InitializeDefault() { | 385 void TraceConfig::InitializeDefault() { |
310 record_mode_ = RECORD_UNTIL_FULL; | 386 record_mode_ = RECORD_UNTIL_FULL; |
311 enable_sampling_ = false; | 387 enable_sampling_ = false; |
312 enable_systrace_ = false; | 388 enable_systrace_ = false; |
313 enable_argument_filter_ = false; | 389 enable_argument_filter_ = false; |
314 excluded_categories_.push_back("*Debug"); | 390 excluded_categories_.push_back("*Debug"); |
315 excluded_categories_.push_back("*Test"); | 391 excluded_categories_.push_back("*Test"); |
316 } | 392 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 434 |
359 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 435 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
360 // If dump triggers not set, the client is using the legacy with just | 436 // If dump triggers not set, the client is using the legacy with just |
361 // category enabled. So, use the default periodic dump config. | 437 // category enabled. So, use the default periodic dump config. |
362 const base::DictionaryValue* memory_dump_config = nullptr; | 438 const base::DictionaryValue* memory_dump_config = nullptr; |
363 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 439 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
364 SetMemoryDumpConfig(*memory_dump_config); | 440 SetMemoryDumpConfig(*memory_dump_config); |
365 else | 441 else |
366 SetDefaultMemoryDumpConfig(); | 442 SetDefaultMemoryDumpConfig(); |
367 } | 443 } |
| 444 |
| 445 const base::ListValue* category_event_filters = nullptr; |
| 446 if (dict.GetList(kEventFiltersParam, &category_event_filters)) |
| 447 SetEventFilters(*category_event_filters); |
368 } | 448 } |
369 | 449 |
370 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { | 450 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
371 std::unique_ptr<Value> value(JSONReader::Read(config_string)); | 451 std::unique_ptr<Value> value(JSONReader::Read(config_string)); |
372 if (!value) | 452 if (!value) |
373 return InitializeDefault(); | 453 return InitializeDefault(); |
374 | 454 |
375 const DictionaryValue* dict = nullptr; | 455 const DictionaryValue* dict = nullptr; |
376 bool is_dict = value->GetAsDictionary(&dict); | 456 bool is_dict = value->GetAsDictionary(&dict); |
377 | 457 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 634 } |
555 } | 635 } |
556 } | 636 } |
557 | 637 |
558 void TraceConfig::SetDefaultMemoryDumpConfig() { | 638 void TraceConfig::SetDefaultMemoryDumpConfig() { |
559 memory_dump_config_.Clear(); | 639 memory_dump_config_.Clear(); |
560 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); | 640 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
561 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); | 641 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
562 } | 642 } |
563 | 643 |
| 644 void TraceConfig::SetEventFilters( |
| 645 const base::ListValue& category_event_filters) { |
| 646 event_filters_.clear(); |
| 647 |
| 648 for (size_t i = 0; i < category_event_filters.GetSize(); ++i) { |
| 649 const base::DictionaryValue* event_filter = nullptr; |
| 650 if (!category_event_filters.GetDictionary(i, &event_filter)) |
| 651 continue; |
| 652 |
| 653 std::string predicate_name; |
| 654 if (!event_filter->GetString(kFilterPredicateParam, &predicate_name)) { |
| 655 LOG(ERROR) << "Invalid predicate name in category event filter."; |
| 656 continue; |
| 657 } |
| 658 |
| 659 EventFilterConfig new_config(predicate_name); |
| 660 const base::ListValue* included_list = nullptr; |
| 661 if (!event_filter->GetList(kIncludedCategoriesParam, &included_list)) { |
| 662 LOG(ERROR) << "Missing included_categories in category event filter."; |
| 663 continue; |
| 664 } |
| 665 |
| 666 for (size_t i = 0; i < included_list->GetSize(); ++i) { |
| 667 std::string category; |
| 668 if (included_list->GetString(i, &category)) |
| 669 new_config.AddIncludedCategory(category); |
| 670 } |
| 671 |
| 672 const base::ListValue* excluded_list = nullptr; |
| 673 if (event_filter->GetList(kExcludedCategoriesParam, &excluded_list)) { |
| 674 for (size_t i = 0; i < excluded_list->GetSize(); ++i) { |
| 675 std::string category; |
| 676 if (excluded_list->GetString(i, &category)) |
| 677 new_config.AddExcludedCategory(category); |
| 678 } |
| 679 } |
| 680 |
| 681 const base::DictionaryValue* args_dict = nullptr; |
| 682 if (event_filter->GetDictionary(kFilterArgsParam, &args_dict)) |
| 683 new_config.SetArgs(args_dict->CreateDeepCopy()); |
| 684 |
| 685 event_filters_.push_back(new_config); |
| 686 } |
| 687 } |
| 688 |
564 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 689 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
565 switch (record_mode_) { | 690 switch (record_mode_) { |
566 case RECORD_UNTIL_FULL: | 691 case RECORD_UNTIL_FULL: |
567 dict.SetString(kRecordModeParam, kRecordUntilFull); | 692 dict.SetString(kRecordModeParam, kRecordUntilFull); |
568 break; | 693 break; |
569 case RECORD_CONTINUOUSLY: | 694 case RECORD_CONTINUOUSLY: |
570 dict.SetString(kRecordModeParam, kRecordContinuously); | 695 dict.SetString(kRecordModeParam, kRecordContinuously); |
571 break; | 696 break; |
572 case RECORD_AS_MUCH_AS_POSSIBLE: | 697 case RECORD_AS_MUCH_AS_POSSIBLE: |
573 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); | 698 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); |
(...skipping 21 matching lines...) Expand all Loading... |
595 dict.SetBoolean(kEnableArgumentFilterParam, false); | 720 dict.SetBoolean(kEnableArgumentFilterParam, false); |
596 | 721 |
597 StringList categories(included_categories_); | 722 StringList categories(included_categories_); |
598 categories.insert(categories.end(), | 723 categories.insert(categories.end(), |
599 disabled_categories_.begin(), | 724 disabled_categories_.begin(), |
600 disabled_categories_.end()); | 725 disabled_categories_.end()); |
601 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 726 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
602 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 727 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
603 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 728 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
604 | 729 |
| 730 if (!event_filters_.empty()) { |
| 731 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
| 732 for (const EventFilterConfig& filter : event_filters_) { |
| 733 std::unique_ptr<base::DictionaryValue> filter_dict( |
| 734 new base::DictionaryValue()); |
| 735 filter_dict->SetString(kFilterPredicateParam, filter.predicate_name()); |
| 736 |
| 737 std::unique_ptr<base::ListValue> included_categories_list( |
| 738 new base::ListValue()); |
| 739 for (const std::string& included_category : filter.included_categories()) |
| 740 included_categories_list->AppendString(included_category); |
| 741 |
| 742 filter_dict->Set(kIncludedCategoriesParam, |
| 743 std::move(included_categories_list)); |
| 744 |
| 745 if (!filter.excluded_categories().empty()) { |
| 746 std::unique_ptr<base::ListValue> excluded_categories_list( |
| 747 new base::ListValue()); |
| 748 for (const std::string& excluded_category : |
| 749 filter.excluded_categories()) |
| 750 excluded_categories_list->AppendString(excluded_category); |
| 751 |
| 752 filter_dict->Set(kExcludedCategoriesParam, |
| 753 std::move(excluded_categories_list)); |
| 754 } |
| 755 |
| 756 if (filter.filter_args()) |
| 757 filter_dict->Set(kFilterArgsParam, |
| 758 filter.filter_args()->CreateDeepCopy()); |
| 759 |
| 760 filter_list->Append(std::move(filter_dict)); |
| 761 } |
| 762 dict.Set(kEventFiltersParam, std::move(filter_list)); |
| 763 } |
| 764 |
605 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 765 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
606 std::unique_ptr<base::DictionaryValue> memory_dump_config( | 766 std::unique_ptr<base::DictionaryValue> memory_dump_config( |
607 new base::DictionaryValue()); | 767 new base::DictionaryValue()); |
608 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); | 768 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
609 for (const MemoryDumpConfig::Trigger& config | 769 for (const MemoryDumpConfig::Trigger& config |
610 : memory_dump_config_.triggers) { | 770 : memory_dump_config_.triggers) { |
611 std::unique_ptr<base::DictionaryValue> trigger_dict( | 771 std::unique_ptr<base::DictionaryValue> trigger_dict( |
612 new base::DictionaryValue()); | 772 new base::DictionaryValue()); |
613 trigger_dict->SetInteger(kPeriodicIntervalParam, | 773 trigger_dict->SetInteger(kPeriodicIntervalParam, |
614 static_cast<int>(config.periodic_interval_ms)); | 774 static_cast<int>(config.periodic_interval_ms)); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 str.at(0) == ' ' || | 881 str.at(0) == ' ' || |
722 str.at(str.length() - 1) == ' '; | 882 str.at(str.length() - 1) == ' '; |
723 } | 883 } |
724 | 884 |
725 bool TraceConfig::HasIncludedPatterns() const { | 885 bool TraceConfig::HasIncludedPatterns() const { |
726 return !included_categories_.empty(); | 886 return !included_categories_.empty(); |
727 } | 887 } |
728 | 888 |
729 } // namespace trace_event | 889 } // namespace trace_event |
730 } // namespace base | 890 } // namespace base |
OLD | NEW |