| 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 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/pattern.h" | 14 #include "base/strings/pattern.h" |
| 14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/trace_event/memory_dump_manager.h" | 18 #include "base/trace_event/memory_dump_manager.h" |
| 18 #include "base/trace_event/memory_dump_request_args.h" | 19 #include "base/trace_event/memory_dump_request_args.h" |
| 19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 namespace trace_event { | 23 namespace trace_event { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 std::string TraceConfig::ToString() const { | 154 std::string TraceConfig::ToString() const { |
| 154 base::DictionaryValue dict; | 155 base::DictionaryValue dict; |
| 155 ToDict(dict); | 156 ToDict(dict); |
| 156 | 157 |
| 157 std::string json; | 158 std::string json; |
| 158 base::JSONWriter::Write(dict, &json); | 159 base::JSONWriter::Write(dict, &json); |
| 159 | 160 |
| 160 return json; | 161 return json; |
| 161 } | 162 } |
| 162 | 163 |
| 163 scoped_ptr<ConvertableToTraceFormat> TraceConfig::AsConvertableToTraceFormat() | 164 std::unique_ptr<ConvertableToTraceFormat> |
| 164 const { | 165 TraceConfig::AsConvertableToTraceFormat() const { |
| 165 return make_scoped_ptr(new ConvertableTraceConfigToTraceFormat(*this)); | 166 return base::WrapUnique(new ConvertableTraceConfigToTraceFormat(*this)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 std::string TraceConfig::ToCategoryFilterString() const { | 169 std::string TraceConfig::ToCategoryFilterString() const { |
| 169 std::string filter_string; | 170 std::string filter_string; |
| 170 WriteCategoryFilterString(included_categories_, &filter_string, true); | 171 WriteCategoryFilterString(included_categories_, &filter_string, true); |
| 171 WriteCategoryFilterString(disabled_categories_, &filter_string, true); | 172 WriteCategoryFilterString(disabled_categories_, &filter_string, true); |
| 172 WriteCategoryFilterString(excluded_categories_, &filter_string, false); | 173 WriteCategoryFilterString(excluded_categories_, &filter_string, false); |
| 173 WriteCategoryFilterString(synthetic_delays_, &filter_string); | 174 WriteCategoryFilterString(synthetic_delays_, &filter_string); |
| 174 return filter_string; | 175 return filter_string; |
| 175 } | 176 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // category enabled. So, use the default periodic dump config. | 339 // category enabled. So, use the default periodic dump config. |
| 339 const base::DictionaryValue* memory_dump_config = nullptr; | 340 const base::DictionaryValue* memory_dump_config = nullptr; |
| 340 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) | 341 if (dict.GetDictionary(kMemoryDumpConfigParam, &memory_dump_config)) |
| 341 SetMemoryDumpConfig(*memory_dump_config); | 342 SetMemoryDumpConfig(*memory_dump_config); |
| 342 else | 343 else |
| 343 SetDefaultMemoryDumpConfig(); | 344 SetDefaultMemoryDumpConfig(); |
| 344 } | 345 } |
| 345 } | 346 } |
| 346 | 347 |
| 347 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { | 348 void TraceConfig::InitializeFromConfigString(const std::string& config_string) { |
| 348 scoped_ptr<Value> value(JSONReader::Read(config_string)); | 349 std::unique_ptr<Value> value(JSONReader::Read(config_string)); |
| 349 if (!value) | 350 if (!value) |
| 350 return InitializeDefault(); | 351 return InitializeDefault(); |
| 351 | 352 |
| 352 const DictionaryValue* dict = nullptr; | 353 const DictionaryValue* dict = nullptr; |
| 353 bool is_dict = value->GetAsDictionary(&dict); | 354 bool is_dict = value->GetAsDictionary(&dict); |
| 354 | 355 |
| 355 if (!is_dict) | 356 if (!is_dict) |
| 356 return InitializeDefault(); | 357 return InitializeDefault(); |
| 357 | 358 |
| 358 DCHECK(dict); | 359 DCHECK(dict); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 470 } |
| 470 } | 471 } |
| 471 } | 472 } |
| 472 | 473 |
| 473 void TraceConfig::AddCategoryToDict(base::DictionaryValue& dict, | 474 void TraceConfig::AddCategoryToDict(base::DictionaryValue& dict, |
| 474 const char* param, | 475 const char* param, |
| 475 const StringList& categories) const { | 476 const StringList& categories) const { |
| 476 if (categories.empty()) | 477 if (categories.empty()) |
| 477 return; | 478 return; |
| 478 | 479 |
| 479 scoped_ptr<base::ListValue> list(new base::ListValue()); | 480 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 480 for (StringList::const_iterator ci = categories.begin(); | 481 for (StringList::const_iterator ci = categories.begin(); |
| 481 ci != categories.end(); | 482 ci != categories.end(); |
| 482 ++ci) { | 483 ++ci) { |
| 483 list->AppendString(*ci); | 484 list->AppendString(*ci); |
| 484 } | 485 } |
| 485 | 486 |
| 486 dict.Set(param, std::move(list)); | 487 dict.Set(param, std::move(list)); |
| 487 } | 488 } |
| 488 | 489 |
| 489 void TraceConfig::SetMemoryDumpConfig( | 490 void TraceConfig::SetMemoryDumpConfig( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 559 |
| 559 StringList categories(included_categories_); | 560 StringList categories(included_categories_); |
| 560 categories.insert(categories.end(), | 561 categories.insert(categories.end(), |
| 561 disabled_categories_.begin(), | 562 disabled_categories_.begin(), |
| 562 disabled_categories_.end()); | 563 disabled_categories_.end()); |
| 563 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 564 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
| 564 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 565 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
| 565 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 566 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
| 566 | 567 |
| 567 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 568 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 568 scoped_ptr<base::DictionaryValue> memory_dump_config( | 569 std::unique_ptr<base::DictionaryValue> memory_dump_config( |
| 569 new base::DictionaryValue()); | 570 new base::DictionaryValue()); |
| 570 scoped_ptr<base::ListValue> triggers_list(new base::ListValue()); | 571 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
| 571 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { | 572 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { |
| 572 scoped_ptr<base::DictionaryValue> trigger_dict( | 573 std::unique_ptr<base::DictionaryValue> trigger_dict( |
| 573 new base::DictionaryValue()); | 574 new base::DictionaryValue()); |
| 574 trigger_dict->SetInteger(kPeriodicIntervalParam, | 575 trigger_dict->SetInteger(kPeriodicIntervalParam, |
| 575 static_cast<int>(config.periodic_interval_ms)); | 576 static_cast<int>(config.periodic_interval_ms)); |
| 576 trigger_dict->SetString( | 577 trigger_dict->SetString( |
| 577 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); | 578 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); |
| 578 triggers_list->Append(std::move(trigger_dict)); | 579 triggers_list->Append(std::move(trigger_dict)); |
| 579 } | 580 } |
| 580 | 581 |
| 581 // Empty triggers will still be specified explicitly since it means that | 582 // Empty triggers will still be specified explicitly since it means that |
| 582 // the periodic dumps are not enabled. | 583 // the periodic dumps are not enabled. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 str.at(0) == ' ' || | 672 str.at(0) == ' ' || |
| 672 str.at(str.length() - 1) == ' '; | 673 str.at(str.length() - 1) == ' '; |
| 673 } | 674 } |
| 674 | 675 |
| 675 bool TraceConfig::HasIncludedPatterns() const { | 676 bool TraceConfig::HasIncludedPatterns() const { |
| 676 return !included_categories_.empty(); | 677 return !included_categories_.empty(); |
| 677 } | 678 } |
| 678 | 679 |
| 679 } // namespace trace_event | 680 } // namespace trace_event |
| 680 } // namespace base | 681 } // namespace base |
| OLD | NEW |