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 #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 Loading... |
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 RECORD_AS_MUCH_AS_POSSIBLE: |
61 category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1); | 61 trace_options_string = kRecordAsMuchAsPossible; |
62 size_t name_length = category.find(';'); | 62 break; |
63 if (name_length != std::string::npos && name_length > 0 && | 63 case ECHO_TO_CONSOLE: |
64 name_length != category.size() - 1) { | 64 trace_options_string = kTraceToConsole; |
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 230 |
268 void TraceConfig::InitializeDefault() { | 231 void TraceConfig::InitializeDefault() { |
269 record_mode_ = RECORD_UNTIL_FULL; | 232 record_mode_ = RECORD_UNTIL_FULL; |
270 enable_sampling_ = false; | 233 enable_sampling_ = false; |
271 enable_systrace_ = false; | 234 enable_systrace_ = false; |
272 enable_argument_filter_ = false; | 235 enable_argument_filter_ = false; |
273 excluded_categories_.push_back("*Debug"); | 236 excluded_categories_.push_back("*Debug"); |
274 excluded_categories_.push_back("*Test"); | 237 excluded_categories_.push_back("*Test"); |
275 } | 238 } |
276 | 239 |
277 void TraceConfig::Initialize(const std::string& config_string) { | 240 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
278 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string)); | 241 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string)); |
279 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { | 242 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
280 InitializeDefault(); | 243 InitializeDefault(); |
281 return; | 244 return; |
282 } | 245 } |
283 scoped_ptr<base::DictionaryValue> dict( | 246 scoped_ptr<base::DictionaryValue> dict( |
284 static_cast<base::DictionaryValue*>(value.release())); | 247 static_cast<base::DictionaryValue*>(value.release())); |
285 | 248 |
286 record_mode_ = RECORD_UNTIL_FULL; | 249 record_mode_ = RECORD_UNTIL_FULL; |
287 std::string record_mode; | 250 std::string record_mode; |
(...skipping 30 matching lines...) Expand all Loading... |
318 | 281 |
319 base::ListValue* category_list = NULL; | 282 base::ListValue* category_list = NULL; |
320 if (dict->GetList(kIncludedCategoriesParam, &category_list)) | 283 if (dict->GetList(kIncludedCategoriesParam, &category_list)) |
321 SetCategoriesFromIncludedList(*category_list); | 284 SetCategoriesFromIncludedList(*category_list); |
322 if (dict->GetList(kExcludedCategoriesParam, &category_list)) | 285 if (dict->GetList(kExcludedCategoriesParam, &category_list)) |
323 SetCategoriesFromExcludedList(*category_list); | 286 SetCategoriesFromExcludedList(*category_list); |
324 if (dict->GetList(kSyntheticDelaysParam, &category_list)) | 287 if (dict->GetList(kSyntheticDelaysParam, &category_list)) |
325 SetSyntheticDelaysFromList(*category_list); | 288 SetSyntheticDelaysFromList(*category_list); |
326 } | 289 } |
327 | 290 |
| 291 void TraceConfig::InitializeFromStrings( |
| 292 const std::string& category_filter_string, |
| 293 const std::string& trace_options_string) { |
| 294 if (!category_filter_string.empty()) { |
| 295 std::vector<std::string> split; |
| 296 std::vector<std::string>::iterator iter; |
| 297 base::SplitString(category_filter_string, ',', &split); |
| 298 for (iter = split.begin(); iter != split.end(); ++iter) { |
| 299 std::string category = *iter; |
| 300 // Ignore empty categories. |
| 301 if (category.empty()) |
| 302 continue; |
| 303 // Synthetic delays are of the form 'DELAY(delay;option;option;...)'. |
| 304 if (category.find(kSyntheticDelayCategoryFilterPrefix) == 0 && |
| 305 category.at(category.size() - 1) == ')') { |
| 306 category = category.substr( |
| 307 strlen(kSyntheticDelayCategoryFilterPrefix), |
| 308 category.size() - strlen(kSyntheticDelayCategoryFilterPrefix) - 1); |
| 309 size_t name_length = category.find(';'); |
| 310 if (name_length != std::string::npos && name_length > 0 && |
| 311 name_length != category.size() - 1) { |
| 312 synthetic_delays_.push_back(category); |
| 313 } |
| 314 } else if (category.at(0) == '-') { |
| 315 // Excluded categories start with '-'. |
| 316 // Remove '-' from category string. |
| 317 category = category.substr(1); |
| 318 excluded_categories_.push_back(category); |
| 319 } else if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), |
| 320 TRACE_DISABLED_BY_DEFAULT("")) == 0) { |
| 321 disabled_categories_.push_back(category); |
| 322 } else { |
| 323 included_categories_.push_back(category); |
| 324 } |
| 325 } |
| 326 } |
| 327 |
| 328 record_mode_ = RECORD_UNTIL_FULL; |
| 329 enable_sampling_ = false; |
| 330 enable_systrace_ = false; |
| 331 enable_argument_filter_ = false; |
| 332 if(!trace_options_string.empty()) { |
| 333 std::vector<std::string> split; |
| 334 std::vector<std::string>::iterator iter; |
| 335 base::SplitString(trace_options_string, ',', &split); |
| 336 for (iter = split.begin(); iter != split.end(); ++iter) { |
| 337 if (*iter == kRecordUntilFull) { |
| 338 record_mode_ = RECORD_UNTIL_FULL; |
| 339 } else if (*iter == kRecordContinuously) { |
| 340 record_mode_ = RECORD_CONTINUOUSLY; |
| 341 } else if (*iter == kTraceToConsole) { |
| 342 record_mode_ = ECHO_TO_CONSOLE; |
| 343 } else if (*iter == kRecordAsMuchAsPossible) { |
| 344 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
| 345 } else if (*iter == kEnableSampling) { |
| 346 enable_sampling_ = true; |
| 347 } else if (*iter == kEnableSystrace) { |
| 348 enable_systrace_ = true; |
| 349 } else if (*iter == kEnableArgumentFilter) { |
| 350 enable_argument_filter_ = true; |
| 351 } |
| 352 } |
| 353 } |
| 354 } |
| 355 |
328 void TraceConfig::SetCategoriesFromIncludedList( | 356 void TraceConfig::SetCategoriesFromIncludedList( |
329 const base::ListValue& included_list) { | 357 const base::ListValue& included_list) { |
330 included_categories_.clear(); | 358 included_categories_.clear(); |
331 for (size_t i = 0; i < included_list.GetSize(); ++i) { | 359 for (size_t i = 0; i < included_list.GetSize(); ++i) { |
332 std::string category; | 360 std::string category; |
333 if (!included_list.GetString(i, &category)) | 361 if (!included_list.GetString(i, &category)) |
334 continue; | 362 continue; |
335 if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), | 363 if (category.compare(0, strlen(TRACE_DISABLED_BY_DEFAULT("")), |
336 TRACE_DISABLED_BY_DEFAULT("")) == 0) { | 364 TRACE_DISABLED_BY_DEFAULT("")) == 0) { |
337 disabled_categories_.push_back(category); | 365 disabled_categories_.push_back(category); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 411 } |
384 | 412 |
385 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 413 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
386 switch (record_mode_) { | 414 switch (record_mode_) { |
387 case RECORD_UNTIL_FULL: | 415 case RECORD_UNTIL_FULL: |
388 dict.SetString(kRecordModeParam, kRecordUntilFull); | 416 dict.SetString(kRecordModeParam, kRecordUntilFull); |
389 break; | 417 break; |
390 case RECORD_CONTINUOUSLY: | 418 case RECORD_CONTINUOUSLY: |
391 dict.SetString(kRecordModeParam, kRecordContinuously); | 419 dict.SetString(kRecordModeParam, kRecordContinuously); |
392 break; | 420 break; |
| 421 case RECORD_AS_MUCH_AS_POSSIBLE: |
| 422 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); |
| 423 break; |
393 case ECHO_TO_CONSOLE: | 424 case ECHO_TO_CONSOLE: |
394 dict.SetString(kRecordModeParam, kTraceToConsole); | 425 dict.SetString(kRecordModeParam, kTraceToConsole); |
395 break; | 426 break; |
396 case RECORD_AS_MUCH_AS_POSSIBLE: | |
397 dict.SetString(kRecordModeParam, kRecordAsMuchAsPossible); | |
398 break; | |
399 default: | 427 default: |
400 NOTREACHED(); | 428 NOTREACHED(); |
401 } | 429 } |
402 | 430 |
403 if (enable_sampling_) | 431 if (enable_sampling_) |
404 dict.SetBoolean(kEnableSamplingParam, true); | 432 dict.SetBoolean(kEnableSamplingParam, true); |
405 else | 433 else |
406 dict.SetBoolean(kEnableSamplingParam, false); | 434 dict.SetBoolean(kEnableSamplingParam, false); |
407 | 435 |
408 if (enable_systrace_) | 436 if (enable_systrace_) |
409 dict.SetBoolean(kEnableSystraceParam, true); | 437 dict.SetBoolean(kEnableSystraceParam, true); |
410 else | 438 else |
411 dict.SetBoolean(kEnableSystraceParam, false); | 439 dict.SetBoolean(kEnableSystraceParam, false); |
412 | 440 |
413 if (enable_argument_filter_) | 441 if (enable_argument_filter_) |
414 dict.SetBoolean(kEnableArgumentFilterParam, true); | 442 dict.SetBoolean(kEnableArgumentFilterParam, true); |
415 else | 443 else |
416 dict.SetBoolean(kEnableArgumentFilterParam, false); | 444 dict.SetBoolean(kEnableArgumentFilterParam, false); |
417 | 445 |
418 StringList categories(included_categories_); | 446 StringList categories(included_categories_); |
419 categories.insert(categories.end(), | 447 categories.insert(categories.end(), |
420 disabled_categories_.begin(), | 448 disabled_categories_.begin(), |
421 disabled_categories_.end()); | 449 disabled_categories_.end()); |
422 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 450 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
423 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 451 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
424 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 452 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
425 } | 453 } |
426 | 454 |
427 std::string TraceConfig::ToTraceOptionsString() const { | 455 std::string TraceConfig::ToTraceOptionsString() const { |
428 TraceOptions to; | 456 std::string ret; |
429 to.record_mode = record_mode_; | 457 switch (record_mode_) { |
430 to.enable_sampling = enable_sampling_; | 458 case RECORD_UNTIL_FULL: |
431 to.enable_systrace = enable_systrace_; | 459 ret = kRecordUntilFull; |
432 to.enable_argument_filter = enable_argument_filter_; | 460 break; |
433 return to.ToString(); | 461 case RECORD_CONTINUOUSLY: |
| 462 ret = kRecordContinuously; |
| 463 break; |
| 464 case RECORD_AS_MUCH_AS_POSSIBLE: |
| 465 ret = kRecordAsMuchAsPossible; |
| 466 break; |
| 467 case ECHO_TO_CONSOLE: |
| 468 ret = kTraceToConsole; |
| 469 break; |
| 470 default: |
| 471 NOTREACHED(); |
| 472 } |
| 473 if (enable_sampling_) |
| 474 ret = ret + "," + kEnableSampling; |
| 475 if (enable_systrace_) |
| 476 ret = ret + "," + kEnableSystrace; |
| 477 if (enable_argument_filter_) |
| 478 ret = ret + "," + kEnableArgumentFilter; |
| 479 return ret; |
434 } | 480 } |
435 | 481 |
436 void TraceConfig::WriteCategoryFilterString(const StringList& values, | 482 void TraceConfig::WriteCategoryFilterString(const StringList& values, |
437 std::string* out, | 483 std::string* out, |
438 bool included) const { | 484 bool included) const { |
439 bool prepend_comma = !out->empty(); | 485 bool prepend_comma = !out->empty(); |
440 int token_cnt = 0; | 486 int token_cnt = 0; |
441 for (StringList::const_iterator ci = values.begin(); | 487 for (StringList::const_iterator ci = values.begin(); |
442 ci != values.end(); ++ci) { | 488 ci != values.end(); ++ci) { |
443 if (token_cnt > 0 || prepend_comma) | 489 if (token_cnt > 0 || prepend_comma) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 str.at(0) == ' ' || | 538 str.at(0) == ' ' || |
493 str.at(str.length() - 1) == ' '; | 539 str.at(str.length() - 1) == ' '; |
494 } | 540 } |
495 | 541 |
496 bool TraceConfig::HasIncludedPatterns() const { | 542 bool TraceConfig::HasIncludedPatterns() const { |
497 return !included_categories_.empty(); | 543 return !included_categories_.empty(); |
498 } | 544 } |
499 | 545 |
500 } // namespace trace_event | 546 } // namespace trace_event |
501 } // namespace base | 547 } // namespace base |
OLD | NEW |