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

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

Issue 1165673002: [Startup Tracing] Hook up TraceConfig and remove CategoryFilter & TraceOptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
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/category_filter.h"
14 #include "base/trace_event/trace_options.h"
15 #include "base/values.h" 13 #include "base/values.h"
16 14
17 namespace base { 15 namespace base {
18 namespace trace_event { 16 namespace trace_event {
19 17
20 class CategoryFilter; 18 // Options determines how the trace buffer stores data.
19 enum TraceRecordMode {
20 // Record until the trace buffer is full.
21 RECORD_UNTIL_FULL,
22
23 // 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 RECORD_CONTINUOUSLY,
26
27 // Echo to console. Events are discarded.
28 ECHO_TO_CONSOLE,
29
30 // Record until the trace buffer is full, but with a huge buffer size.
31 RECORD_AS_MUCH_AS_POSSIBLE
32 };
21 33
22 class BASE_EXPORT TraceConfig { 34 class BASE_EXPORT TraceConfig {
23 public: 35 public:
24 typedef std::vector<std::string> StringList; 36 typedef std::vector<std::string> StringList;
25 37
26 TraceConfig(); 38 TraceConfig();
27 39
28 // Create TraceConfig object from category filter and trace options strings. 40 // Create TraceConfig object from category filter and trace options strings.
29 // 41 //
30 // |category_filter_string| is a comma-delimited list of category wildcards. 42 // |category_filter_string| is a comma-delimited list of category wildcards.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // default options. 76 // default options.
65 // Example: TraceConfig("DELAY(gpu.PresentingFrame;16;oneshot)", ""); 77 // Example: TraceConfig("DELAY(gpu.PresentingFrame;16;oneshot)", "");
66 // would make swap buffers take at least 16 ms the first time it is 78 // would make swap buffers take at least 16 ms the first time it is
67 // called; and use default options. 79 // called; and use default options.
68 // Example: TraceConfig("DELAY(gpu.PresentingFrame;16;alternating)", ""); 80 // Example: TraceConfig("DELAY(gpu.PresentingFrame;16;alternating)", "");
69 // would make swap buffers take at least 16 ms every other time it 81 // would make swap buffers take at least 16 ms every other time it
70 // is called; and use default options. 82 // is called; and use default options.
71 TraceConfig(const std::string& category_filter_string, 83 TraceConfig(const std::string& category_filter_string,
72 const std::string& trace_options_string); 84 const std::string& trace_options_string);
73 85
86 TraceConfig(const std::string& category_filter_string,
87 TraceRecordMode record_mode);
88
74 // Create TraceConfig object from the trace config string. 89 // Create TraceConfig object from the trace config string.
75 // 90 //
76 // |config_string| is a dictionary formatted as a JSON string, containing both 91 // |config_string| is a dictionary formatted as a JSON string, containing both
77 // category filters and trace options. 92 // category filters and trace options.
78 // 93 //
79 // Example: 94 // Example:
80 // { 95 // {
81 // "record_mode": "record-continuously", 96 // "record_mode": "record-continuously",
82 // "enable_sampling": true, 97 // "enable_sampling": true,
83 // "enable_systrace": true, 98 // "enable_systrace": true,
84 // "enable_argument_filter": true, 99 // "enable_argument_filter": true,
85 // "included_categories": ["included", 100 // "included_categories": ["included",
86 // "inc_pattern*", 101 // "inc_pattern*",
87 // "disabled-by-default-category1"], 102 // "disabled-by-default-category1"],
88 // "excluded_categories": ["excluded", "exc_pattern*"], 103 // "excluded_categories": ["excluded", "exc_pattern*"],
89 // "synthetic_delays": ["test.Delay1;16", "test.Delay2;32"] 104 // "synthetic_delays": ["test.Delay1;16", "test.Delay2;32"]
90 // } 105 // }
91 explicit TraceConfig(const std::string& config_string); 106 explicit TraceConfig(const std::string& config_string);
92 107
108 TraceConfig(const TraceConfig& tc);
109
93 ~TraceConfig(); 110 ~TraceConfig();
94 111
112 TraceConfig& operator=(const TraceConfig& rhs);
113
95 // Return a list of the synthetic delays specified in this category filter. 114 // Return a list of the synthetic delays specified in this category filter.
96 const StringList& GetSyntheticDelayValues() const; 115 const StringList& GetSyntheticDelayValues() const;
97 116
117 TraceRecordMode GetTraceRecordMode() const;
118 bool IsSamplingEnabled() const;
119 bool IsSystraceEnabled() const;
120 bool IsArgumentFilterEnabled() const;
121
122 void SetTraceRecordMode(TraceRecordMode mode);
123 void EnableSampling();
124 void EnableSystrace();
125
98 // Writes the string representation of the TraceConfig. The string is JSON 126 // Writes the string representation of the TraceConfig. The string is JSON
99 // formatted. 127 // formatted.
100 std::string ToString() const; 128 std::string ToString() const;
101 129
102 // Write the string representation of the CategoryFilter part. 130 // Write the string representation of the CategoryFilter part.
103 std::string ToCategoryFilterString() const; 131 std::string ToCategoryFilterString() const;
104 132
105 // Returns true if at least one category in the list is enabled by this 133 // Returns true if at least one category in the list is enabled by this
106 // trace config. 134 // trace config.
107 bool IsCategoryGroupEnabled(const char* category_group) const; 135 bool IsCategoryGroupEnabled(const char* category_group) const;
108 136
109 // Merges config with the current TraceConfig 137 // Merges config with the current TraceConfig
110 void Merge(const TraceConfig& config); 138 void Merge(const TraceConfig& config);
111 139
112 void Clear(); 140 void Clear();
113 141
114 private: 142 private:
115 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyStrings); 143 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyFormat);
116 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, 144 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
117 TraceConfigFromInvalidLegacyStrings); 145 TraceConfigFromInvalidLegacyStrings);
118 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); 146 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig);
119 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); 147 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString);
120 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); 148 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString);
121 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, MergingTraceConfigs);
122 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, IsCategoryGroupEnabled);
123 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, 149 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest,
124 IsEmptyOrContainsLeadingOrTrailingWhitespace); 150 IsEmptyOrContainsLeadingOrTrailingWhitespace);
125 friend class CategoryFilter;
126
127 // TODO(zhenw): remove COPY and ASSIGN after CategoryFilter is removed.
128 explicit TraceConfig(const TraceConfig& tc);
129 TraceConfig& operator=(const TraceConfig& rhs);
130 151
131 // The default trace config, used when none is provided. 152 // The default trace config, used when none is provided.
132 // Allows all non-disabled-by-default categories through, except if they end 153 // Allows all non-disabled-by-default categories through, except if they end
133 // in the suffix 'Debug' or 'Test'. 154 // in the suffix 'Debug' or 'Test'.
134 void InitializeDefault(); 155 void InitializeDefault();
135 156
136 void Initialize(const std::string& config_string); 157 // Initialize from the config string
158 void InitializeFromConfigString(const std::string& config_string);
159
160 // Initialize from category filter and trace options strings
161 void InitializeFromStrings(const std::string& category_filter_string,
162 const std::string& trace_options_string);
137 163
138 void SetCategoriesFromIncludedList(const base::ListValue& included_list); 164 void SetCategoriesFromIncludedList(const base::ListValue& included_list);
139 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list); 165 void SetCategoriesFromExcludedList(const base::ListValue& excluded_list);
140 void SetSyntheticDelaysFromList(const base::ListValue& list); 166 void SetSyntheticDelaysFromList(const base::ListValue& list);
141 void AddCategoryToDict(base::DictionaryValue& dict, 167 void AddCategoryToDict(base::DictionaryValue& dict,
142 const char* param, 168 const char* param,
143 const StringList& categories) const; 169 const StringList& categories) const;
144 170
145 // Convert TraceConfig to the dict representation of the TraceConfig. 171 // Convert TraceConfig to the dict representation of the TraceConfig.
146 void ToDict(base::DictionaryValue& dict) const; 172 void ToDict(base::DictionaryValue& dict) const;
(...skipping 22 matching lines...) Expand all
169 StringList included_categories_; 195 StringList included_categories_;
170 StringList disabled_categories_; 196 StringList disabled_categories_;
171 StringList excluded_categories_; 197 StringList excluded_categories_;
172 StringList synthetic_delays_; 198 StringList synthetic_delays_;
173 }; 199 };
174 200
175 } // namespace trace_event 201 } // namespace trace_event
176 } // namespace base 202 } // namespace base
177 203
178 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_ 204 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698