| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/trace_event/memory_dump_provider.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 namespace trace_event { | 17 namespace trace_event { |
| 17 | 18 |
| 18 // Options determines how the trace buffer stores data. | 19 // Options determines how the trace buffer stores data. |
| 19 enum TraceRecordMode { | 20 enum TraceRecordMode { |
| 20 // Record until the trace buffer is full. | 21 // Record until the trace buffer is full. |
| 21 RECORD_UNTIL_FULL, | 22 RECORD_UNTIL_FULL, |
| 22 | 23 |
| 23 // Record until the user ends the trace. The trace buffer is a fixed size | 24 // Record until the user ends the trace. The trace buffer is a fixed size |
| 24 // and we use it as a ring buffer during recording. | 25 // and we use it as a ring buffer during recording. |
| 25 RECORD_CONTINUOUSLY, | 26 RECORD_CONTINUOUSLY, |
| 26 | 27 |
| 27 // Record until the trace buffer is full, but with a huge buffer size. | 28 // Record until the trace buffer is full, but with a huge buffer size. |
| 28 RECORD_AS_MUCH_AS_POSSIBLE, | 29 RECORD_AS_MUCH_AS_POSSIBLE, |
| 29 | 30 |
| 30 // Echo to console. Events are discarded. | 31 // Echo to console. Events are discarded. |
| 31 ECHO_TO_CONSOLE, | 32 ECHO_TO_CONSOLE, |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 class BASE_EXPORT TraceConfig { | 35 class BASE_EXPORT TraceConfig { |
| 35 public: | 36 public: |
| 36 typedef std::vector<std::string> StringList; | 37 typedef std::vector<std::string> StringList; |
| 37 | 38 |
| 39 // Specifies the memory dump config for tracing. Used only when |
| 40 // "memory-infra" category is enabled. |
| 41 struct MemoryDumpTriggerConfig { |
| 42 uint32 periodic_interval_ms; |
| 43 MemoryDumpArgs::LevelOfDetail level_of_detail; |
| 44 }; |
| 45 |
| 46 typedef std::vector<MemoryDumpTriggerConfig> MemoryDumpConfig; |
| 47 |
| 38 TraceConfig(); | 48 TraceConfig(); |
| 39 | 49 |
| 40 // Create TraceConfig object from category filter and trace options strings. | 50 // Create TraceConfig object from category filter and trace options strings. |
| 41 // | 51 // |
| 42 // |category_filter_string| is a comma-delimited list of category wildcards. | 52 // |category_filter_string| is a comma-delimited list of category wildcards. |
| 43 // A category can have an optional '-' prefix to make it an excluded category. | 53 // A category can have an optional '-' prefix to make it an excluded category. |
| 44 // All the same rules apply above, so for example, having both included and | 54 // All the same rules apply above, so for example, having both included and |
| 45 // excluded categories in the same list would not be supported. | 55 // excluded categories in the same list would not be supported. |
| 46 // | 56 // |
| 47 // Category filters can also be used to configure synthetic delays. | 57 // Category filters can also be used to configure synthetic delays. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // category filters and trace options. | 102 // category filters and trace options. |
| 93 // | 103 // |
| 94 // Example: | 104 // Example: |
| 95 // { | 105 // { |
| 96 // "record_mode": "record-continuously", | 106 // "record_mode": "record-continuously", |
| 97 // "enable_sampling": true, | 107 // "enable_sampling": true, |
| 98 // "enable_systrace": true, | 108 // "enable_systrace": true, |
| 99 // "enable_argument_filter": true, | 109 // "enable_argument_filter": true, |
| 100 // "included_categories": ["included", | 110 // "included_categories": ["included", |
| 101 // "inc_pattern*", | 111 // "inc_pattern*", |
| 102 // "disabled-by-default-category1"], | 112 // "disabled-by-default-memory-infra"], |
| 103 // "excluded_categories": ["excluded", "exc_pattern*"], | 113 // "excluded_categories": ["excluded", "exc_pattern*"], |
| 104 // "synthetic_delays": ["test.Delay1;16", "test.Delay2;32"] | 114 // "synthetic_delays": ["test.Delay1;16", "test.Delay2;32"] |
| 115 // "memory_dump_config": { |
| 116 // "triggers": [ |
| 117 // { |
| 118 // "mode": "detailed", |
| 119 // "periodic_interval_ms": 2000 |
| 120 // } |
| 121 // ] |
| 122 // } |
| 105 // } | 123 // } |
| 124 // |
| 125 // Note: memory_dump_config can be specified only if |
| 126 // disabled-by-default-memory-infra category is enabled. |
| 106 explicit TraceConfig(const std::string& config_string); | 127 explicit TraceConfig(const std::string& config_string); |
| 107 | 128 |
| 108 TraceConfig(const TraceConfig& tc); | 129 TraceConfig(const TraceConfig& tc); |
| 109 | 130 |
| 110 ~TraceConfig(); | 131 ~TraceConfig(); |
| 111 | 132 |
| 112 TraceConfig& operator=(const TraceConfig& rhs); | 133 TraceConfig& operator=(const TraceConfig& rhs); |
| 113 | 134 |
| 114 // Return a list of the synthetic delays specified in this category filter. | 135 // Return a list of the synthetic delays specified in this category filter. |
| 115 const StringList& GetSyntheticDelayValues() const; | 136 const StringList& GetSyntheticDelayValues() const; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 133 | 154 |
| 134 // Returns true if at least one category in the list is enabled by this | 155 // Returns true if at least one category in the list is enabled by this |
| 135 // trace config. | 156 // trace config. |
| 136 bool IsCategoryGroupEnabled(const char* category_group) const; | 157 bool IsCategoryGroupEnabled(const char* category_group) const; |
| 137 | 158 |
| 138 // Merges config with the current TraceConfig | 159 // Merges config with the current TraceConfig |
| 139 void Merge(const TraceConfig& config); | 160 void Merge(const TraceConfig& config); |
| 140 | 161 |
| 141 void Clear(); | 162 void Clear(); |
| 142 | 163 |
| 164 const MemoryDumpConfig& memory_dump_config() const { |
| 165 return memory_dump_config_; |
| 166 } |
| 167 |
| 143 private: | 168 private: |
| 144 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); | 169 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); |
| 145 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | 170 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 146 TraceConfigFromInvalidLegacyStrings); | 171 TraceConfigFromInvalidLegacyStrings); |
| 147 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); | 172 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); |
| 148 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); | 173 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); |
| 149 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); | 174 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); |
| 150 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | 175 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 151 IsEmptyOrContainsLeadingOrTrailingWhitespace); | 176 IsEmptyOrContainsLeadingOrTrailingWhitespace); |
| 177 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromMemoryConfigString); |
| 178 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, LegacyStringToMemoryDumpConfig); |
| 179 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, EmptyMemoryDumpConfigTest); |
| 152 | 180 |
| 153 // The default trace config, used when none is provided. | 181 // The default trace config, used when none is provided. |
| 154 // Allows all non-disabled-by-default categories through, except if they end | 182 // Allows all non-disabled-by-default categories through, except if they end |
| 155 // in the suffix 'Debug' or 'Test'. | 183 // in the suffix 'Debug' or 'Test'. |
| 156 void InitializeDefault(); | 184 void InitializeDefault(); |
| 157 | 185 |
| 158 // Initialize from the config string | 186 // Initialize from the config string |
| 159 void InitializeFromConfigString(const std::string& config_string); | 187 void InitializeFromConfigString(const std::string& config_string); |
| 160 | 188 |
| 161 // Initialize from category filter and trace options strings | 189 // Initialize from category filter and trace options strings |
| 162 void InitializeFromStrings(const std::string& category_filter_string, | 190 void InitializeFromStrings(const std::string& category_filter_string, |
| 163 const std::string& trace_options_string); | 191 const std::string& trace_options_string); |
| 164 | 192 |
| 165 void SetCategoriesFromIncludedList(const base::ListValue& included_list); | 193 void SetCategoriesFromIncludedList(const base::ListValue& included_list); |
| 166 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list); | 194 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list); |
| 167 void SetSyntheticDelaysFromList(const base::ListValue& list); | 195 void SetSyntheticDelaysFromList(const base::ListValue& list); |
| 168 void AddCategoryToDict(base::DictionaryValue& dict, | 196 void AddCategoryToDict(base::DictionaryValue& dict, |
| 169 const char* param, | 197 const char* param, |
| 170 const StringList& categories) const; | 198 const StringList& categories) const; |
| 171 | 199 |
| 200 void SetMemoryDumpConfig(const base::DictionaryValue& memory_dump_config); |
| 201 void SetDefaultMemoryDumpConfig(); |
| 202 |
| 172 // Convert TraceConfig to the dict representation of the TraceConfig. | 203 // Convert TraceConfig to the dict representation of the TraceConfig. |
| 173 void ToDict(base::DictionaryValue& dict) const; | 204 void ToDict(base::DictionaryValue& dict) const; |
| 174 | 205 |
| 175 std::string ToTraceOptionsString() const; | 206 std::string ToTraceOptionsString() const; |
| 176 | 207 |
| 177 void WriteCategoryFilterString(const StringList& values, | 208 void WriteCategoryFilterString(const StringList& values, |
| 178 std::string* out, | 209 std::string* out, |
| 179 bool included) const; | 210 bool included) const; |
| 180 void WriteCategoryFilterString(const StringList& delays, | 211 void WriteCategoryFilterString(const StringList& delays, |
| 181 std::string* out) const; | 212 std::string* out) const; |
| 182 | 213 |
| 183 // Returns true if category is enable according to this trace config. | 214 // Returns true if category is enable according to this trace config. |
| 184 bool IsCategoryEnabled(const char* category_name) const; | 215 bool IsCategoryEnabled(const char* category_name) const; |
| 185 | 216 |
| 186 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( | 217 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| 187 const std::string& str); | 218 const std::string& str); |
| 188 | 219 |
| 189 bool HasIncludedPatterns() const; | 220 bool HasIncludedPatterns() const; |
| 190 | 221 |
| 191 TraceRecordMode record_mode_; | 222 TraceRecordMode record_mode_; |
| 192 bool enable_sampling_ : 1; | 223 bool enable_sampling_ : 1; |
| 193 bool enable_systrace_ : 1; | 224 bool enable_systrace_ : 1; |
| 194 bool enable_argument_filter_ : 1; | 225 bool enable_argument_filter_ : 1; |
| 195 | 226 |
| 227 MemoryDumpConfig memory_dump_config_; |
| 228 |
| 196 StringList included_categories_; | 229 StringList included_categories_; |
| 197 StringList disabled_categories_; | 230 StringList disabled_categories_; |
| 198 StringList excluded_categories_; | 231 StringList excluded_categories_; |
| 199 StringList synthetic_delays_; | 232 StringList synthetic_delays_; |
| 200 }; | 233 }; |
| 201 | 234 |
| 202 } // namespace trace_event | 235 } // namespace trace_event |
| 203 } // namespace base | 236 } // namespace base |
| 204 | 237 |
| 205 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ | 238 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ |
| OLD | NEW |