1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_CATEGORY_FILTER_H_ 6 #define BASE_TRACE_EVENT_TRACE_CONFIG_CATEGORY_FILTER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/base_export.h" 12 #include "base/strings/string_piece.h" 13 #include "base/values.h" 14 15 namespace base { 16 namespace trace_event { 17 18 // Configuration of categories enabled and disabled in TraceConfig. 19 class BASE_EXPORT TraceConfigCategoryFilter { 20 public: 21 using StringList = std::vector<std::string>; 22 23 TraceConfigCategoryFilter(); 24 TraceConfigCategoryFilter(const TraceConfigCategoryFilter& other); 25 ~TraceConfigCategoryFilter(); 26 27 TraceConfigCategoryFilter& operator=(const TraceConfigCategoryFilter& rhs); 28 29 // Initializes from category filter string. See TraceConfig constructor for 30 // description of how to write category filter string. 31 void InitializeFromString(const StringPiece& category_filter_string); 32 33 // Initializes TraceConfigCategoryFilter object from the config dictionary. 34 void InitializeFromConfigDict(const DictionaryValue& dict); 35 36 // Merges this with category filter config. 37 void Merge(const TraceConfigCategoryFilter& config); 38 void Clear(); 39 40 // Returns true if at least one category in the list is enabled by this 41 // trace config. This is used to determine if the category filters are 42 // enabled in the TRACE_* macros. 43 bool IsCategoryGroupEnabled(const StringPiece& category_group_name) const; 44 45 // Returns true if the category is enabled according to this trace config. 46 // This tells whether a category is enabled from the TraceConfig's 47 // perspective. Please refer to IsCategoryGroupEnabled() to determine if a 48 // category is enabled from the tracing runtime's perspective. 49 bool IsCategoryEnabled(const StringPiece& category_name) const; 50 51 void ToDict(DictionaryValue* dict) const; 52 53 std::string ToFilterString() const; 54 55 // Returns true if category name is a valid string. 56 static bool IsCategoryNameAllowed(StringPiece str); 57 included_categories()58 const StringList& included_categories() const { return included_categories_; } excluded_categories()59 const StringList& excluded_categories() const { return excluded_categories_; } synthetic_delays()60 const StringList& synthetic_delays() const { return synthetic_delays_; } 61 62 private: 63 void SetCategoriesFromIncludedList(const ListValue& included_list); 64 void SetCategoriesFromExcludedList(const ListValue& excluded_list); 65 void SetSyntheticDelaysFromList(const ListValue& list); 66 67 void AddCategoriesToDict(const StringList& categories, 68 const char* param, 69 DictionaryValue* dict) const; 70 71 void WriteCategoryFilterString(const StringList& values, 72 std::string* out, 73 bool included) const; 74 void WriteCategoryFilterString(const StringList& delays, 75 std::string* out) const; 76 77 StringList included_categories_; 78 StringList disabled_categories_; 79 StringList excluded_categories_; 80 StringList synthetic_delays_; 81 }; 82 83 } // namespace trace_event 84 } // namespace base 85 86 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_CATEGORY_FILTER_H_ 87