Index: base/trace_event/trace_config.cc |
diff --git a/base/trace_event/trace_config.cc b/base/trace_event/trace_config.cc |
index e9e5a099893377e844be716845b0bbcfe90a2639..ac7f655e951a1762fc50feb416ea299d7fea5df0 100644 |
--- a/base/trace_event/trace_config.cc |
+++ b/base/trace_event/trace_config.cc |
@@ -51,6 +51,11 @@ const char kTriggersParam[] = "triggers"; |
const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
const char kModeParam[] = "mode"; |
+// String parameters used to parse category event filters. |
+const char kCategoryEventFilterParam[] = "category_event_filters"; |
+const char kPredicateParam[] = "predicate"; |
+const char kArgsParam[] = "args"; |
+ |
// Default configuration of memory dumps. |
const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { |
2000, // periodic_interval_ms |
@@ -75,6 +80,75 @@ class ConvertableTraceConfigToTraceFormat |
} // namespace |
+TraceConfig::CategoryEventFilterConfig::CategoryEventFilterConfig( |
+ const std::string& predicate_name) |
+ : predicate_name_(predicate_name) {} |
+TraceConfig::CategoryEventFilterConfig::~CategoryEventFilterConfig() {} |
+ |
+TraceConfig::CategoryEventFilterConfig::CategoryEventFilterConfig( |
+ const CategoryEventFilterConfig& tc) |
+ : predicate_name_(tc.predicate_name_), |
+ included_categories_(tc.included_categories_), |
+ excluded_categories_(tc.excluded_categories_) { |
+ if (tc.args_) |
+ args_ = tc.args_->CreateDeepCopy(); |
+} |
+ |
+TraceConfig::CategoryEventFilterConfig& TraceConfig::CategoryEventFilterConfig:: |
+operator=(const TraceConfig::CategoryEventFilterConfig& rhs) { |
+ if (this == &rhs) |
+ return *this; |
+ |
+ predicate_name_ = rhs.predicate_name_; |
+ included_categories_ = rhs.included_categories_; |
+ excluded_categories_ = rhs.excluded_categories_; |
+ if (rhs.args_) |
+ args_ = rhs.args_->CreateDeepCopy(); |
+ |
+ return *this; |
+} |
+ |
+void TraceConfig::CategoryEventFilterConfig::AddIncludedCategory( |
+ const std::string& category) { |
+ included_categories_.push_back(category); |
+} |
+ |
+void TraceConfig::CategoryEventFilterConfig::AddExcludedCategory( |
+ const std::string& category) { |
+ excluded_categories_.push_back(category); |
+} |
+ |
+void TraceConfig::CategoryEventFilterConfig::SetArgs( |
+ std::unique_ptr<base::DictionaryValue> args) { |
+ args_ = std::move(args); |
+} |
+ |
+bool TraceConfig::CategoryEventFilterConfig::IsCategoryGroupEnabled( |
+ const char* category_group_name) const { |
+ CStringTokenizer category_group_tokens( |
+ category_group_name, category_group_name + strlen(category_group_name), |
+ ","); |
+ while (category_group_tokens.GetNext()) { |
+ std::string category_group_token = category_group_tokens.token(); |
+ |
+ for (const auto& excluded_category : excluded_categories_) { |
+ if (base::MatchPattern(category_group_token.c_str(), |
+ excluded_category.c_str())) { |
+ return false; |
+ } |
+ } |
+ |
+ for (const auto& included_category : included_categories_) { |
+ if (base::MatchPattern(category_group_token.c_str(), |
+ included_category.c_str())) { |
+ return true; |
+ } |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
TraceConfig::TraceConfig() { |
InitializeDefault(); |
} |
@@ -126,7 +200,8 @@ TraceConfig::TraceConfig(const TraceConfig& tc) |
included_categories_(tc.included_categories_), |
disabled_categories_(tc.disabled_categories_), |
excluded_categories_(tc.excluded_categories_), |
- synthetic_delays_(tc.synthetic_delays_) {} |
+ synthetic_delays_(tc.synthetic_delays_), |
+ category_event_filters_(tc.category_event_filters_) {} |
TraceConfig::~TraceConfig() { |
} |
@@ -144,6 +219,7 @@ TraceConfig& TraceConfig::operator=(const TraceConfig& rhs) { |
disabled_categories_ = rhs.disabled_categories_; |
excluded_categories_ = rhs.excluded_categories_; |
synthetic_delays_ = rhs.synthetic_delays_; |
+ category_event_filters_ = rhs.category_event_filters_; |
return *this; |
} |
@@ -282,6 +358,7 @@ void TraceConfig::Clear() { |
excluded_categories_.clear(); |
synthetic_delays_.clear(); |
memory_dump_config_.clear(); |
+ category_event_filters_.clear(); |
} |
void TraceConfig::InitializeDefault() { |
@@ -343,6 +420,10 @@ void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { |
else |
SetDefaultMemoryDumpConfig(); |
} |
+ |
+ const base::ListValue* category_event_filters = nullptr; |
+ if (dict.GetList(kCategoryEventFilterParam, &category_event_filters)) |
+ SetCategoryEventFilters(*category_event_filters); |
} |
void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
@@ -524,6 +605,51 @@ void TraceConfig::SetDefaultMemoryDumpConfig() { |
memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); |
} |
+void TraceConfig::SetCategoryEventFilters( |
+ const base::ListValue& category_event_filters) { |
+ category_event_filters_.clear(); |
+ |
+ for (size_t i = 0; i < category_event_filters.GetSize(); ++i) { |
+ const base::DictionaryValue* event_filter = nullptr; |
+ if (!category_event_filters.GetDictionary(i, &event_filter)) |
+ continue; |
+ |
+ std::string predicate_name; |
+ if (!event_filter->GetString(kPredicateParam, &predicate_name)) { |
+ LOG(ERROR) << "Invalid predicate name in category event filter."; |
+ continue; |
+ } |
+ |
+ CategoryEventFilterConfig new_config(predicate_name); |
+ const base::ListValue* included_list = nullptr; |
+ if (!event_filter->GetList(kIncludedCategoriesParam, &included_list)) { |
+ LOG(ERROR) << "Missing included_categories in category event filter."; |
+ continue; |
+ } |
+ |
+ for (size_t i = 0; i < included_list->GetSize(); ++i) { |
+ std::string category; |
+ if (included_list->GetString(i, &category)) |
+ new_config.AddIncludedCategory(category); |
+ } |
+ |
+ const base::ListValue* excluded_list = nullptr; |
+ if (event_filter->GetList(kExcludedCategoriesParam, &excluded_list)) { |
+ for (size_t i = 0; i < excluded_list->GetSize(); ++i) { |
+ std::string category; |
+ if (excluded_list->GetString(i, &category)) |
+ new_config.AddExcludedCategory(category); |
+ } |
+ } |
+ |
+ const base::DictionaryValue* args_dict = nullptr; |
+ if (event_filter->GetDictionary(kArgsParam, &args_dict)) |
+ new_config.SetArgs(args_dict->CreateDeepCopy()); |
+ |
+ category_event_filters_.push_back(new_config); |
+ } |
+} |
+ |
void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
switch (record_mode_) { |
case RECORD_UNTIL_FULL: |
@@ -565,6 +691,40 @@ void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
+ if (!category_event_filters_.empty()) { |
+ std::unique_ptr<base::ListValue> filter_list(new base::ListValue()); |
+ for (const CategoryEventFilterConfig& filter : category_event_filters_) { |
+ std::unique_ptr<base::DictionaryValue> filter_dict( |
+ new base::DictionaryValue()); |
+ filter_dict->SetString(kPredicateParam, filter.predicate_name()); |
+ |
+ std::unique_ptr<base::ListValue> included_categories_list( |
+ new base::ListValue()); |
+ for (const std::string& included_category : filter.included_categories()) |
+ included_categories_list->AppendString(included_category); |
+ |
+ filter_dict->Set(kIncludedCategoriesParam, |
+ std::move(included_categories_list)); |
+ |
+ if (!filter.excluded_categories().empty()) { |
+ std::unique_ptr<base::ListValue> excluded_categories_list( |
+ new base::ListValue()); |
+ for (const std::string& excluded_category : |
+ filter.excluded_categories()) |
+ excluded_categories_list->AppendString(excluded_category); |
+ |
+ filter_dict->Set(kExcludedCategoriesParam, |
+ std::move(excluded_categories_list)); |
+ } |
+ |
+ if (filter.args()) |
+ filter_dict->Set(kArgsParam, filter.args()->CreateDeepCopy()); |
+ |
+ filter_list->Append(std::move(filter_dict)); |
+ } |
+ dict.Set(kCategoryEventFilterParam, std::move(filter_list)); |
+ } |
+ |
if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
std::unique_ptr<base::DictionaryValue> memory_dump_config( |
new base::DictionaryValue()); |