Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1937)

Side by Side Diff: base/trace_event/trace_config.h

Issue 1115023003: [Startup Tracing] The TraceConfig class [STALE] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/trace_event/trace_config.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_H_
6 #define BASE_TRACE_EVENT_TRACE_CONFIG_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/gtest_prod_util.h"
12 #include "base/values.h"
13
14 namespace base {
15 namespace trace_event {
16
17 class CategoryFilter;
18
19 // Options determines how the trace buffer stores data.
20 enum TraceRecordMode {
21 // Record until the trace buffer is full.
22 RECORD_UNTIL_FULL,
23
24 // Record until the user ends the trace. The trace buffer is a fixed size
25 // and we use it as a ring buffer during recording.
26 RECORD_CONTINUOUSLY,
27
28 // Echo to console. Events are discarded.
29 ECHO_TO_CONSOLE,
30
31 // Record until the trace buffer is full, but with a huge buffer size.
32 RECORD_AS_MUCH_AS_POSSIBLE
33 };
34
35 struct BASE_EXPORT TraceOptions {
dsinclair 2015/05/25 13:36:02 Why a struct and not a class?
36 TraceOptions()
37 : record_mode(RECORD_UNTIL_FULL),
38 enable_sampling(false),
39 enable_systrace(false),
40 enable_argument_filter(false) {}
41
42 explicit TraceOptions(TraceRecordMode record_mode)
43 : record_mode(record_mode),
44 enable_sampling(false),
45 enable_systrace(false),
46 enable_argument_filter(false) {}
47
48 // |options_string| is a comma-delimited list of trace options.
49 // Possible options are: "record-until-full", "record-continuously",
50 // "trace-to-console", "enable-sampling" and "enable-systrace".
51 // The first 3 options are trace recoding modes and hence
52 // mutually exclusive. If more than one trace recording modes appear in the
53 // options_string, the last one takes precedence. If none of the trace
54 // recording mode is specified, recording mode is RECORD_UNTIL_FULL.
55 //
56 // The trace option will first be reset to the default option
57 // (record_mode set to RECORD_UNTIL_FULL, enable_sampling and enable_systrace
58 // set to false) before options parsed from |options_string| are applied on
59 // it.
60 // If |options_string| is invalid, the final state of trace_options is
61 // undefined.
62 //
63 // Example: trace_options.SetFromString("record-until-full")
64 // Example: trace_options.SetFromString(
65 // "record-continuously, enable-sampling")
66 // Example: trace_options.SetFromString("record-until-full, trace-to-console")
67 // will set ECHO_TO_CONSOLE as the recording mode.
68 //
69 // Returns true on success.
70 bool SetFromString(const std::string& options_string);
71
72 std::string ToString() const;
73
74 TraceRecordMode record_mode;
75 bool enable_sampling;
dsinclair 2015/05/25 13:36:02 Can you bit pack these please.
76 bool enable_systrace;
77 bool enable_argument_filter;
78 };
79
80 class BASE_EXPORT TraceConfig {
81 public:
82 typedef std::vector<std::string> StringList;
83
84 TraceConfig();
85
86 // Create TraceConfig object from CategoryFilter and TraceOptions.
87 TraceConfig(const CategoryFilter& cf, const TraceOptions& options);
88
89 // Create TraceConfig object from category filter and trace options strings.
90 TraceConfig(const std::string& category_filter_string,
91 const std::string& trace_options_string);
92
93 // |config_string| is a dictionary formatted as a JSON string, containing both
94 // category filters and trace options.
95 explicit TraceConfig(const std::string& config_string);
96
97 explicit TraceConfig(const TraceConfig& tc);
98
99 ~TraceConfig();
100
101 TraceConfig& operator=(const TraceConfig& rhs);
102
103 // Return a list of the synthetic delays specified in this category filter.
104 const StringList& GetSyntheticDelayValues() const;
105
106 // Writes the string representation of the TraceConfig. The string is JSON
107 // formatted.
108 std::string ToString() const;
109
110 // Write the string representation of the CategoryFilter part.
111 std::string ToCategoryFilterString() const;
112
113 // Write the string representation of the TraceOptions part.
114 std::string ToTraceOptionsString() const;
115
116 // Returns true if at least one category in the list is enabled by this
117 // trace config.
118 bool IsCategoryGroupEnabled(const char* category_group) const;
119
120 // Merges config with the current TraceConfig
121 void Merge(const TraceConfig& config);
122
123 void Clear();
124
125 private:
126 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyStrings);
127 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
128 TraceConfigFromInvalidLegacyStrings);
129 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig);
130 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString);
131 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString);
132 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
133 IsEmptyOrContainsLeadingOrTrailingWhitespace);
134 friend class CategoryFilter;
135
136 void Initialize(const std::string& config_string);
137
138 // The default trace config, used when none is provided.
139 // Allows all categories through, except if they end in the suffix 'Debug' or
140 // 'Test'.
141 void InitializeDefault();
142
143 void SetCategoriesFromList(StringList& categories,
144 const base::ListValue& list);
145 void SetSyntheticDelaysFromList(StringList& delays,
146 const base::ListValue& list);
147 void AddCategoryToDict(base::DictionaryValue& dict,
148 const char* param,
149 const StringList& categories) const;
150
151 // Returns true if category is enable according to this trace config.
152 bool IsCategoryEnabled(const char* category_name) const;
153
154 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
155 const std::string& str);
156
157 bool HasIncludedPatterns() const;
158
159 // Convert TraceConfig to the dict representation of the TraceConfig.
160 void ToDict(base::DictionaryValue& dict) const;
161
162 TraceRecordMode record_mode_;
163 bool enable_sampling_ : 1;
164 bool enable_systrace_ : 1;
165
166 StringList included_categories_;
167 StringList disabled_categories_;
168 StringList excluded_categories_;
169 StringList synthetic_delays_;
170 };
171
172 class BASE_EXPORT CategoryFilter {
173 public:
174 typedef std::vector<std::string> StringList;
175
176 // The default category filter, used when none is provided.
177 // Allows all categories through, except if they end in the suffix 'Debug' or
178 // 'Test'.
179 static const char kDefaultCategoryFilterString[];
180
181 // |filter_string| is a comma-delimited list of category wildcards.
182 // A category can have an optional '-' prefix to make it an excluded category.
183 // All the same rules apply above, so for example, having both included and
184 // excluded categories in the same list would not be supported.
185 //
186 // Example: CategoryFilter"test_MyTest*");
187 // Example: CategoryFilter("test_MyTest*,test_OtherStuff");
188 // Example: CategoryFilter("-excluded_category1,-excluded_category2");
189 // Example: CategoryFilter("-*,webkit"); would disable everything but webkit.
190 // Example: CategoryFilter("-webkit"); would enable everything but webkit.
191 //
192 // Category filters can also be used to configure synthetic delays.
193 //
194 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16)"); would make swap
195 // buffers always take at least 16 ms.
196 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16;oneshot)"); would
197 // make swap buffers take at least 16 ms the first time it is
198 // called.
199 // Example: CategoryFilter("DELAY(gpu.PresentingFrame;16;alternating)");
200 // would make swap buffers take at least 16 ms every other time it
201 // is called.
202 explicit CategoryFilter(const std::string& filter_string);
203
204 CategoryFilter();
205
206 CategoryFilter(const CategoryFilter& cf);
207
208 ~CategoryFilter();
209
210 CategoryFilter& operator=(const CategoryFilter& rhs);
211
212 // Writes the string representation of the CategoryFilter. This is a comma
213 // separated string, similar in nature to the one used to determine
214 // enabled/disabled category patterns, except here there is an arbitrary
215 // order, included categories go first, then excluded categories. Excluded
216 // categories are distinguished from included categories by the prefix '-'.
217 std::string ToString() const;
218
219 // Returns true if at least one category in the list is enabled by this
220 // category filter.
221 bool IsCategoryGroupEnabled(const char* category_group) const;
222
223 // Return a list of the synthetic delays specified in this category filter.
224 const StringList& GetSyntheticDelayValues() const;
225
226 // Merges nested_filter with the current CategoryFilter
227 void Merge(const CategoryFilter& nested_filter);
228
229 // Clears both included/excluded pattern lists. This would be equivalent to
230 // creating a CategoryFilter with an empty string, through the constructor.
231 // i.e: CategoryFilter().
232 //
233 // When using an empty filter, all categories are considered included as we
234 // are not excluding anything.
235 void Clear();
236
237 private:
238 FRIEND_TEST_ALL_PREFIXES(CategoryFilterTest, CategoryFilter);
239 friend class TraceConfig;
240
241 // Returns true if category is enable according to this filter.
242 bool IsCategoryEnabled(const char* category_name) const;
243
244 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
245 const std::string& str);
246
247 void Initialize(const std::string& filter_string);
248 void WriteString(const StringList& values,
249 std::string* out,
250 bool included) const;
251 void WriteString(const StringList& delays, std::string* out) const;
252 bool HasIncludedPatterns() const;
253
254 TraceConfig config_;
255 };
256
257 } // namespace trace_event
258 } // namespace base
259
260 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_config.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698