Chromium Code Reviews| 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 // DISABLED_BY_DEFAULT("memory-infra") category is enabled. | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
I'd just say "memory-infra" category, so if tomorr
ssid
2015/08/24 15:29:31
Done.
| |
| 41 struct MemoryDumpConfig { | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
Shouldn't this be named MemoryDumpTriggerConfig?
ssid
2015/08/24 15:29:31
Done.
| |
| 42 uint32 periodic_interval_ms; | |
| 43 MemoryDumpArgs::LevelOfDetail dump_level_of_detail; | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
i'd omit the "dump_" part in the name (i.e. just l
ssid
2015/08/24 15:29:31
Done.
| |
| 44 }; | |
| 45 | |
| 46 typedef std::vector<MemoryDumpConfig> MemoryDumpConfigList; | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
And this just MemoryDumpConfig?
ssid
2015/08/24 15:29:31
Done.
| |
| 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 // "dump_type": "heavy", | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
Why not "level_of_detail"? So it is consistent wit
ssid
2015/08/24 15:29:31
Done.
| |
| 119 // "periodic_interval_ms": 2000 | |
| 120 // } | |
| 121 // ] | |
| 122 // } | |
| 105 // } | 123 // } |
| 106 explicit TraceConfig(const std::string& config_string); | 124 explicit TraceConfig(const std::string& config_string); |
| 107 | 125 |
| 108 TraceConfig(const TraceConfig& tc); | 126 TraceConfig(const TraceConfig& tc); |
| 109 | 127 |
| 110 ~TraceConfig(); | 128 ~TraceConfig(); |
| 111 | 129 |
| 112 TraceConfig& operator=(const TraceConfig& rhs); | 130 TraceConfig& operator=(const TraceConfig& rhs); |
| 113 | 131 |
| 114 // Return a list of the synthetic delays specified in this category filter. | 132 // Return a list of the synthetic delays specified in this category filter. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 133 | 151 |
| 134 // Returns true if at least one category in the list is enabled by this | 152 // Returns true if at least one category in the list is enabled by this |
| 135 // trace config. | 153 // trace config. |
| 136 bool IsCategoryGroupEnabled(const char* category_group) const; | 154 bool IsCategoryGroupEnabled(const char* category_group) const; |
| 137 | 155 |
| 138 // Merges config with the current TraceConfig | 156 // Merges config with the current TraceConfig |
| 139 void Merge(const TraceConfig& config); | 157 void Merge(const TraceConfig& config); |
| 140 | 158 |
| 141 void Clear(); | 159 void Clear(); |
| 142 | 160 |
| 161 const MemoryDumpConfigList& memory_dump_config_list() const { | |
| 162 return memory_dump_config_list_; | |
| 163 } | |
| 164 | |
| 143 private: | 165 private: |
| 144 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); | 166 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat); |
| 145 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | 167 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 146 TraceConfigFromInvalidLegacyStrings); | 168 TraceConfigFromInvalidLegacyStrings); |
| 147 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); | 169 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); |
| 148 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); | 170 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); |
| 149 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); | 171 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); |
| 150 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, | 172 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 151 IsEmptyOrContainsLeadingOrTrailingWhitespace); | 173 IsEmptyOrContainsLeadingOrTrailingWhitespace); |
| 174 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromMemoryConfigString); | |
| 175 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, InvalidMemoryConfigString); | |
| 152 | 176 |
| 153 // The default trace config, used when none is provided. | 177 // The default trace config, used when none is provided. |
| 154 // Allows all non-disabled-by-default categories through, except if they end | 178 // Allows all non-disabled-by-default categories through, except if they end |
| 155 // in the suffix 'Debug' or 'Test'. | 179 // in the suffix 'Debug' or 'Test'. |
| 156 void InitializeDefault(); | 180 void InitializeDefault(); |
| 157 | 181 |
| 158 // Initialize from the config string | 182 // Initialize from the config string |
| 159 void InitializeFromConfigString(const std::string& config_string); | 183 void InitializeFromConfigString(const std::string& config_string); |
| 160 | 184 |
| 161 // Initialize from category filter and trace options strings | 185 // Initialize from category filter and trace options strings |
| 162 void InitializeFromStrings(const std::string& category_filter_string, | 186 void InitializeFromStrings(const std::string& category_filter_string, |
| 163 const std::string& trace_options_string); | 187 const std::string& trace_options_string); |
| 164 | 188 |
| 165 void SetCategoriesFromIncludedList(const base::ListValue& included_list); | 189 void SetCategoriesFromIncludedList(const base::ListValue& included_list); |
| 166 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list); | 190 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list); |
| 167 void SetSyntheticDelaysFromList(const base::ListValue& list); | 191 void SetSyntheticDelaysFromList(const base::ListValue& list); |
| 168 void AddCategoryToDict(base::DictionaryValue& dict, | 192 void AddCategoryToDict(base::DictionaryValue& dict, |
| 169 const char* param, | 193 const char* param, |
| 170 const StringList& categories) const; | 194 const StringList& categories) const; |
| 171 | 195 |
| 196 void SetMemoryDumpConfigList(base::DictionaryValue& memory_dump_config); | |
|
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
+const base::....
Primiano Tucci (use gerrit)
2015/08/24 11:58:36
Shouldn't this be just SetMemoryDumpConfig (withou
ssid
2015/08/24 15:29:31
Done.
| |
| 197 | |
| 172 // Convert TraceConfig to the dict representation of the TraceConfig. | 198 // Convert TraceConfig to the dict representation of the TraceConfig. |
| 173 void ToDict(base::DictionaryValue& dict) const; | 199 void ToDict(base::DictionaryValue& dict) const; |
| 174 | 200 |
| 175 std::string ToTraceOptionsString() const; | 201 std::string ToTraceOptionsString() const; |
| 176 | 202 |
| 177 void WriteCategoryFilterString(const StringList& values, | 203 void WriteCategoryFilterString(const StringList& values, |
| 178 std::string* out, | 204 std::string* out, |
| 179 bool included) const; | 205 bool included) const; |
| 180 void WriteCategoryFilterString(const StringList& delays, | 206 void WriteCategoryFilterString(const StringList& delays, |
| 181 std::string* out) const; | 207 std::string* out) const; |
| 182 | 208 |
| 183 // Returns true if category is enable according to this trace config. | 209 // Returns true if category is enable according to this trace config. |
| 184 bool IsCategoryEnabled(const char* category_name) const; | 210 bool IsCategoryEnabled(const char* category_name) const; |
| 185 | 211 |
| 186 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( | 212 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| 187 const std::string& str); | 213 const std::string& str); |
| 188 | 214 |
| 189 bool HasIncludedPatterns() const; | 215 bool HasIncludedPatterns() const; |
| 190 | 216 |
| 191 TraceRecordMode record_mode_; | 217 TraceRecordMode record_mode_; |
| 192 bool enable_sampling_ : 1; | 218 bool enable_sampling_ : 1; |
| 193 bool enable_systrace_ : 1; | 219 bool enable_systrace_ : 1; |
| 194 bool enable_argument_filter_ : 1; | 220 bool enable_argument_filter_ : 1; |
| 195 | 221 |
| 222 MemoryDumpConfigList memory_dump_config_list_; | |
| 223 | |
| 196 StringList included_categories_; | 224 StringList included_categories_; |
| 197 StringList disabled_categories_; | 225 StringList disabled_categories_; |
| 198 StringList excluded_categories_; | 226 StringList excluded_categories_; |
| 199 StringList synthetic_delays_; | 227 StringList synthetic_delays_; |
| 200 }; | 228 }; |
| 201 | 229 |
| 202 } // namespace trace_event | 230 } // namespace trace_event |
| 203 } // namespace base | 231 } // namespace base |
| 204 | 232 |
| 205 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ | 233 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ |
| OLD | NEW |