| 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/pattern.h" | 9 #include "base/strings/pattern.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/trace_event/memory_dump_manager.h" | 13 #include "base/trace_event/memory_dump_manager.h" |
| 14 #include "base/trace_event/memory_dump_request_args.h" |
| 14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 namespace trace_event { | 18 namespace trace_event { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // String options that can be used to initialize TraceOptions. | 22 // String options that can be used to initialize TraceOptions. |
| 22 const char kRecordUntilFull[] = "record-until-full"; | 23 const char kRecordUntilFull[] = "record-until-full"; |
| 23 const char kRecordContinuously[] = "record-continuously"; | 24 const char kRecordContinuously[] = "record-continuously"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 const char kSyntheticDelaysParam[] = "synthetic_delays"; | 38 const char kSyntheticDelaysParam[] = "synthetic_delays"; |
| 38 | 39 |
| 39 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; | 40 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; |
| 40 | 41 |
| 41 // String parameters that is used to parse memory dump config in trace config | 42 // String parameters that is used to parse memory dump config in trace config |
| 42 // string. | 43 // string. |
| 43 const char kMemoryDumpConfigParam[] = "memory_dump_config"; | 44 const char kMemoryDumpConfigParam[] = "memory_dump_config"; |
| 44 const char kTriggersParam[] = "triggers"; | 45 const char kTriggersParam[] = "triggers"; |
| 45 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; | 46 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
| 46 const char kModeParam[] = "mode"; | 47 const char kModeParam[] = "mode"; |
| 47 const char kDetailedParam[] = "detailed"; | |
| 48 const char kLightParam[] = "light"; | |
| 49 | 48 |
| 50 // Default configuration of memory dumps. | 49 // Default configuration of memory dumps. |
| 51 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { | 50 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { |
| 52 2000, // periodic_interval_ms | 51 2000, // periodic_interval_ms |
| 53 MemoryDumpArgs::LevelOfDetail::HIGH}; | 52 MemoryDumpLevelOfDetail::DETAILED}; |
| 54 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { | 53 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { |
| 55 250, // periodic_interval_ms | 54 250, // periodic_interval_ms |
| 56 MemoryDumpArgs::LevelOfDetail::LOW}; | 55 MemoryDumpLevelOfDetail::LIGHT}; |
| 57 | 56 |
| 58 } // namespace | 57 } // namespace |
| 59 | 58 |
| 60 TraceConfig::TraceConfig() { | 59 TraceConfig::TraceConfig() { |
| 61 InitializeDefault(); | 60 InitializeDefault(); |
| 62 } | 61 } |
| 63 | 62 |
| 64 TraceConfig::TraceConfig(const std::string& category_filter_string, | 63 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| 65 const std::string& trace_options_string) { | 64 const std::string& trace_options_string) { |
| 66 InitializeFromStrings(category_filter_string, trace_options_string); | 65 InitializeFromStrings(category_filter_string, trace_options_string); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 trigger_list->GetSize() == 0) { | 457 trigger_list->GetSize() == 0) { |
| 459 return; | 458 return; |
| 460 } | 459 } |
| 461 | 460 |
| 462 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { | 461 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { |
| 463 const base::DictionaryValue* trigger = nullptr; | 462 const base::DictionaryValue* trigger = nullptr; |
| 464 if (!trigger_list->GetDictionary(i, &trigger)) | 463 if (!trigger_list->GetDictionary(i, &trigger)) |
| 465 continue; | 464 continue; |
| 466 | 465 |
| 467 MemoryDumpTriggerConfig dump_config; | 466 MemoryDumpTriggerConfig dump_config; |
| 468 std::string dump_type; | |
| 469 int interval = 0; | 467 int interval = 0; |
| 470 | 468 |
| 471 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { | 469 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { |
| 472 continue; | 470 continue; |
| 473 } | 471 } |
| 474 DCHECK_GT(interval, 0); | 472 DCHECK_GT(interval, 0); |
| 475 dump_config.periodic_interval_ms = static_cast<uint32>(interval); | 473 dump_config.periodic_interval_ms = static_cast<uint32>(interval); |
| 476 dump_config.level_of_detail = MemoryDumpArgs::LevelOfDetail::LOW; | 474 std::string level_of_detail_str; |
| 477 | 475 trigger->GetString(kModeParam, &level_of_detail_str); |
| 478 if (trigger->GetString(kModeParam, &dump_type)) { | 476 dump_config.level_of_detail = |
| 479 if (dump_type == kDetailedParam) { | 477 StringToMemoryDumpLevelOfDetail(level_of_detail_str); |
| 480 dump_config.level_of_detail = MemoryDumpArgs::LevelOfDetail::HIGH; | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 memory_dump_config_.push_back(dump_config); | 478 memory_dump_config_.push_back(dump_config); |
| 485 } | 479 } |
| 486 } | 480 } |
| 487 | 481 |
| 488 void TraceConfig::SetDefaultMemoryDumpConfig() { | 482 void TraceConfig::SetDefaultMemoryDumpConfig() { |
| 489 memory_dump_config_.clear(); | 483 memory_dump_config_.clear(); |
| 490 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); | 484 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); |
| 491 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); | 485 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); |
| 492 } | 486 } |
| 493 | 487 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 528 |
| 535 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 529 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 536 scoped_ptr<base::DictionaryValue> memory_dump_config( | 530 scoped_ptr<base::DictionaryValue> memory_dump_config( |
| 537 new base::DictionaryValue()); | 531 new base::DictionaryValue()); |
| 538 scoped_ptr<base::ListValue> triggers_list(new base::ListValue()); | 532 scoped_ptr<base::ListValue> triggers_list(new base::ListValue()); |
| 539 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { | 533 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { |
| 540 scoped_ptr<base::DictionaryValue> trigger_dict( | 534 scoped_ptr<base::DictionaryValue> trigger_dict( |
| 541 new base::DictionaryValue()); | 535 new base::DictionaryValue()); |
| 542 trigger_dict->SetInteger(kPeriodicIntervalParam, | 536 trigger_dict->SetInteger(kPeriodicIntervalParam, |
| 543 static_cast<int>(config.periodic_interval_ms)); | 537 static_cast<int>(config.periodic_interval_ms)); |
| 544 | 538 trigger_dict->SetString( |
| 545 switch (config.level_of_detail) { | 539 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); |
| 546 case MemoryDumpArgs::LevelOfDetail::LOW: | |
| 547 trigger_dict->SetString(kModeParam, kLightParam); | |
| 548 break; | |
| 549 case MemoryDumpArgs::LevelOfDetail::HIGH: | |
| 550 trigger_dict->SetString(kModeParam, kDetailedParam); | |
| 551 break; | |
| 552 default: | |
| 553 NOTREACHED(); | |
| 554 } | |
| 555 triggers_list->Append(trigger_dict.Pass()); | 540 triggers_list->Append(trigger_dict.Pass()); |
| 556 } | 541 } |
| 557 | 542 |
| 558 // Empty triggers will still be specified explicitly since it means that | 543 // Empty triggers will still be specified explicitly since it means that |
| 559 // the periodic dumps are not enabled. | 544 // the periodic dumps are not enabled. |
| 560 memory_dump_config->Set(kTriggersParam, triggers_list.Pass()); | 545 memory_dump_config->Set(kTriggersParam, triggers_list.Pass()); |
| 561 dict.Set(kMemoryDumpConfigParam, memory_dump_config.Pass()); | 546 dict.Set(kMemoryDumpConfigParam, memory_dump_config.Pass()); |
| 562 } | 547 } |
| 563 } | 548 } |
| 564 | 549 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 str.at(0) == ' ' || | 633 str.at(0) == ' ' || |
| 649 str.at(str.length() - 1) == ' '; | 634 str.at(str.length() - 1) == ' '; |
| 650 } | 635 } |
| 651 | 636 |
| 652 bool TraceConfig::HasIncludedPatterns() const { | 637 bool TraceConfig::HasIncludedPatterns() const { |
| 653 return !included_categories_.empty(); | 638 return !included_categories_.empty(); |
| 654 } | 639 } |
| 655 | 640 |
| 656 } // namespace trace_event | 641 } // namespace trace_event |
| 657 } // namespace base | 642 } // namespace base |
| OLD | NEW |