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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // String parameters that is used to parse memory dump config in trace config | 48 // String parameters that is used to parse memory dump config in trace config |
49 // string. | 49 // string. |
50 const char kMemoryDumpConfigParam[] = "memory_dump_config"; | 50 const char kMemoryDumpConfigParam[] = "memory_dump_config"; |
51 const char kAllowedDumpModesParam[] = "allowed_dump_modes"; | 51 const char kAllowedDumpModesParam[] = "allowed_dump_modes"; |
52 const char kTriggersParam[] = "triggers"; | 52 const char kTriggersParam[] = "triggers"; |
53 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; | 53 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
54 const char kModeParam[] = "mode"; | 54 const char kModeParam[] = "mode"; |
55 const char kHeapProfilerOptions[] = "heap_profiler_options"; | 55 const char kHeapProfilerOptions[] = "heap_profiler_options"; |
56 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; | 56 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; |
57 | 57 |
| 58 // String parameters used to parse category event filters. |
| 59 const char kEventFiltersParam[] = "event_filters"; |
| 60 const char kFilterPredicateParam[] = "filter_predicate"; |
| 61 const char kFilterArgsParam[] = "filter_args"; |
| 62 |
58 // Default configuration of memory dumps. | 63 // Default configuration of memory dumps. |
59 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { | 64 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { |
60 2000, // periodic_interval_ms | 65 2000, // periodic_interval_ms |
61 MemoryDumpLevelOfDetail::DETAILED}; | 66 MemoryDumpLevelOfDetail::DETAILED}; |
62 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { | 67 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { |
63 250, // periodic_interval_ms | 68 250, // periodic_interval_ms |
64 MemoryDumpLevelOfDetail::LIGHT}; | 69 MemoryDumpLevelOfDetail::LIGHT}; |
65 | 70 |
66 class ConvertableTraceConfigToTraceFormat | 71 class ConvertableTraceConfigToTraceFormat |
67 : public base::trace_event::ConvertableToTraceFormat { | 72 : public base::trace_event::ConvertableToTraceFormat { |
68 public: | 73 public: |
69 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) | 74 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) |
70 : trace_config_(trace_config) {} | 75 : trace_config_(trace_config) {} |
| 76 |
71 ~ConvertableTraceConfigToTraceFormat() override {} | 77 ~ConvertableTraceConfigToTraceFormat() override {} |
72 | 78 |
73 void AppendAsTraceFormat(std::string* out) const override { | 79 void AppendAsTraceFormat(std::string* out) const override { |
74 out->append(trace_config_.ToString()); | 80 out->append(trace_config_.ToString()); |
75 } | 81 } |
76 | 82 |
77 private: | 83 private: |
78 const TraceConfig trace_config_; | 84 const TraceConfig trace_config_; |
79 }; | 85 }; |
80 | 86 |
(...skipping 27 matching lines...) Expand all Loading... |
108 const MemoryDumpConfig& other) = default; | 114 const MemoryDumpConfig& other) = default; |
109 | 115 |
110 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} | 116 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {} |
111 | 117 |
112 void TraceConfig::MemoryDumpConfig::Clear() { | 118 void TraceConfig::MemoryDumpConfig::Clear() { |
113 allowed_dump_modes.clear(); | 119 allowed_dump_modes.clear(); |
114 triggers.clear(); | 120 triggers.clear(); |
115 heap_profiler_options.Clear(); | 121 heap_profiler_options.Clear(); |
116 } | 122 } |
117 | 123 |
| 124 TraceConfig::EventFilterConfig::EventFilterConfig( |
| 125 const std::string& predicate_name) |
| 126 : predicate_name_(predicate_name) {} |
| 127 |
| 128 TraceConfig::EventFilterConfig::~EventFilterConfig() {} |
| 129 |
| 130 TraceConfig::EventFilterConfig::EventFilterConfig(const EventFilterConfig& tc) { |
| 131 *this = tc; |
| 132 } |
| 133 |
| 134 TraceConfig::EventFilterConfig& TraceConfig::EventFilterConfig::operator=( |
| 135 const TraceConfig::EventFilterConfig& rhs) { |
| 136 if (this == &rhs) |
| 137 return *this; |
| 138 |
| 139 predicate_name_ = rhs.predicate_name_; |
| 140 included_categories_ = rhs.included_categories_; |
| 141 excluded_categories_ = rhs.excluded_categories_; |
| 142 if (rhs.args_) |
| 143 args_ = rhs.args_->CreateDeepCopy(); |
| 144 |
| 145 return *this; |
| 146 } |
| 147 |
| 148 void TraceConfig::EventFilterConfig::AddIncludedCategory( |
| 149 const std::string& category) { |
| 150 included_categories_.push_back(category); |
| 151 } |
| 152 |
| 153 void TraceConfig::EventFilterConfig::AddExcludedCategory( |
| 154 const std::string& category) { |
| 155 excluded_categories_.push_back(category); |
| 156 } |
| 157 |
| 158 void TraceConfig::EventFilterConfig::SetArgs( |
| 159 std::unique_ptr<base::DictionaryValue> args) { |
| 160 args_ = std::move(args); |
| 161 } |
| 162 |
| 163 bool TraceConfig::EventFilterConfig::IsCategoryGroupEnabled( |
| 164 const char* category_group_name) const { |
| 165 CStringTokenizer category_group_tokens( |
| 166 category_group_name, category_group_name + strlen(category_group_name), |
| 167 ","); |
| 168 while (category_group_tokens.GetNext()) { |
| 169 std::string category_group_token = category_group_tokens.token(); |
| 170 |
| 171 for (const auto& excluded_category : excluded_categories_) { |
| 172 if (base::MatchPattern(category_group_token, excluded_category)) { |
| 173 return false; |
| 174 } |
| 175 } |
| 176 |
| 177 for (const auto& included_category : included_categories_) { |
| 178 if (base::MatchPattern(category_group_token, included_category)) { |
| 179 return true; |
| 180 } |
| 181 } |
| 182 } |
| 183 |
| 184 return false; |
| 185 } |
| 186 |
118 TraceConfig::TraceConfig() { | 187 TraceConfig::TraceConfig() { |
119 InitializeDefault(); | 188 InitializeDefault(); |
120 } | 189 } |
121 | 190 |
122 TraceConfig::TraceConfig(StringPiece category_filter_string, | 191 TraceConfig::TraceConfig(StringPiece category_filter_string, |
123 StringPiece trace_options_string) { | 192 StringPiece trace_options_string) { |
124 InitializeFromStrings(category_filter_string, trace_options_string); | 193 InitializeFromStrings(category_filter_string, trace_options_string); |
125 } | 194 } |
126 | 195 |
127 TraceConfig::TraceConfig(StringPiece category_filter_string, | 196 TraceConfig::TraceConfig(StringPiece category_filter_string, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 228 |
160 TraceConfig::TraceConfig(const TraceConfig& tc) | 229 TraceConfig::TraceConfig(const TraceConfig& tc) |
161 : record_mode_(tc.record_mode_), | 230 : record_mode_(tc.record_mode_), |
162 enable_sampling_(tc.enable_sampling_), | 231 enable_sampling_(tc.enable_sampling_), |
163 enable_systrace_(tc.enable_systrace_), | 232 enable_systrace_(tc.enable_systrace_), |
164 enable_argument_filter_(tc.enable_argument_filter_), | 233 enable_argument_filter_(tc.enable_argument_filter_), |
165 memory_dump_config_(tc.memory_dump_config_), | 234 memory_dump_config_(tc.memory_dump_config_), |
166 included_categories_(tc.included_categories_), | 235 included_categories_(tc.included_categories_), |
167 disabled_categories_(tc.disabled_categories_), | 236 disabled_categories_(tc.disabled_categories_), |
168 excluded_categories_(tc.excluded_categories_), | 237 excluded_categories_(tc.excluded_categories_), |
169 synthetic_delays_(tc.synthetic_delays_) {} | 238 synthetic_delays_(tc.synthetic_delays_), |
| 239 event_filters_(tc.event_filters_) {} |
170 | 240 |
171 TraceConfig::~TraceConfig() { | 241 TraceConfig::~TraceConfig() { |
172 } | 242 } |
173 | 243 |
174 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { | 244 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
175 if (this == &rhs) | 245 if (this == &rhs) |
176 return *this; | 246 return *this; |
177 | 247 |
178 record_mode_ = rhs.record_mode_; | 248 record_mode_ = rhs.record_mode_; |
179 enable_sampling_ = rhs.enable_sampling_; | 249 enable_sampling_ = rhs.enable_sampling_; |
180 enable_systrace_ = rhs.enable_systrace_; | 250 enable_systrace_ = rhs.enable_systrace_; |
181 enable_argument_filter_ = rhs.enable_argument_filter_; | 251 enable_argument_filter_ = rhs.enable_argument_filter_; |
182 memory_dump_config_ = rhs.memory_dump_config_; | 252 memory_dump_config_ = rhs.memory_dump_config_; |
183 included_categories_ = rhs.included_categories_; | 253 included_categories_ = rhs.included_categories_; |
184 disabled_categories_ = rhs.disabled_categories_; | 254 disabled_categories_ = rhs.disabled_categories_; |
185 excluded_categories_ = rhs.excluded_categories_; | 255 excluded_categories_ = rhs.excluded_categories_; |
186 synthetic_delays_ = rhs.synthetic_delays_; | 256 synthetic_delays_ = rhs.synthetic_delays_; |
| 257 event_filters_ = rhs.event_filters_; |
187 return *this; | 258 return *this; |
188 } | 259 } |
189 | 260 |
190 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { | 261 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { |
191 return synthetic_delays_; | 262 return synthetic_delays_; |
192 } | 263 } |
193 | 264 |
194 std::string TraceConfig::ToString() const { | 265 std::string TraceConfig::ToString() const { |
195 std::unique_ptr<DictionaryValue> dict = ToDict(); | 266 std::unique_ptr<DictionaryValue> dict = ToDict(); |
196 std::string json; | 267 std::string json; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 void TraceConfig::Clear() { | 378 void TraceConfig::Clear() { |
308 record_mode_ = RECORD_UNTIL_FULL; | 379 record_mode_ = RECORD_UNTIL_FULL; |
309 enable_sampling_ = false; | 380 enable_sampling_ = false; |
310 enable_systrace_ = false; | 381 enable_systrace_ = false; |
311 enable_argument_filter_ = false; | 382 enable_argument_filter_ = false; |
312 included_categories_.clear(); | 383 included_categories_.clear(); |
313 disabled_categories_.clear(); | 384 disabled_categories_.clear(); |
314 excluded_categories_.clear(); | 385 excluded_categories_.clear(); |
315 synthetic_delays_.clear(); | 386 synthetic_delays_.clear(); |
316 memory_dump_config_.Clear(); | 387 memory_dump_config_.Clear(); |
| 388 event_filters_.clear(); |
317 } | 389 } |
318 | 390 |
319 void TraceConfig::InitializeDefault() { | 391 void TraceConfig::InitializeDefault() { |
320 record_mode_ = RECORD_UNTIL_FULL; | 392 record_mode_ = RECORD_UNTIL_FULL; |
321 enable_sampling_ = false; | 393 enable_sampling_ = false; |
322 enable_systrace_ = false; | 394 enable_systrace_ = false; |
323 enable_argument_filter_ = false; | 395 enable_argument_filter_ = false; |
324 } | 396 } |
325 | 397 |
326 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { | 398 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { |
(...skipping 27 matching lines...) Expand all Loading... |
354 | 426 |
355 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 427 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
356 // If dump triggers not set, the client is using the legacy with just | 428 // If dump triggers not set, the client is using the legacy with just |
357 // category enabled. So, use the default periodic dump config. | 429 // category enabled. So, use the default periodic dump config. |
358 const DictionaryValue* memory_dump_config = nullptr; | 430 const DictionaryValue* memory_dump_config = nullptr; |
359 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 431 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
360 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); | 432 SetMemoryDumpConfigFromConfigDict(*memory_dump_config); |
361 else | 433 else |
362 SetDefaultMemoryDumpConfig(); | 434 SetDefaultMemoryDumpConfig(); |
363 } | 435 } |
| 436 |
| 437 const base::ListValue* category_event_filters = nullptr; |
| 438 if (dict.GetList(kEventFiltersParam, &category_event_filters)) |
| 439 SetEventFilters(*category_event_filters); |
364 } | 440 } |
365 | 441 |
366 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { | 442 void TraceConfig::InitializeFromConfigString(StringPiece config_string) { |
367 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); | 443 auto dict = DictionaryValue::From(JSONReader::Read(config_string)); |
368 if (dict) | 444 if (dict) |
369 InitializeFromConfigDict(*dict); | 445 InitializeFromConfigDict(*dict); |
370 else | 446 else |
371 InitializeDefault(); | 447 InitializeDefault(); |
372 } | 448 } |
373 | 449 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 624 } |
549 } | 625 } |
550 | 626 |
551 void TraceConfig::SetDefaultMemoryDumpConfig() { | 627 void TraceConfig::SetDefaultMemoryDumpConfig() { |
552 memory_dump_config_.Clear(); | 628 memory_dump_config_.Clear(); |
553 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); | 629 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
554 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); | 630 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
555 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); | 631 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes(); |
556 } | 632 } |
557 | 633 |
| 634 void TraceConfig::SetEventFilters( |
| 635 const base::ListValue& category_event_filters) { |
| 636 event_filters_.clear(); |
| 637 |
| 638 for (size_t event_filter_index = 0; |
| 639 event_filter_index < category_event_filters.GetSize(); |
| 640 ++event_filter_index) { |
| 641 const base::DictionaryValue* event_filter = nullptr; |
| 642 if (!category_event_filters.GetDictionary(event_filter_index, |
| 643 &event_filter)) |
| 644 continue; |
| 645 |
| 646 std::string predicate_name; |
| 647 CHECK(event_filter->GetString(kFilterPredicateParam, &predicate_name)) |
| 648 << "Invalid predicate name in category event filter."; |
| 649 |
| 650 EventFilterConfig new_config(predicate_name); |
| 651 const base::ListValue* included_list = nullptr; |
| 652 CHECK(event_filter->GetList(kIncludedCategoriesParam, &included_list)) |
| 653 << "Missing included_categories in category event filter."; |
| 654 |
| 655 for (size_t i = 0; i < included_list->GetSize(); ++i) { |
| 656 std::string category; |
| 657 if (included_list->GetString(i, &category)) |
| 658 new_config.AddIncludedCategory(category); |
| 659 } |
| 660 |
| 661 const base::ListValue* excluded_list = nullptr; |
| 662 if (event_filter->GetList(kExcludedCategoriesParam, &excluded_list)) { |
| 663 for (size_t i = 0; i < excluded_list->GetSize(); ++i) { |
| 664 std::string category; |
| 665 if (excluded_list->GetString(i, &category)) |
| 666 new_config.AddExcludedCategory(category); |
| 667 } |
| 668 } |
| 669 |
| 670 const base::DictionaryValue* args_dict = nullptr; |
| 671 if (event_filter->GetDictionary(kFilterArgsParam, &args_dict)) |
| 672 new_config.SetArgs(args_dict->CreateDeepCopy()); |
| 673 |
| 674 event_filters_.push_back(new_config); |
| 675 } |
| 676 } |
| 677 |
558 std::unique_ptr<DictionaryValue> TraceConfig::ToDict() const { | 678 std::unique_ptr<DictionaryValue> TraceConfig::ToDict() const { |
559 auto dict = MakeUnique<DictionaryValue>(); | 679 auto dict = MakeUnique<DictionaryValue>(); |
560 switch (record_mode_) { | 680 switch (record_mode_) { |
561 case RECORD_UNTIL_FULL: | 681 case RECORD_UNTIL_FULL: |
562 dict->SetString(kRecordModeParam, kRecordUntilFull); | 682 dict->SetString(kRecordModeParam, kRecordUntilFull); |
563 break; | 683 break; |
564 case RECORD_CONTINUOUSLY: | 684 case RECORD_CONTINUOUSLY: |
565 dict->SetString(kRecordModeParam, kRecordContinuously); | 685 dict->SetString(kRecordModeParam, kRecordContinuously); |
566 break; | 686 break; |
567 case RECORD_AS_MUCH_AS_POSSIBLE: | 687 case RECORD_AS_MUCH_AS_POSSIBLE: |
(...skipping 11 matching lines...) Expand all Loading... |
579 dict->SetBoolean(kEnableArgumentFilterParam, enable_argument_filter_); | 699 dict->SetBoolean(kEnableArgumentFilterParam, enable_argument_filter_); |
580 | 700 |
581 StringList categories(included_categories_); | 701 StringList categories(included_categories_); |
582 categories.insert(categories.end(), | 702 categories.insert(categories.end(), |
583 disabled_categories_.begin(), | 703 disabled_categories_.begin(), |
584 disabled_categories_.end()); | 704 disabled_categories_.end()); |
585 AddCategoryToDict(dict.get(), kIncludedCategoriesParam, categories); | 705 AddCategoryToDict(dict.get(), kIncludedCategoriesParam, categories); |
586 AddCategoryToDict(dict.get(), kExcludedCategoriesParam, excluded_categories_); | 706 AddCategoryToDict(dict.get(), kExcludedCategoriesParam, excluded_categories_); |
587 AddCategoryToDict(dict.get(), kSyntheticDelaysParam, synthetic_delays_); | 707 AddCategoryToDict(dict.get(), kSyntheticDelaysParam, synthetic_delays_); |
588 | 708 |
| 709 if (!event_filters_.empty()) { |
| 710 std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
| 711 for (const EventFilterConfig& filter : event_filters_) { |
| 712 std::unique_ptr<base::DictionaryValue> filter_dict( |
| 713 new base::DictionaryValue()); |
| 714 filter_dict->SetString(kFilterPredicateParam, filter.predicate_name()); |
| 715 |
| 716 std::unique_ptr<base::ListValue> included_categories_list( |
| 717 new base::ListValue()); |
| 718 for (const std::string& included_category : filter.included_categories()) |
| 719 included_categories_list->AppendString(included_category); |
| 720 |
| 721 filter_dict->Set(kIncludedCategoriesParam, |
| 722 std::move(included_categories_list)); |
| 723 |
| 724 if (!filter.excluded_categories().empty()) { |
| 725 std::unique_ptr<base::ListValue> excluded_categories_list( |
| 726 new base::ListValue()); |
| 727 for (const std::string& excluded_category : |
| 728 filter.excluded_categories()) |
| 729 excluded_categories_list->AppendString(excluded_category); |
| 730 |
| 731 filter_dict->Set(kExcludedCategoriesParam, |
| 732 std::move(excluded_categories_list)); |
| 733 } |
| 734 |
| 735 if (filter.filter_args()) |
| 736 filter_dict->Set(kFilterArgsParam, |
| 737 filter.filter_args()->CreateDeepCopy()); |
| 738 |
| 739 filter_list->Append(std::move(filter_dict)); |
| 740 } |
| 741 dict->Set(kEventFiltersParam, std::move(filter_list)); |
| 742 } |
| 743 |
589 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 744 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
590 auto allowed_modes = MakeUnique<ListValue>(); | 745 auto allowed_modes = MakeUnique<ListValue>(); |
591 for (auto dump_mode : memory_dump_config_.allowed_dump_modes) | 746 for (auto dump_mode : memory_dump_config_.allowed_dump_modes) |
592 allowed_modes->AppendString(MemoryDumpLevelOfDetailToString(dump_mode)); | 747 allowed_modes->AppendString(MemoryDumpLevelOfDetailToString(dump_mode)); |
593 | 748 |
594 auto memory_dump_config = MakeUnique<DictionaryValue>(); | 749 auto memory_dump_config = MakeUnique<DictionaryValue>(); |
595 memory_dump_config->Set(kAllowedDumpModesParam, std::move(allowed_modes)); | 750 memory_dump_config->Set(kAllowedDumpModesParam, std::move(allowed_modes)); |
596 | 751 |
597 auto triggers_list = MakeUnique<ListValue>(); | 752 auto triggers_list = MakeUnique<ListValue>(); |
598 for (const auto& config : memory_dump_config_.triggers) { | 753 for (const auto& config : memory_dump_config_.triggers) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 StringPiece str) { | 852 StringPiece str) { |
698 return str.empty() || str.front() == ' ' || str.back() == ' '; | 853 return str.empty() || str.front() == ' ' || str.back() == ' '; |
699 } | 854 } |
700 | 855 |
701 bool TraceConfig::HasIncludedPatterns() const { | 856 bool TraceConfig::HasIncludedPatterns() const { |
702 return !included_categories_.empty(); | 857 return !included_categories_.empty(); |
703 } | 858 } |
704 | 859 |
705 } // namespace trace_event | 860 } // namespace trace_event |
706 } // namespace base | 861 } // namespace base |
OLD | NEW |