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