Chromium Code Reviews| Index: base/debug/trace_event_impl.h |
| diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h |
| index 7652419e1e03c4510bd3ade5c1037b6313588734..4eddbe516dd0ad6f5c1ac98b2f3749688dacb4d4 100644 |
| --- a/base/debug/trace_event_impl.h |
| +++ b/base/debug/trace_event_impl.h |
| @@ -67,7 +67,7 @@ class BASE_EXPORT TraceEvent { |
| TraceEvent(int thread_id, |
| TimeTicks timestamp, |
| char phase, |
| - const unsigned char* category_enabled, |
| + const unsigned char* category_group_enabled, |
| const char* name, |
| unsigned long long id, |
| int num_args, |
| @@ -96,7 +96,10 @@ class BASE_EXPORT TraceEvent { |
| return parameter_copy_storage_.get(); |
| } |
| - const unsigned char* category_enabled() const { return category_enabled_; } |
| + const unsigned char* category_group_enabled() const { |
| + return category_group_enabled_; |
| + } |
| + |
| const char* name() const { return name_; } |
| private: |
| @@ -106,7 +109,7 @@ class BASE_EXPORT TraceEvent { |
| unsigned long long id_; |
| TraceValue arg_values_[kTraceMaxNumArgs]; |
| const char* arg_names_[kTraceMaxNumArgs]; |
| - const unsigned char* category_enabled_; |
| + const unsigned char* category_group_enabled_; |
| const char* name_; |
| scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
| int thread_id_; |
| @@ -173,6 +176,65 @@ class BASE_EXPORT TraceResultBuffer { |
| bool append_comma_; |
| }; |
| +class BASE_EXPORT CategoryFilter { |
| + public: |
| + // 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; |
| + |
| + // |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: CategoryFilter"test_MyTest*"); |
| + // Example: CategoryFilter("test_MyTest*,test_OtherStuff"); |
| + // Example: CategoryFilter("-excluded_category1,-excluded_category2"); |
| + // Example: CategoryFilter("-*,webkit"); would disable everything but webkit. |
| + // Example: CategoryFilter("-webkit"); would enable everything but webkit. |
| + explicit CategoryFilter(const std::string& filter_string); |
| + |
| + CategoryFilter(const CategoryFilter& cf); |
| + |
| + CategoryFilter& operator=(const CategoryFilter& rhs); |
| + |
| + // 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 '-'. |
| + std::string ToString() const; |
| + |
| + // Determines whether category group would be enabled or |
| + // disabled by this category 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 explicitly allowed category patterns. |
| + bool HasIncludedPatterns() const; |
| + |
| + // Clears both included/excluded pattern lists. This would be equivalent to |
| + // creating a CategoryFilter with an empty string, through the constructor. |
| + // i.e: CategoryFilter(""). |
| + // |
| + // When using an empty filter, all categories are considered included as we |
| + // are not excluding anything. |
| + void Clear(); |
| + |
| + static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| + const std::string str); |
|
jar (doing other things)
2013/03/31 15:14:08
nit: should this be a const ref?
rterrazas
2013/04/15 01:41:11
Done.
|
| + |
| + 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_; |
| +}; |
|
jar (doing other things)
2013/03/31 15:14:08
nit: can we have a DISALLOW_COPY_AND_ASSIGN, or is
rterrazas
2013/04/15 01:41:11
Nope, it's created/copied in other classes.
|
| + |
| class TraceSamplingThread; |
| class BASE_EXPORT TraceLog { |
| @@ -206,43 +268,22 @@ class BASE_EXPORT TraceLog { |
| // the string does not provide valid options. |
| static Options TraceOptionsFromString(const std::string& str); |
| - // 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, |
| - Options options); |
| - |
| - // |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, Options options); |
| + // 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 GetKnownCategoryGroups(std::vector<std::string>* category_groups); |
| - // Retieves the categories set via a prior call to SetEnabled(). Only |
| + // Retrieves the current filter used to enable categories. Only |
| // meaningful if |IsEnabled()| is true. |
| - void GetEnabledTraceCategories(std::vector<std::string>* included_out, |
| - std::vector<std::string>* excluded_out); |
| + const CategoryFilter& GetCurrentCategoryFilter(); |
| Options trace_options() const { return trace_options_; } |
| + // Enables tracing. See CategoryFilter comments for details |
| + // on how to control what categories will be traced. |
| + void SetEnabled(const CategoryFilter& category_filter, Options options); |
| + |
| // Disable tracing for all categories. |
| void SetDisabled(); |
| - // Helper method to enable/disable tracing for all categories. |
| - void SetEnabled(bool enabled, Options options); |
| bool IsEnabled() { return !!enable_count_; } |
| #if defined(OS_ANDROID) |
| @@ -304,15 +345,18 @@ class BASE_EXPORT TraceLog { |
| void Flush(const OutputCallback& cb); |
| // Called by TRACE_EVENT* macros, don't call this directly. |
| - static const unsigned char* GetCategoryEnabled(const char* name); |
| - static const char* GetCategoryName(const unsigned char* category_enabled); |
| + // The name parameter is a category group for example: |
| + // TRACE_EVENT0("renderer,webkit", "WebViewImpl::HandleInputEvent") |
| + static const unsigned char* GetCategoryGroupEnabled(const char* name); |
| + static const char* GetCategoryGroupName( |
| + const unsigned char* category_group_enabled); |
| // Called by TRACE_EVENT* macros, don't call this directly. |
| // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
| // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. |
| void AddTraceEvent(char phase, |
| - const unsigned char* category_enabled, |
| - const char* name, |
| + const unsigned char* category_group_enabled, |
| + const char* category_group, |
| unsigned long long id, |
| int num_args, |
| const char** arg_names, |
| @@ -332,11 +376,11 @@ class BASE_EXPORT TraceLog { |
| const unsigned long long* arg_values, |
| unsigned char flags); |
| static void AddTraceEventEtw(char phase, |
| - const char* name, |
| + const char* category_group, |
| const void* id, |
| const char* extra); |
| static void AddTraceEventEtw(char phase, |
| - const char* name, |
| + const char* category_group, |
| const void* id, |
| const std::string& extra); |
| @@ -379,8 +423,14 @@ 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 current category_filter_. |
| + // If the category group contains a category that matches an included category |
| + // pattern, that category group will be enabled. |
| + void EnableIncludedCategoryGroups(); |
| + void EnableIncludedCategoryGroup(int category_index); |
| + |
| + // 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(). |
| @@ -415,12 +465,12 @@ class BASE_EXPORT TraceLog { |
| TraceLog(); |
| ~TraceLog(); |
| - const unsigned char* GetCategoryEnabledInternal(const char* name); |
| + const unsigned char* GetCategoryGroupEnabledInternal(const char* name); |
| void AddThreadNameMetadataEvents(); |
| #if defined(OS_ANDROID) |
| void SendToATrace(char phase, |
| - const char* category, |
| + const char* category_group, |
| const char* name, |
| unsigned long long id, |
| int num_args, |
| @@ -428,7 +478,7 @@ class BASE_EXPORT TraceLog { |
| const unsigned char* arg_types, |
| const unsigned long long* arg_values, |
| unsigned char flags); |
| - static void ApplyATraceEnabledFlag(unsigned char* category_enabled); |
| + static void ApplyATraceEnabledFlag(unsigned char* category_group_enabled); |
| #endif |
| TraceBuffer* GetTraceBuffer(); |
| @@ -441,8 +491,6 @@ class BASE_EXPORT TraceLog { |
| NotificationCallback notification_callback_; |
| scoped_ptr<TraceBuffer> logged_events_; |
| EventCallback event_callback_; |
| - std::vector<std::string> included_categories_; |
| - std::vector<std::string> excluded_categories_; |
| bool dispatching_to_observer_list_; |
| ObserverList<EnabledStateChangedObserver> enabled_state_observer_list_; |
| @@ -465,6 +513,8 @@ class BASE_EXPORT TraceLog { |
| scoped_ptr<TraceSamplingThread> sampling_thread_; |
| PlatformThreadHandle sampling_thread_handle_; |
| + CategoryFilter category_filter_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| }; |