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

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

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 #include "base/trace_event/trace_config.h" 5 #include "base/trace_event/trace_config.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
(...skipping 26 matching lines...) Expand all
37 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; 37 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY(";
38 38
39 } // namespace 39 } // namespace
40 40
41 TraceConfig::TraceConfig() { 41 TraceConfig::TraceConfig() {
42 InitializeDefault(); 42 InitializeDefault();
43 } 43 }
44 44
45 TraceConfig::TraceConfig(const std::string& category_filter_string, 45 TraceConfig::TraceConfig(const std::string& category_filter_string,
46 const std::string& trace_options_string) { 46 const std::string& trace_options_string) {
47 if (!category_filter_string.empty()) { 47 InitializeFromStrings(category_filter_string, trace_options_string);
48 std::vector<std::string> split; 48 }
49 std::vector<std::string>::iterator iter; 49
50 base::SplitString(category_filter_string, ',', &split); 50 TraceConfig::TraceConfig(const std::string& category_filter_string,
51 for (iter = split.begin(); iter != split.end(); ++iter) { 51 TraceRecordMode record_mode) {
52 std::string category = *iter; 52 std::string trace_options_string;
53 // Ignore empty categories. 53 switch (record_mode) {
54 if (category.empty()) 54 case RECORD_UNTIL_FULL:
55 continue; 55 trace_options_string = kRecordUntilFull;
56 // Synthetic delays are of the form 'DELAY(delay;option;option;...)'. 56 break;
57 if (category.find(kSyntheticDelayCategoryFilterPrefix) == 0 && 57 case RECORD_CONTINUOUSLY:
58 category.at(category.size() - 1) == ')') { 58 trace_options_string = kRecordContinuously;
59 category = category.substr( 59 break;
60 strlen(kSyntheticDelayCategoryFilterPrefix), 60 case ECHO_TO_CONSOLE:
dsinclair 2015/06/02 13:56:55 Put this one below RECORD_AS_MUCH_AS_POSSIBLE so w
Zhen Wang 2015/06/02 16:24:42 Done. I also updated the order in the header file
61 category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1); 61 trace_options_string = kTraceToConsole;
62 size_t name_length = category.find(';'); 62 break;
63 if (name_length != std::string::npos && name_length > 0 && 63 case RECORD_AS_MUCH_AS_POSSIBLE:
64 name_length != category.size() - 1) { 64 trace_options_string = kRecordAsMuchAsPossible;
65 synthetic_delays_.push_back(category); 65 break;
66 } 66 default:
67 } else if (category.at(0) == '-') { 67 NOTREACHED();
68 // Excluded categories start with '-'.
69 // Remove '-' from category string.
70 category = category.substr(1);
71 excluded_categories_.push_back(category);
72 } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")),
73 TRACE_DISABLED_BY_DEFAULT("")) == 0) {
74 disabled_categories_.push_back(category);
75 } else {
76 included_categories_.push_back(category);
77 }
78 }
79 } 68 }
80 69 InitializeFromStrings(category_filter_string, trace_options_string);
81 record_mode_ = RECORD_UNTIL_FULL;
82 enable_sampling_ = false;
83 enable_systrace_ = false;
84 enable_argument_filter_ = false;
85 if(!trace_options_string.empty()) {
86 std::vector<std::string> split;
87 std::vector<std::string>::iterator iter;
88 base::SplitString(trace_options_string, ',', &split);
89 for (iter = split.begin(); iter != split.end(); ++iter) {
90 if (*iter == kRecordUntilFull) {
91 record_mode_ = RECORD_UNTIL_FULL;
92 } else if (*iter == kRecordContinuously) {
93 record_mode_ = RECORD_CONTINUOUSLY;
94 } else if (*iter == kTraceToConsole) {
95 record_mode_ = ECHO_TO_CONSOLE;
96 } else if (*iter == kRecordAsMuchAsPossible) {
97 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE;
98 } else if (*iter == kEnableSampling) {
99 enable_sampling_ = true;
100 } else if (*iter == kEnableSystrace) {
101 enable_systrace_ = true;
102 } else if (*iter == kEnableArgumentFilter) {
103 enable_argument_filter_ = true;
104 }
105 }
106 }
107 } 70 }
108 71
109 TraceConfig::TraceConfig(const std::string& config_string) { 72 TraceConfig::TraceConfig(const std::string& config_string) {
110 if (!config_string.empty()) 73 if (!config_string.empty())
111 Initialize(config_string); 74 InitializeFromConfigString(config_string);
112 else 75 else
113 InitializeDefault(); 76 InitializeDefault();
114 } 77 }
115 78
116 TraceConfig::TraceConfig(const TraceConfig& tc) 79 TraceConfig::TraceConfig(const TraceConfig& tc)
117 : record_mode_(tc.record_mode_), 80 : record_mode_(tc.record_mode_),
118 enable_sampling_(tc.enable_sampling_), 81 enable_sampling_(tc.enable_sampling_),
119 enable_systrace_(tc.enable_systrace_), 82 enable_systrace_(tc.enable_systrace_),
120 enable_argument_filter_(tc.enable_argument_filter_), 83 enable_argument_filter_(tc.enable_argument_filter_),
121 included_categories_(tc.included_categories_), 84 included_categories_(tc.included_categories_),
(...skipping 17 matching lines...) Expand all
139 disabled_categories_ = rhs.disabled_categories_; 102 disabled_categories_ = rhs.disabled_categories_;
140 excluded_categories_ = rhs.excluded_categories_; 103 excluded_categories_ = rhs.excluded_categories_;
141 synthetic_delays_ = rhs.synthetic_delays_; 104 synthetic_delays_ = rhs.synthetic_delays_;
142 return *this; 105 return *this;
143 } 106 }
144 107
145 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const { 108 const TraceConfig::StringList& TraceConfig::GetSyntheticDelayValues() const {
146 return synthetic_delays_; 109 return synthetic_delays_;
147 } 110 }
148 111
112 TraceRecordMode TraceConfig::GetTraceRecordMode() const {
113 return record_mode_;
dsinclair 2015/06/02 13:56:55 These can all be implemented in the header.
Zhen Wang 2015/06/02 16:24:42 Done.
114 }
115
116 bool TraceConfig::IsSamplingEnabled() const {
117 return enable_sampling_;
118 }
119
120 bool TraceConfig::IsSystraceEnabled() const {
121 return enable_systrace_;
122 }
123
124 bool TraceConfig::IsArgumentFilterEnabled() const {
125 return enable_argument_filter_;
126 }
127
128 void TraceConfig::SetTraceRecordMode(TraceRecordMode mode) {
129 record_mode_ = mode;
130 }
131
132 void TraceConfig::EnableSampling() {
133 enable_sampling_ = true;
134 }
135
136 void TraceConfig::EnableSystrace() {
137 enable_systrace_ = true;
138 }
139
149 std::string TraceConfig::ToString() const { 140 std::string TraceConfig::ToString() const {
150 base::DictionaryValue dict; 141 base::DictionaryValue dict;
151 ToDict(dict); 142 ToDict(dict);
152 143
153 std::string json; 144 std::string json;
154 base::JSONWriter::Write(dict, &json); 145 base::JSONWriter::Write(dict, &json);
155 146
156 return json; 147 return json;
157 } 148 }
158 149
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 258
268 void TraceConfig::InitializeDefault() { 259 void TraceConfig::InitializeDefault() {
269 record_mode_ = RECORD_UNTIL_FULL; 260 record_mode_ = RECORD_UNTIL_FULL;
270 enable_sampling_ = false; 261 enable_sampling_ = false;
271 enable_systrace_ = false; 262 enable_systrace_ = false;
272 enable_argument_filter_ = false; 263 enable_argument_filter_ = false;
273 excluded_categories_.push_back("*Debug"); 264 excluded_categories_.push_back("*Debug");
274 excluded_categories_.push_back("*Test"); 265 excluded_categories_.push_back("*Test");
275 } 266 }
276 267
277 void TraceConfig::Initialize(const std::string& config_string) { 268 void TraceConfig::InitializeFromConfigString(const std::string& config_string) {
278 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string)); 269 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string));
279 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { 270 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) {
280 InitializeDefault(); 271 InitializeDefault();
281 return; 272 return;
282 } 273 }
283 scoped_ptr<base::DictionaryValue> dict( 274 scoped_ptr<base::DictionaryValue> dict(
284 static_cast<base::DictionaryValue*>(value.release())); 275 static_cast<base::DictionaryValue*>(value.release()));
285 276
286 record_mode_ = RECORD_UNTIL_FULL; 277 record_mode_ = RECORD_UNTIL_FULL;
287 std::string record_mode; 278 std::string record_mode;
(...skipping 30 matching lines...) Expand all
318 309
319 base::ListValue* category_list = NULL; 310 base::ListValue* category_list = NULL;
320 if (dict->GetList(kIncludedCategoriesParam, &category_list)) 311 if (dict->GetList(kIncludedCategoriesParam, &category_list))
321 SetCategoriesFromIncludedList(*category_list); 312 SetCategoriesFromIncludedList(*category_list);
322 if (dict->GetList(kExcludedCategoriesParam, &category_list)) 313 if (dict->GetList(kExcludedCategoriesParam, &category_list))
323 SetCategoriesFromExcludedList(*category_list); 314 SetCategoriesFromExcludedList(*category_list);
324 if (dict->GetList(kSyntheticDelaysParam, &category_list)) 315 if (dict->GetList(kSyntheticDelaysParam, &category_list))
325 SetSyntheticDelaysFromList(*category_list); 316 SetSyntheticDelaysFromList(*category_list);
326 } 317 }
327 318
319 void TraceConfig::InitializeFromStrings(
320 const std::string& category_filter_string,
321 const std::string& trace_options_string) {
322 if (!category_filter_string.empty()) {
323 std::vector<std::string> split;
324 std::vector<std::string>::iterator iter;
325 base::SplitString(category_filter_string, ',', &split);
326 for (iter = split.begin(); iter != split.end(); ++iter) {
327 std::string category = *iter;
328 // Ignore empty categories.
329 if (category.empty())
330 continue;
331 // Synthetic delays are of the form 'DELAY(delay;option;option;...)'.
332 if (category.find(kSyntheticDelayCategoryFilterPrefix) == 0 &&
333 category.at(category.size() - 1) == ')') {
334 category = category.substr(
335 strlen(kSyntheticDelayCategoryFilterPrefix),
336 category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1);
337 size_t name_length = category.find(';');
338 if (name_length != std::string::npos && name_length > 0 &&
339 name_length != category.size() - 1) {
340 synthetic_delays_.push_back(category);
341 }
342 } else if (category.at(0) == '-') {
343 // Excluded categories start with '-'.
344 // Remove '-' from category string.
345 category = category.substr(1);
346 excluded_categories_.push_back(category);
347 } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")),
348 TRACE_DISABLED_BY_DEFAULT("")) == 0) {
349 disabled_categories_.push_back(category);
350 } else {
351 included_categories_.push_back(category);
352 }
353 }
354 }
355
356 record_mode_ = RECORD_UNTIL_FULL;
357 enable_sampling_ = false;
358 enable_systrace_ = false;
359 enable_argument_filter_ = false;
360 if(!trace_options_string.empty()) {
361 std::vector<std::string> split;
362 std::vector<std::string>::iterator iter;
363 base::SplitString(trace_options_string, ',', &split);
364 for (iter = split.begin(); iter != split.end(); ++iter) {
365 if (*iter == kRecordUntilFull) {
366 record_mode_ = RECORD_UNTIL_FULL;
367 } else if (*iter == kRecordContinuously) {
368 record_mode_ = RECORD_CONTINUOUSLY;
369 } else if (*iter == kTraceToConsole) {
370 record_mode_ = ECHO_TO_CONSOLE;
371 } else if (*iter == kRecordAsMuchAsPossible) {
372 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE;
373 } else if (*iter == kEnableSampling) {
374 enable_sampling_ = true;
375 } else if (*iter == kEnableSystrace) {
376 enable_systrace_ = true;
377 } else if (*iter == kEnableArgumentFilter) {
378 enable_argument_filter_ = true;
379 }
380 }
381 }
382 }
383
328 void TraceConfig::SetCategoriesFromIncludedList( 384 void TraceConfig::SetCategoriesFromIncludedList(
329 const base::ListValue& included_list) { 385 const base::ListValue& included_list) {
330 included_categories_.clear(); 386 included_categories_.clear();
331 for (size_t i = 0; i < included_list.GetSize(); ++i) { 387 for (size_t i = 0; i < included_list.GetSize(); ++i) {
332 std::string category; 388 std::string category;
333 if (!included_list.GetString(i, &category)) 389 if (!included_list.GetString(i, &category))
334 continue; 390 continue;
335 if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), 391 if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")),
336 TRACE_DISABLED_BY_DEFAULT("")) == 0) { 392 TRACE_DISABLED_BY_DEFAULT("")) == 0) {
337 disabled_categories_.push_back(category); 393 disabled_categories_.push_back(category);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 StringList categories(included_categories_); 474 StringList categories(included_categories_);
419 categories.insert(categories.end(), 475 categories.insert(categories.end(),
420 disabled_categories_.begin(), 476 disabled_categories_.begin(),
421 disabled_categories_.end()); 477 disabled_categories_.end());
422 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); 478 AddCategoryToDict(dict, kIncludedCategoriesParam, categories);
423 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); 479 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_);
424 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); 480 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_);
425 } 481 }
426 482
427 std::string TraceConfig::ToTraceOptionsString() const { 483 std::string TraceConfig::ToTraceOptionsString() const {
428 TraceOptions to; 484 std::string ret;
429 to.record_mode = record_mode_; 485 switch (record_mode_) {
430 to.enable_sampling = enable_sampling_; 486 case RECORD_UNTIL_FULL:
431 to.enable_systrace = enable_systrace_; 487 ret = kRecordUntilFull;
432 to.enable_argument_filter = enable_argument_filter_; 488 break;
433 return to.ToString(); 489 case RECORD_CONTINUOUSLY:
490 ret = kRecordContinuously;
491 break;
492 case ECHO_TO_CONSOLE:
493 ret = kTraceToConsole;
494 break;
495 case RECORD_AS_MUCH_AS_POSSIBLE:
496 ret = kRecordAsMuchAsPossible;
497 break;
498 default:
499 NOTREACHED();
500 }
501 if (enable_sampling_)
502 ret = ret + "," + kEnableSampling;
503 if (enable_systrace_)
504 ret = ret + "," + kEnableSystrace;
505 if (enable_argument_filter_)
506 ret = ret + "," + kEnableArgumentFilter;
507 return ret;
434 } 508 }
435 509
436 void TraceConfig::WriteCategoryFilterString(const StringList& values, 510 void TraceConfig::WriteCategoryFilterString(const StringList& values,
437 std::string* out, 511 std::string* out,
438 bool included) const { 512 bool included) const {
439 bool prepend_comma = !out->empty(); 513 bool prepend_comma = !out->empty();
440 int token_cnt = 0; 514 int token_cnt = 0;
441 for (StringList::const_iterator ci = values.begin(); 515 for (StringList::const_iterator ci = values.begin();
442 ci != values.end(); ++ci) { 516 ci != values.end(); ++ci) {
443 if (token_cnt > 0 || prepend_comma) 517 if (token_cnt > 0 || prepend_comma)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 str.at(0) == ' ' || 566 str.at(0) == ' ' ||
493 str.at(str.length() - 1) == ' '; 567 str.at(str.length() - 1) == ' ';
494 } 568 }
495 569
496 bool TraceConfig::HasIncludedPatterns() const { 570 bool TraceConfig::HasIncludedPatterns() const {
497 return !included_categories_.empty(); 571 return !included_categories_.empty();
498 } 572 }
499 573
500 } // namespace trace_event 574 } // namespace trace_event
501 } // namespace base 575 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698