| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_H_ | 5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_H_ |
| 6 #define BASE_TRACE_EVENT_TRACE_CONFIG_H_ | 6 #define BASE_TRACE_EVENT_TRACE_CONFIG_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <unordered_set> | 13 #include <unordered_set> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/base_export.h" | 16 #include "base/base_export.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/trace_event/memory_dump_request_args.h" | 19 #include "base/trace_event/memory_dump_request_args.h" |
| 20 #include "base/trace_event/trace_config_category_filter.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 namespace trace_event { | 24 namespace trace_event { |
| 24 | 25 |
| 25 class ConvertableToTraceFormat; | 26 class ConvertableToTraceFormat; |
| 26 | 27 |
| 27 // Options determines how the trace buffer stores data. | 28 // Options determines how the trace buffer stores data. |
| 28 enum TraceRecordMode { | 29 enum TraceRecordMode { |
| 29 // Record until the trace buffer is full. | 30 // Record until the trace buffer is full. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 88 |
| 88 class BASE_EXPORT EventFilterConfig { | 89 class BASE_EXPORT EventFilterConfig { |
| 89 public: | 90 public: |
| 90 EventFilterConfig(const std::string& predicate_name); | 91 EventFilterConfig(const std::string& predicate_name); |
| 91 EventFilterConfig(const EventFilterConfig& tc); | 92 EventFilterConfig(const EventFilterConfig& tc); |
| 92 | 93 |
| 93 ~EventFilterConfig(); | 94 ~EventFilterConfig(); |
| 94 | 95 |
| 95 EventFilterConfig& operator=(const EventFilterConfig& rhs); | 96 EventFilterConfig& operator=(const EventFilterConfig& rhs); |
| 96 | 97 |
| 97 void AddIncludedCategory(const std::string& category); | 98 void InitializeFromConfigDict(const base::DictionaryValue* event_filter); |
| 98 void AddExcludedCategory(const std::string& category); | 99 |
| 99 void SetArgs(std::unique_ptr<base::DictionaryValue> args); | 100 void SetCategoryFilter(const TraceConfigCategoryFilter& category_filter); |
| 101 |
| 102 void ToDict(DictionaryValue* filter_dict) const; |
| 103 |
| 100 bool GetArgAsSet(const char* key, std::unordered_set<std::string>*) const; | 104 bool GetArgAsSet(const char* key, std::unordered_set<std::string>*) const; |
| 101 | 105 |
| 102 bool IsCategoryGroupEnabled(const char* category_group_name) const; | 106 bool IsCategoryGroupEnabled(const char* category_group_name) const; |
| 103 | 107 |
| 104 const std::string& predicate_name() const { return predicate_name_; } | 108 const std::string& predicate_name() const { return predicate_name_; } |
| 105 base::DictionaryValue* filter_args() const { return args_.get(); } | 109 base::DictionaryValue* filter_args() const { return args_.get(); } |
| 106 const StringList& included_categories() const { | 110 const TraceConfigCategoryFilter& category_filter() const { |
| 107 return included_categories_; | 111 return category_filter_; |
| 108 } | |
| 109 const StringList& excluded_categories() const { | |
| 110 return excluded_categories_; | |
| 111 } | 112 } |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 std::string predicate_name_; | 115 std::string predicate_name_; |
| 115 StringList included_categories_; | 116 TraceConfigCategoryFilter category_filter_; |
| 116 StringList excluded_categories_; | |
| 117 std::unique_ptr<base::DictionaryValue> args_; | 117 std::unique_ptr<base::DictionaryValue> args_; |
| 118 }; | 118 }; |
| 119 typedef std::vector<EventFilterConfig> EventFilters; | 119 typedef std::vector<EventFilterConfig> EventFilters; |
| 120 | 120 |
| 121 TraceConfig(); | 121 TraceConfig(); |
| 122 | 122 |
| 123 // Create TraceConfig object from category filter and trace options strings. | 123 // Create TraceConfig object from category filter and trace options strings. |
| 124 // | 124 // |
| 125 // |category_filter_string| is a comma-delimited list of category wildcards. | 125 // |category_filter_string| is a comma-delimited list of category wildcards. |
| 126 // A category can have an optional '-' prefix to make it an excluded category. | 126 // A category can have an optional '-' prefix to make it an excluded category. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 bool IsCategoryGroupEnabled(const char* category_group_name) const; | 234 bool IsCategoryGroupEnabled(const char* category_group_name) const; |
| 235 | 235 |
| 236 // Merges config with the current TraceConfig | 236 // Merges config with the current TraceConfig |
| 237 void Merge(const TraceConfig& config); | 237 void Merge(const TraceConfig& config); |
| 238 | 238 |
| 239 void Clear(); | 239 void Clear(); |
| 240 | 240 |
| 241 // Clears and resets the memory dump config. | 241 // Clears and resets the memory dump config. |
| 242 void ResetMemoryDumpConfig(const MemoryDumpConfig& memory_dump_config); | 242 void ResetMemoryDumpConfig(const MemoryDumpConfig& memory_dump_config); |
| 243 | 243 |
| 244 const TraceConfigCategoryFilter& category_filter() const { |
| 245 return category_filter_; |
| 246 } |
| 247 |
| 244 const MemoryDumpConfig& memory_dump_config() const { | 248 const MemoryDumpConfig& memory_dump_config() const { |
| 245 return memory_dump_config_; | 249 return memory_dump_config_; |
| 246 } | 250 } |
| 247 | 251 |
| 248 const EventFilters& event_filters() const { return event_filters_; } | 252 const EventFilters& event_filters() const { return event_filters_; } |
| 249 void SetEventFilters(const EventFilters& filter_configs) { | 253 void SetEventFilters(const EventFilters& filter_configs) { |
| 250 event_filters_ = filter_configs; | 254 event_filters_ = filter_configs; |
| 251 } | 255 } |
| 252 | 256 |
| 253 private: | 257 private: |
| 254 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); | 258 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); |
| 255 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | 259 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 256 TraceConfigFromInvalidLegacyStrings); | 260 TraceConfigFromInvalidLegacyStrings); |
| 257 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); | |
| 258 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); | |
| 259 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | |
| 260 IsEmptyOrContainsLeadingOrTrailingWhitespace); | |
| 261 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromMemoryConfigString); | |
| 262 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, LegacyStringToMemoryDumpConfig); | |
| 263 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, EmptyMemoryDumpConfigTest); | |
| 264 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | |
| 265 EmptyAndAsteriskCategoryFilterString); | |
| 266 | 261 |
| 267 // The default trace config, used when none is provided. | 262 // The default trace config, used when none is provided. |
| 268 // Allows all non-disabled-by-default categories through, except if they end | 263 // Allows all non-disabled-by-default categories through, except if they end |
| 269 // in the suffix 'Debug' or 'Test'. | 264 // in the suffix 'Debug' or 'Test'. |
| 270 void InitializeDefault(); | 265 void InitializeDefault(); |
| 271 | 266 |
| 272 // Initialize from a config dictionary. | 267 // Initialize from a config dictionary. |
| 273 void InitializeFromConfigDict(const DictionaryValue& dict); | 268 void InitializeFromConfigDict(const DictionaryValue& dict); |
| 274 | 269 |
| 275 // Initialize from a config string. | 270 // Initialize from a config string. |
| 276 void InitializeFromConfigString(StringPiece config_string); | 271 void InitializeFromConfigString(StringPiece config_string); |
| 277 | 272 |
| 278 // Initialize from category filter and trace options strings | 273 // Initialize from category filter and trace options strings |
| 279 void InitializeFromStrings(StringPiece category_filter_string, | 274 void InitializeFromStrings(StringPiece category_filter_string, |
| 280 StringPiece trace_options_string); | 275 StringPiece trace_options_string); |
| 281 | 276 |
| 282 void SetCategoriesFromIncludedList(const ListValue& included_list); | |
| 283 void SetCategoriesFromExcludedList(const ListValue& excluded_list); | |
| 284 void SetSyntheticDelaysFromList(const ListValue& list); | |
| 285 void AddCategoryToDict(DictionaryValue* dict, | |
| 286 const char* param, | |
| 287 const StringList& categories) const; | |
| 288 | |
| 289 void SetMemoryDumpConfigFromConfigDict( | 277 void SetMemoryDumpConfigFromConfigDict( |
| 290 const DictionaryValue& memory_dump_config); | 278 const DictionaryValue& memory_dump_config); |
| 291 void SetDefaultMemoryDumpConfig(); | 279 void SetDefaultMemoryDumpConfig(); |
| 292 | 280 |
| 293 void SetEventFiltersFromConfigList(const base::ListValue& event_filters); | 281 void SetEventFiltersFromConfigList(const base::ListValue& event_filters); |
| 294 std::unique_ptr<DictionaryValue> ToDict() const; | 282 std::unique_ptr<DictionaryValue> ToDict() const; |
| 295 | 283 |
| 296 std::string ToTraceOptionsString() const; | 284 std::string ToTraceOptionsString() const; |
| 297 | 285 |
| 298 void WriteCategoryFilterString(const StringList& values, | |
| 299 std::string* out, | |
| 300 bool included) const; | |
| 301 void WriteCategoryFilterString(const StringList& delays, | |
| 302 std::string* out) const; | |
| 303 | |
| 304 // Returns true if the category is enabled according to this trace config. | |
| 305 // This tells whether a category is enabled from the TraceConfig's | |
| 306 // perspective. Please refer to IsCategoryGroupEnabled() to determine if a | |
| 307 // category is enabled from the tracing runtime's perspective. | |
| 308 bool IsCategoryEnabled(const char* category_name) const; | |
| 309 | |
| 310 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(StringPiece str); | |
| 311 | |
| 312 bool HasIncludedPatterns() const; | |
| 313 | |
| 314 TraceRecordMode record_mode_; | 286 TraceRecordMode record_mode_; |
| 315 bool enable_systrace_ : 1; | 287 bool enable_systrace_ : 1; |
| 316 bool enable_argument_filter_ : 1; | 288 bool enable_argument_filter_ : 1; |
| 317 | 289 |
| 290 TraceConfigCategoryFilter category_filter_; |
| 291 |
| 318 MemoryDumpConfig memory_dump_config_; | 292 MemoryDumpConfig memory_dump_config_; |
| 319 | 293 |
| 320 StringList included_categories_; | |
| 321 StringList disabled_categories_; | |
| 322 StringList excluded_categories_; | |
| 323 StringList synthetic_delays_; | |
| 324 EventFilters event_filters_; | 294 EventFilters event_filters_; |
| 325 }; | 295 }; |
| 326 | 296 |
| 327 } // namespace trace_event | 297 } // namespace trace_event |
| 328 } // namespace base | 298 } // namespace base |
| 329 | 299 |
| 330 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ | 300 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ |
| OLD | NEW |