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 TraceConfig::CategoryEventFilterConfig::~CategoryEventFilterConfig() {} |
| 85 |
| 86 TraceConfig::CategoryEventFilterConfig::CategoryEventFilterConfig( |
| 87 const CategoryEventFilterConfig& tc) |
| 88 : predicate_name(tc.predicate_name), |
| 89 included_categories(tc.included_categories), |
| 90 excluded_categories(tc.excluded_categories) { |
| 91 if (tc.args) |
| 92 args = tc.args->CreateDeepCopy(); |
| 93 } |
| 94 |
| 95 TraceConfig::CategoryEventFilterConfig& TraceConfig::CategoryEventFilterConfig:: |
| 96 operator=(const TraceConfig::CategoryEventFilterConfig& rhs) { |
| 97 if (this == &rhs) |
| 98 return *this; |
| 99 |
| 100 predicate_name = rhs.predicate_name; |
| 101 included_categories = rhs.included_categories; |
| 102 excluded_categories = rhs.excluded_categories; |
| 103 if (rhs.args) |
| 104 args = rhs.args->CreateDeepCopy(); |
| 105 |
| 106 return *this; |
| 107 } |
| 108 |
| 109 bool TraceConfig::CategoryEventFilterConfig::IsCategoryGroupEnabled( |
| 110 const char* category_group_name) const { |
| 111 CStringTokenizer category_group_tokens( |
| 112 category_group_name, category_group_name + strlen(category_group_name), |
| 113 ","); |
| 114 while (category_group_tokens.GetNext()) { |
| 115 std::string category_group_token = category_group_tokens.token(); |
| 116 |
| 117 for (const auto& excluded_category : excluded_categories) { |
| 118 if (base::MatchPattern(category_group_token.c_str(), |
| 119 excluded_category.c_str())) { |
| 120 return false; |
| 121 } |
| 122 } |
| 123 |
| 124 for (const auto& included_category : included_categories) { |
| 125 if (base::MatchPattern(category_group_token.c_str(), |
| 126 included_category.c_str())) { |
| 127 return true; |
| 128 } |
| 129 } |
| 130 } |
| 131 |
| 132 return false; |
| 133 } |
| 134 |
78 TraceConfig::TraceConfig() { | 135 TraceConfig::TraceConfig() { |
79 InitializeDefault(); | 136 InitializeDefault(); |
80 } | 137 } |
81 | 138 |
82 TraceConfig::TraceConfig(const std::string& category_filter_string, | 139 TraceConfig::TraceConfig(const std::string& category_filter_string, |
83 const std::string& trace_options_string) { | 140 const std::string& trace_options_string) { |
84 InitializeFromStrings(category_filter_string, trace_options_string); | 141 InitializeFromStrings(category_filter_string, trace_options_string); |
85 } | 142 } |
86 | 143 |
87 TraceConfig::TraceConfig(const std::string& category_filter_string, | 144 TraceConfig::TraceConfig(const std::string& category_filter_string, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 176 |
120 TraceConfig::TraceConfig(const TraceConfig& tc) | 177 TraceConfig::TraceConfig(const TraceConfig& tc) |
121 : record_mode_(tc.record_mode_), | 178 : record_mode_(tc.record_mode_), |
122 enable_sampling_(tc.enable_sampling_), | 179 enable_sampling_(tc.enable_sampling_), |
123 enable_systrace_(tc.enable_systrace_), | 180 enable_systrace_(tc.enable_systrace_), |
124 enable_argument_filter_(tc.enable_argument_filter_), | 181 enable_argument_filter_(tc.enable_argument_filter_), |
125 memory_dump_config_(tc.memory_dump_config_), | 182 memory_dump_config_(tc.memory_dump_config_), |
126 included_categories_(tc.included_categories_), | 183 included_categories_(tc.included_categories_), |
127 disabled_categories_(tc.disabled_categories_), | 184 disabled_categories_(tc.disabled_categories_), |
128 excluded_categories_(tc.excluded_categories_), | 185 excluded_categories_(tc.excluded_categories_), |
129 synthetic_delays_(tc.synthetic_delays_) {} | 186 synthetic_delays_(tc.synthetic_delays_), |
| 187 category_event_filters_(tc.category_event_filters_) {} |
130 | 188 |
131 TraceConfig::~TraceConfig() { | 189 TraceConfig::~TraceConfig() { |
132 } | 190 } |
133 | 191 |
134 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { | 192 TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
135 if (this == &rhs) | 193 if (this == &rhs) |
136 return *this; | 194 return *this; |
137 | 195 |
138 record_mode_ = rhs.record_mode_; | 196 record_mode_ = rhs.record_mode_; |
139 enable_sampling_ = rhs.enable_sampling_; | 197 enable_sampling_ = rhs.enable_sampling_; |
140 enable_systrace_ = rhs.enable_systrace_; | 198 enable_systrace_ = rhs.enable_systrace_; |
141 enable_argument_filter_ = rhs.enable_argument_filter_; | 199 enable_argument_filter_ = rhs.enable_argument_filter_; |
142 memory_dump_config_ = rhs.memory_dump_config_; | 200 memory_dump_config_ = rhs.memory_dump_config_; |
143 included_categories_ = rhs.included_categories_; | 201 included_categories_ = rhs.included_categories_; |
144 disabled_categories_ = rhs.disabled_categories_; | 202 disabled_categories_ = rhs.disabled_categories_; |
145 excluded_categories_ = rhs.excluded_categories_; | 203 excluded_categories_ = rhs.excluded_categories_; |
146 synthetic_delays_ = rhs.synthetic_delays_; | 204 synthetic_delays_ = rhs.synthetic_delays_; |
| 205 category_event_filters_ = rhs.category_event_filters_; |
147 return *this; | 206 return *this; |
148 } | 207 } |
149 | 208 |
150 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { | 209 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { |
151 return synthetic_delays_; | 210 return synthetic_delays_; |
152 } | 211 } |
153 | 212 |
| 213 const TraceConfig::CategoryEventFilters& TraceConfig::GetCategoryEventFilters() |
| 214 const { |
| 215 return category_event_filters_; |
| 216 } |
| 217 |
154 std::string TraceConfig::ToString() const { | 218 std::string TraceConfig::ToString() const { |
155 base::DictionaryValue dict; | 219 base::DictionaryValue dict; |
156 ToDict(dict); | 220 ToDict(dict); |
157 | 221 |
158 std::string json; | 222 std::string json; |
159 base::JSONWriter::Write(dict, &json); | 223 base::JSONWriter::Write(dict, &json); |
160 | 224 |
161 return json; | 225 return json; |
162 } | 226 } |
163 | 227 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 400 |
337 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 401 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
338 // If dump triggers not set, the client is using the legacy with just | 402 // If dump triggers not set, the client is using the legacy with just |
339 // category enabled. So, use the default periodic dump config. | 403 // category enabled. So, use the default periodic dump config. |
340 const base::DictionaryValue* memory_dump_config = nullptr; | 404 const base::DictionaryValue* memory_dump_config = nullptr; |
341 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 405 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
342 SetMemoryDumpConfig(*memory_dump_config); | 406 SetMemoryDumpConfig(*memory_dump_config); |
343 else | 407 else |
344 SetDefaultMemoryDumpConfig(); | 408 SetDefaultMemoryDumpConfig(); |
345 } | 409 } |
| 410 |
| 411 const base::ListValue* category_event_filters = nullptr; |
| 412 if (dict.GetList(kCategoryEventFilterParam, &category_event_filters)) |
| 413 SetCategoryEventFilters(*category_event_filters); |
346 } | 414 } |
347 | 415 |
348 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { | 416 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
349 std::unique_ptr<Value> value(JSONReader::Read(config_string)); | 417 std::unique_ptr<Value> value(JSONReader::Read(config_string)); |
350 if (!value) | 418 if (!value) |
351 return InitializeDefault(); | 419 return InitializeDefault(); |
352 | 420 |
353 const DictionaryValue* dict = nullptr; | 421 const DictionaryValue* dict = nullptr; |
354 bool is_dict = value->GetAsDictionary(&dict); | 422 bool is_dict = value->GetAsDictionary(&dict); |
355 | 423 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 memory_dump_config_.push_back(dump_config); | 585 memory_dump_config_.push_back(dump_config); |
518 } | 586 } |
519 } | 587 } |
520 | 588 |
521 void TraceConfig::SetDefaultMemoryDumpConfig() { | 589 void TraceConfig::SetDefaultMemoryDumpConfig() { |
522 memory_dump_config_.clear(); | 590 memory_dump_config_.clear(); |
523 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); | 591 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); |
524 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); | 592 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); |
525 } | 593 } |
526 | 594 |
| 595 void TraceConfig::SetCategoryEventFilters( |
| 596 const base::ListValue& category_event_filters) { |
| 597 category_event_filters_.clear(); |
| 598 |
| 599 for (size_t i = 0; i < category_event_filters.GetSize(); ++i) { |
| 600 const base::DictionaryValue* event_filter = nullptr; |
| 601 if (!category_event_filters.GetDictionary(i, &event_filter)) |
| 602 continue; |
| 603 |
| 604 CategoryEventFilterConfig new_config; |
| 605 if (!event_filter->GetString(kPredicateParam, &new_config.predicate_name)) { |
| 606 LOG(ERROR) << "Invalid predicate name in category event filter."; |
| 607 continue; |
| 608 } |
| 609 |
| 610 const base::ListValue* included_list = nullptr; |
| 611 if (!event_filter->GetList(kIncludedCategoriesParam, &included_list)) { |
| 612 LOG(ERROR) << "Missing included_categories in category event filter."; |
| 613 continue; |
| 614 } |
| 615 |
| 616 for (size_t i = 0; i < included_list->GetSize(); ++i) { |
| 617 std::string category; |
| 618 if (included_list->GetString(i, &category)) |
| 619 new_config.included_categories.push_back(category); |
| 620 } |
| 621 |
| 622 const base::ListValue* excluded_list = nullptr; |
| 623 if (event_filter->GetList(kExcludedCategoriesParam, &excluded_list)) { |
| 624 for (size_t i = 0; i < excluded_list->GetSize(); ++i) { |
| 625 std::string category; |
| 626 if (excluded_list->GetString(i, &category)) |
| 627 new_config.excluded_categories.push_back(category); |
| 628 } |
| 629 } |
| 630 |
| 631 const base::DictionaryValue* args_dict = nullptr; |
| 632 if (event_filter->GetDictionary(kArgsParam, &args_dict)) { |
| 633 new_config.args = args_dict->CreateDeepCopy(); |
| 634 } |
| 635 |
| 636 category_event_filters_.push_back(new_config); |
| 637 } |
| 638 } |
| 639 |
527 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 640 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
528 switch (record_mode_) { | 641 switch (record_mode_) { |
529 case RECORD_UNTIL_FULL: | 642 case RECORD_UNTIL_FULL: |
530 dict.SetString(kRecordModeParam, kRecordUntilFull); | 643 dict.SetString(kRecordModeParam, kRecordUntilFull); |
531 break; | 644 break; |
532 case RECORD_CONTINUOUSLY: | 645 case RECORD_CONTINUOUSLY: |
533 dict.SetString(kRecordModeParam, kRecordContinuously); | 646 dict.SetString(kRecordModeParam, kRecordContinuously); |
534 break; | 647 break; |
535 case RECORD_AS_MUCH_AS_POSSIBLE: | 648 case RECORD_AS_MUCH_AS_POSSIBLE: |
536 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); | 649 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 str.at(0) == ' ' || | 785 str.at(0) == ' ' || |
673 str.at(str.length() - 1) == ' '; | 786 str.at(str.length() - 1) == ' '; |
674 } | 787 } |
675 | 788 |
676 bool TraceConfig::HasIncludedPatterns() const { | 789 bool TraceConfig::HasIncludedPatterns() const { |
677 return !included_categories_.empty(); | 790 return !included_categories_.empty(); |
678 } | 791 } |
679 | 792 |
680 } // namespace trace_event | 793 } // namespace trace_event |
681 } // namespace base | 794 } // namespace base |
OLD | NEW |