| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 break; | 98 break; |
| 99 case ECHO_TO_CONSOLE: | 99 case ECHO_TO_CONSOLE: |
| 100 trace_options_string = kTraceToConsole; | 100 trace_options_string = kTraceToConsole; |
| 101 break; | 101 break; |
| 102 default: | 102 default: |
| 103 NOTREACHED(); | 103 NOTREACHED(); |
| 104 } | 104 } |
| 105 InitializeFromStrings(category_filter_string, trace_options_string); | 105 InitializeFromStrings(category_filter_string, trace_options_string); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TraceConfig::TraceConfig(const DictionaryValue& config) { | |
| 109 InitializeFromConfigDict(config); | |
| 110 } | |
| 111 | |
| 112 TraceConfig::TraceConfig(const std::string& config_string) { | 108 TraceConfig::TraceConfig(const std::string& config_string) { |
| 113 if (!config_string.empty()) | 109 if (!config_string.empty()) |
| 114 InitializeFromConfigString(config_string); | 110 InitializeFromConfigString(config_string); |
| 115 else | 111 else |
| 116 InitializeDefault(); | 112 InitializeDefault(); |
| 117 } | 113 } |
| 118 | 114 |
| 119 TraceConfig::TraceConfig(const TraceConfig& tc) | 115 TraceConfig::TraceConfig(const TraceConfig& tc) |
| 120 : record_mode_(tc.record_mode_), | 116 : record_mode_(tc.record_mode_), |
| 121 enable_sampling_(tc.enable_sampling_), | 117 enable_sampling_(tc.enable_sampling_), |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 281 |
| 286 void TraceConfig::InitializeDefault() { | 282 void TraceConfig::InitializeDefault() { |
| 287 record_mode_ = RECORD_UNTIL_FULL; | 283 record_mode_ = RECORD_UNTIL_FULL; |
| 288 enable_sampling_ = false; | 284 enable_sampling_ = false; |
| 289 enable_systrace_ = false; | 285 enable_systrace_ = false; |
| 290 enable_argument_filter_ = false; | 286 enable_argument_filter_ = false; |
| 291 excluded_categories_.push_back("*Debug"); | 287 excluded_categories_.push_back("*Debug"); |
| 292 excluded_categories_.push_back("*Test"); | 288 excluded_categories_.push_back("*Test"); |
| 293 } | 289 } |
| 294 | 290 |
| 295 void TraceConfig::InitializeFromConfigDict(const DictionaryValue& dict) { | 291 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
| 292 scoped_ptr<base::Value> value(base::JSONReader::Read(config_string)); |
| 293 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 294 InitializeDefault(); |
| 295 return; |
| 296 } |
| 297 scoped_ptr<base::DictionaryValue> dict( |
| 298 static_cast<base::DictionaryValue*>(value.release())); |
| 299 |
| 296 record_mode_ = RECORD_UNTIL_FULL; | 300 record_mode_ = RECORD_UNTIL_FULL; |
| 297 std::string record_mode; | 301 std::string record_mode; |
| 298 if (dict.GetString(kRecordModeParam, &record_mode)) { | 302 if (dict->GetString(kRecordModeParam, &record_mode)) { |
| 299 if (record_mode == kRecordUntilFull) { | 303 if (record_mode == kRecordUntilFull) { |
| 300 record_mode_ = RECORD_UNTIL_FULL; | 304 record_mode_ = RECORD_UNTIL_FULL; |
| 301 } else if (record_mode == kRecordContinuously) { | 305 } else if (record_mode == kRecordContinuously) { |
| 302 record_mode_ = RECORD_CONTINUOUSLY; | 306 record_mode_ = RECORD_CONTINUOUSLY; |
| 303 } else if (record_mode == kTraceToConsole) { | 307 } else if (record_mode == kTraceToConsole) { |
| 304 record_mode_ = ECHO_TO_CONSOLE; | 308 record_mode_ = ECHO_TO_CONSOLE; |
| 305 } else if (record_mode == kRecordAsMuchAsPossible) { | 309 } else if (record_mode == kRecordAsMuchAsPossible) { |
| 306 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; | 310 record_mode_ = RECORD_AS_MUCH_AS_POSSIBLE; |
| 307 } | 311 } |
| 308 } | 312 } |
| 309 | 313 |
| 310 bool enable_sampling; | 314 bool enable_sampling; |
| 311 if (!dict.GetBoolean(kEnableSamplingParam, &enable_sampling)) | 315 if (!dict->GetBoolean(kEnableSamplingParam, &enable_sampling)) |
| 312 enable_sampling_ = false; | 316 enable_sampling_ = false; |
| 313 else | 317 else |
| 314 enable_sampling_ = enable_sampling; | 318 enable_sampling_ = enable_sampling; |
| 315 | 319 |
| 316 bool enable_systrace; | 320 bool enable_systrace; |
| 317 if (!dict.GetBoolean(kEnableSystraceParam, &enable_systrace)) | 321 if (!dict->GetBoolean(kEnableSystraceParam, &enable_systrace)) |
| 318 enable_systrace_ = false; | 322 enable_systrace_ = false; |
| 319 else | 323 else |
| 320 enable_systrace_ = enable_systrace; | 324 enable_systrace_ = enable_systrace; |
| 321 | 325 |
| 322 bool enable_argument_filter; | 326 bool enable_argument_filter; |
| 323 if (!dict.GetBoolean(kEnableArgumentFilterParam, &enable_argument_filter)) | 327 if (!dict->GetBoolean(kEnableArgumentFilterParam, &enable_argument_filter)) |
| 324 enable_argument_filter_ = false; | 328 enable_argument_filter_ = false; |
| 325 else | 329 else |
| 326 enable_argument_filter_ = enable_argument_filter; | 330 enable_argument_filter_ = enable_argument_filter; |
| 327 | 331 |
| 328 const base::ListValue* category_list = nullptr; | 332 base::ListValue* category_list = nullptr; |
| 329 if (dict.GetList(kIncludedCategoriesParam, &category_list)) | 333 if (dict->GetList(kIncludedCategoriesParam, &category_list)) |
| 330 SetCategoriesFromIncludedList(*category_list); | 334 SetCategoriesFromIncludedList(*category_list); |
| 331 if (dict.GetList(kExcludedCategoriesParam, &category_list)) | 335 if (dict->GetList(kExcludedCategoriesParam, &category_list)) |
| 332 SetCategoriesFromExcludedList(*category_list); | 336 SetCategoriesFromExcludedList(*category_list); |
| 333 if (dict.GetList(kSyntheticDelaysParam, &category_list)) | 337 if (dict->GetList(kSyntheticDelaysParam, &category_list)) |
| 334 SetSyntheticDelaysFromList(*category_list); | 338 SetSyntheticDelaysFromList(*category_list); |
| 335 | 339 |
| 336 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 340 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 337 // If dump triggers not set, the client is using the legacy with just | 341 // If dump triggers not set, the client is using the legacy with just |
| 338 // category enabled. So, use the default periodic dump config. | 342 // category enabled. So, use the default periodic dump config. |
| 339 const base::DictionaryValue* memory_dump_config = nullptr; | 343 base::DictionaryValue* memory_dump_config = nullptr; |
| 340 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 344 if (dict->GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
| 341 SetMemoryDumpConfig(*memory_dump_config); | 345 SetMemoryDumpConfig(*memory_dump_config); |
| 342 else | 346 else |
| 343 SetDefaultMemoryDumpConfig(); | 347 SetDefaultMemoryDumpConfig(); |
| 344 } | 348 } |
| 345 } | 349 } |
| 346 | 350 |
| 347 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { | |
| 348 scoped_ptr<Value> value(JSONReader::Read(config_string)); | |
| 349 if (!value) | |
| 350 return InitializeDefault(); | |
| 351 | |
| 352 const DictionaryValue* dict = nullptr; | |
| 353 bool is_dict = value->GetAsDictionary(&dict); | |
| 354 | |
| 355 if (!is_dict) | |
| 356 return InitializeDefault(); | |
| 357 | |
| 358 DCHECK(dict); | |
| 359 InitializeFromConfigDict(*dict); | |
| 360 } | |
| 361 | |
| 362 void TraceConfig::InitializeFromStrings( | 351 void TraceConfig::InitializeFromStrings( |
| 363 const std::string& category_filter_string, | 352 const std::string& category_filter_string, |
| 364 const std::string& trace_options_string) { | 353 const std::string& trace_options_string) { |
| 365 if (!category_filter_string.empty()) { | 354 if (!category_filter_string.empty()) { |
| 366 std::vector<std::string> split = base::SplitString( | 355 std::vector<std::string> split = base::SplitString( |
| 367 category_filter_string, ",", base::TRIM_WHITESPACE, | 356 category_filter_string, ",", base::TRIM_WHITESPACE, |
| 368 base::SPLIT_WANT_ALL); | 357 base::SPLIT_WANT_ALL); |
| 369 std::vector<std::string>::iterator iter; | 358 std::vector<std::string>::iterator iter; |
| 370 for (iter = split.begin(); iter != split.end(); ++iter) { | 359 for (iter = split.begin(); iter != split.end(); ++iter) { |
| 371 std::string category = *iter; | 360 std::string category = *iter; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 str.at(0) == ' ' || | 660 str.at(0) == ' ' || |
| 672 str.at(str.length() - 1) == ' '; | 661 str.at(str.length() - 1) == ' '; |
| 673 } | 662 } |
| 674 | 663 |
| 675 bool TraceConfig::HasIncludedPatterns() const { | 664 bool TraceConfig::HasIncludedPatterns() const { |
| 676 return !included_categories_.empty(); | 665 return !included_categories_.empty(); |
| 677 } | 666 } |
| 678 | 667 |
| 679 } // namespace trace_event | 668 } // namespace trace_event |
| 680 } // namespace base | 669 } // namespace base |
| OLD | NEW |