Index: base/debug/trace_event_impl.h |
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h |
index f152b0a413b4302e51191518b2c3993252d15d70..16361b1eedac4d3f01e5326bb57a06177d251007 100644 |
--- a/base/debug/trace_event_impl.h |
+++ b/base/debug/trace_event_impl.h |
@@ -157,6 +157,55 @@ class BASE_EXPORT TraceResultBuffer { |
bool append_comma_; |
}; |
+class BASE_EXPORT CategoryFilter { |
+ // The default category filter, used when none is provided. |
+ // Allows all categories through, except if they end in the suffix 'Debug' or |
+ // 'Test'. |
+ static const char* kDefaultCategoryFilterString; |
+ |
+ public: |
+ // Constructs the default category filter. This is equivalent to |
+ // CategoryFilter(CategoryFilter::kDefaultCategoryFilterString); |
+ CategoryFilter(); |
+ |
+ // |filter_string| is a comma-delimited list of category wildcards. |
+ // A category can have an optional '-' prefix to make it an excluded category. |
+ // All the same rules apply above, so for example, having both included and |
+ // excluded categories in the same list would not be supported. |
+ // |
+ // Example: SetEnabled("test_MyTest*"); |
+ // Example: SetEnabled("test_MyTest*,test_OtherStuff"); |
+ // Example: SetEnabled("-excluded_category1,-excluded_category2"); |
+ CategoryFilter(const std::string& filter_string); |
+ |
+ // Writes the string representation of the CategoryFilter. This is a comma |
+ // separated string, similar in nature to the one used to determine |
+ // enabled/disabled category patterns, except here there is an arbitrary |
+ // order, included categories go first, then excluded categories. Excluded |
+ // categories are distinguished from included categories by the prefix '-'. |
+ void ToString(std::string* filter_string) const; |
+ |
+ // Determines whether category group would be enabled or |
+ // disabled by this filter. |
+ bool IsCategoryGroupEnabled(const char* category_group) const; |
+ |
+ // Merges nested_filter with the current CategoryFilter |
+ void Merge(const CategoryFilter& nested_filter); |
+ |
+ // Determines whether or not we have included category patterns. |
+ bool HasIncludedCategories() const; |
+ |
+ // Clears both included/excluded pattern lists. |
+ void Clear(); |
+ |
+private: |
+ void Initialize(const std::string& filter_string); |
+ void WriteString(std::string* out, bool included) const; |
+ |
+ std::vector<std::string> included_; |
+ std::vector<std::string> excluded_; |
+ |
+}; |
class BASE_EXPORT TraceLog { |
public: |
@@ -172,40 +221,22 @@ class BASE_EXPORT TraceLog { |
static TraceLog* GetInstance(); |
- // Get set of known categories. This can change as new code paths are reached. |
- // The known categories are inserted into |categories|. |
- void GetKnownCategories(std::vector<std::string>* categories); |
- |
- // Enable tracing for provided list of categories. If tracing is already |
- // enabled, this method does nothing -- changing categories during trace is |
- // not supported. |
- // If both included_categories and excluded_categories are empty, |
- // all categories are traced. |
- // Else if included_categories is non-empty, only those are traced. |
- // Else if excluded_categories is non-empty, everything but those are traced. |
- // Wildcards * and ? are supported (see MatchPattern in string_util.h). |
- void SetEnabled(const std::vector<std::string>& included_categories, |
- const std::vector<std::string>& excluded_categories); |
- |
- // |categories| is a comma-delimited list of category wildcards. |
- // A category can have an optional '-' prefix to make it an excluded category. |
- // All the same rules apply above, so for example, having both included and |
- // excluded categories in the same list would not be supported. |
- // |
- // Example: SetEnabled("test_MyTest*"); |
- // Example: SetEnabled("test_MyTest*,test_OtherStuff"); |
- // Example: SetEnabled("-excluded_category1,-excluded_category2"); |
- void SetEnabled(const std::string& categories); |
+ // Get set of known category groups. This can change as new code paths are |
+ // reached. The known category groups are inserted into |category_groups|. |
+ void GetKnownCategories(std::vector<std::string>* category_groups); |
- // Retieves the categories set via a prior call to SetEnabled(). Only |
- // meaningful if |IsEnabled()| is true. |
- void GetEnabledTraceCategories(std::vector<std::string>* included_out, |
- std::vector<std::string>* excluded_out); |
+ // Enables tracing. See CategoryFilter comments for details |
+ // on how to control what categories will be traced. |
+ void SetEnabled(const CategoryFilter& category_filter); |
// Disable tracing for all categories. |
void SetDisabled(); |
+ |
+ // Retieves the current filter used to enable categories. Only |
+ // meaningful if |IsEnabled()| is true. |
+ CategoryFilter& GetCurrentCategoryFilter(); |
+ |
// Helper method to enable/disable tracing for all categories. |
- void SetEnabled(bool enabled); |
bool IsEnabled() { return !!enable_count_; } |
#if defined(OS_ANDROID) |
@@ -251,6 +282,8 @@ class BASE_EXPORT TraceLog { |
void Flush(const OutputCallback& cb); |
// Called by TRACE_EVENT* macros, don't call this directly. |
+ // The name parameter is a category group for example: |
+ // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
static const unsigned char* GetCategoryEnabled(const char* name); |
static const char* GetCategoryName(const unsigned char* category_enabled); |
@@ -325,8 +358,16 @@ class BASE_EXPORT TraceLog { |
// by the Singleton class. |
friend struct StaticMemorySingletonTraits<TraceLog>; |
- // The pointer returned from GetCategoryEnabledInternal() points to a value |
- // with zero or more of the following bits. Used in this class only. |
+ // Enable/disable each category group based on the given |category_filter|. |
+ // If the category group contains a category that matches an included category |
+ // pattern, that category group will be enabled. |
+ static void EnableIncludedCategoryGroups( |
+ const CategoryFilter& category_filter); |
+ static void EnableIncludedCategoryGroup(int category_index, |
+ const CategoryFilter& category_filter); |
+ |
+ // The pointer returned from GetCategoryGroupEnabledInternal() points to a |
+ // value with zero or more of the following bits. Used in this class only. |
// The TRACE_EVENT macros should only use the value as a bool. |
enum CategoryEnabledFlags { |
// Normal enabled flag for categories enabled with Enable(). |
@@ -382,8 +423,7 @@ class BASE_EXPORT TraceLog { |
int enable_count_; |
NotificationCallback notification_callback_; |
std::vector<TraceEvent> logged_events_; |
- std::vector<std::string> included_categories_; |
- std::vector<std::string> excluded_categories_; |
+ CategoryFilter category_filter_; |
bool dispatching_to_observer_list_; |
ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; |