Index: base/debug/trace_event_impl.cc |
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
index 50c0d82abdf384591e2404148f298411d2bd6662..14e646356260542539754ea2f632a096855cd0b2 100644 |
--- a/base/debug/trace_event_impl.cc |
+++ b/base/debug/trace_event_impl.cc |
@@ -393,14 +393,32 @@ const char* TraceLog::GetCategoryName(const unsigned char* category_enabled) { |
return g_categories[category_index]; |
} |
+static bool DoesCategoryContainMatchingTag(const char* tagged_category, |
nduca
2013/01/28 08:15:28
So this would be DoesCategoryGroupContainCategory
|
+ const char* tag_pattern) { |
+ CStringTokenizer tag_tokens(tagged_category, |
+ tagged_category + strlen(tagged_category), ","); |
+ while (tag_tokens.GetNext()) { |
+ std::string trimmed_tag; |
+ //Trimming tokens to allow categories with arbitrary spacing: |
+ // i.e: "webkit, input" or "webkit , input". |
+ TrimWhitespaceASCII(tag_tokens.token(), TRIM_ALL, &trimmed_tag); |
rterrazas
2013/01/18 17:44:18
I'm thinking that maybe checking if we have leadin
|
+ if(trimmed_tag.length() == 0) |
+ continue; |
+ if (MatchPattern(trimmed_tag.c_str(), tag_pattern)) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
static void EnableMatchingCategory(int category_index, |
- const std::vector<std::string>& patterns, |
+ const std::vector<std::string>& tag_patterns, |
unsigned char matched_value, |
unsigned char unmatched_value) { |
- std::vector<std::string>::const_iterator ci = patterns.begin(); |
+ std::vector<std::string>::const_iterator ci = tag_patterns.begin(); |
bool is_match = false; |
- for (; ci != patterns.end(); ++ci) { |
- is_match = MatchPattern(g_categories[category_index], ci->c_str()); |
+ for (; ci != tag_patterns.end(); ++ci) { |
+ is_match = DoesCategoryContainMatchingTag(g_categories[category_index], |
+ ci->c_str()); |
if (is_match) |
break; |
} |
@@ -408,14 +426,16 @@ static void EnableMatchingCategory(int category_index, |
matched_value : unmatched_value; |
} |
-// Enable/disable each category based on the category filters in |patterns|. |
-// If the category name matches one of the patterns, its enabled status is set |
-// to |matched_value|. Otherwise its enabled status is set to |unmatched_value|. |
-static void EnableMatchingCategories(const std::vector<std::string>& patterns, |
- unsigned char matched_value, |
- unsigned char unmatched_value) { |
+// Enable/disable each category based on the category filters in |tag_patterns|. |
+// If the category contains a tag that matches one of the tag_patterns, its |
+// enabled status is set to |matched_value|. |
+// Otherwise its enabled status is set to |unmatched_value|. |
+static void EnableMatchingCategories( |
+ const std::vector<std::string>& tag_patterns, |
+ unsigned char matched_value, |
+ unsigned char unmatched_value) { |
for (int i = 0; i < g_category_index; i++) |
- EnableMatchingCategory(i, patterns, matched_value, unmatched_value); |
+ EnableMatchingCategory(i, tag_patterns, matched_value, unmatched_value); |
} |
const unsigned char* TraceLog::GetCategoryEnabledInternal(const char* name) { |
@@ -445,13 +465,13 @@ const unsigned char* TraceLog::GetCategoryEnabledInternal(const char* name) { |
g_categories[new_index] = new_name; |
DCHECK(!g_category_enabled[new_index]); |
if (enable_count_) { |
- // Note that if both included and excluded_categories are empty, the |
+ // Note that if both included and excluded_tag_patterns are empty, the |
// else clause below excludes nothing, thereby enabling this category. |
- if (!included_categories_.empty()) { |
- EnableMatchingCategory(new_index, included_categories_, |
+ if (!included_tag_patterns_.empty()) { |
+ EnableMatchingCategory(new_index, included_tag_patterns_, |
CATEGORY_ENABLED, 0); |
} else { |
- EnableMatchingCategory(new_index, excluded_categories_, |
+ EnableMatchingCategory(new_index, excluded_tag_patterns_, |
0, CATEGORY_ENABLED); |
} |
} else { |
@@ -474,23 +494,23 @@ void TraceLog::GetKnownCategories(std::vector<std::string>* categories) { |
categories->push_back(g_categories[i]); |
} |
-void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, |
- const std::vector<std::string>& excluded_categories) { |
+void TraceLog::SetEnabled( |
+ const std::vector<std::string>& included_tag_patterns, |
+ const std::vector<std::string>& excluded_tag_patterns) { |
AutoLock lock(lock_); |
- |
if (enable_count_++ > 0) { |
- // Tracing is already enabled, so just merge in enabled categories. |
+ // Tracing is already enabled, so just merge in enabled categories |
// We only expand the set of enabled categories upon nested SetEnable(). |
- if (!included_categories_.empty() && !included_categories.empty()) { |
- included_categories_.insert(included_categories_.end(), |
- included_categories.begin(), |
- included_categories.end()); |
- EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
+ if (!included_tag_patterns_.empty() && !included_tag_patterns.empty()) { |
+ included_tag_patterns_.insert(included_tag_patterns_.end(), |
+ included_tag_patterns.begin(), |
+ included_tag_patterns.end()); |
+ EnableMatchingCategories(included_tag_patterns_, CATEGORY_ENABLED, 0); |
} else { |
// If either old or new included categories are empty, allow all events. |
- included_categories_.clear(); |
- excluded_categories_.clear(); |
- EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
+ included_tag_patterns_.clear(); |
+ excluded_tag_patterns_.clear(); |
+ EnableMatchingCategories(excluded_tag_patterns_, 0, CATEGORY_ENABLED); |
} |
return; |
} |
@@ -507,33 +527,33 @@ void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, |
dispatching_to_observer_list_ = false; |
logged_events_.reserve(1024); |
- included_categories_ = included_categories; |
- excluded_categories_ = excluded_categories; |
- // Note that if both included and excluded_categories are empty, the else |
+ included_tag_patterns_ = included_tag_patterns; |
+ excluded_tag_patterns_ = excluded_tag_patterns; |
+ // Note that if both included and excluded_tag_patterns are empty, the else |
// clause below excludes nothing, thereby enabling all categories. |
- if (!included_categories_.empty()) |
- EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
+ if (!included_tag_patterns_.empty()) |
+ EnableMatchingCategories(included_tag_patterns_, CATEGORY_ENABLED, 0); |
else |
- EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
+ EnableMatchingCategories(excluded_tag_patterns_, 0, CATEGORY_ENABLED); |
} |
-void TraceLog::SetEnabled(const std::string& categories) { |
+void TraceLog::SetEnabled(const std::string& tag_patterns) { |
std::vector<std::string> included, excluded; |
- // Tokenize list of categories, delimited by ','. |
- StringTokenizer tokens(categories, ","); |
+ // Tokenize list of tag patterns, delimited by ','. |
+ StringTokenizer tokens(tag_patterns, ","); |
while (tokens.GetNext()) { |
bool is_included = true; |
- std::string category = tokens.token(); |
- // Excluded categories start with '-'. |
- if (category.at(0) == '-') { |
- // Remove '-' from category string. |
- category = category.substr(1); |
+ std::string tag_pattern = tokens.token(); |
+ // Excluded tag patterns start with '-'. |
+ if (tag_pattern.at(0) == '-') { |
+ // Remove '-' from tag_pattern string. |
+ tag_pattern = tag_pattern.substr(1); |
is_included = false; |
} |
if (is_included) |
- included.push_back(category); |
+ included.push_back(tag_pattern); |
else |
- excluded.push_back(category); |
+ excluded.push_back(tag_pattern); |
} |
SetEnabled(included, excluded); |
} |
@@ -543,8 +563,8 @@ void TraceLog::GetEnabledTraceCategories( |
std::vector<std::string>* excluded_out) { |
AutoLock lock(lock_); |
if (enable_count_) { |
- *included_out = included_categories_; |
- *excluded_out = excluded_categories_; |
+ *included_out = included_tag_patterns_; |
+ *excluded_out = excluded_tag_patterns_; |
} |
} |
@@ -565,8 +585,8 @@ void TraceLog::SetDisabled() { |
OnTraceLogWillDisable()); |
dispatching_to_observer_list_ = false; |
- included_categories_.clear(); |
- excluded_categories_.clear(); |
+ included_tag_patterns_.clear(); |
+ excluded_tag_patterns_.clear(); |
watch_category_ = NULL; |
watch_event_name_ = ""; |
for (int i = 0; i < g_category_index; i++) |