Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 const char kSyntheticDelaysParam[] = "synthetic_delays"; | 43 const char kSyntheticDelaysParam[] = "synthetic_delays"; |
| 44 | 44 |
| 45 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; | 45 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; |
| 46 | 46 |
| 47 // String parameters that is used to parse memory dump config in trace config | 47 // String parameters that is used to parse memory dump config in trace config |
| 48 // string. | 48 // string. |
| 49 const char kMemoryDumpConfigParam[] = "memory_dump_config"; | 49 const char kMemoryDumpConfigParam[] = "memory_dump_config"; |
| 50 const char kTriggersParam[] = "triggers"; | 50 const char kTriggersParam[] = "triggers"; |
| 51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; | 51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
| 52 const char kModeParam[] = "mode"; | 52 const char kModeParam[] = "mode"; |
| 53 const char kHeapProfilerOptions[] = "heap_profiler_options"; | |
| 54 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; | |
| 53 | 55 |
| 54 // Default configuration of memory dumps. | 56 // Default configuration of memory dumps. |
| 55 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { | 57 const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { |
| 56 2000, // periodic_interval_ms | 58 2000, // periodic_interval_ms |
| 57 MemoryDumpLevelOfDetail::DETAILED}; | 59 MemoryDumpLevelOfDetail::DETAILED}; |
| 58 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { | 60 const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { |
| 59 250, // periodic_interval_ms | 61 250, // periodic_interval_ms |
| 60 MemoryDumpLevelOfDetail::LIGHT}; | 62 MemoryDumpLevelOfDetail::LIGHT}; |
| 61 | 63 |
| 62 class ConvertableTraceConfigToTraceFormat | 64 class ConvertableTraceConfigToTraceFormat |
| 63 : public base::trace_event::ConvertableToTraceFormat { | 65 : public base::trace_event::ConvertableToTraceFormat { |
| 64 public: | 66 public: |
| 65 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) | 67 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) |
| 66 : trace_config_(trace_config) {} | 68 : trace_config_(trace_config) {} |
| 67 ~ConvertableTraceConfigToTraceFormat() override {} | 69 ~ConvertableTraceConfigToTraceFormat() override {} |
| 68 void AppendAsTraceFormat(std::string* out) const override { | 70 void AppendAsTraceFormat(std::string* out) const override { |
| 69 out->append(trace_config_.ToString()); | 71 out->append(trace_config_.ToString()); |
| 70 } | 72 } |
| 71 | 73 |
| 72 private: | 74 private: |
| 73 const TraceConfig trace_config_; | 75 const TraceConfig trace_config_; |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 } // namespace | 78 } // namespace |
| 77 | 79 |
| 80 | |
| 81 TraceConfig::HeapProfilerOptions::HeapProfilerOptions() : | |
| 82 breakdown_threshold_bytes(kDefaultBreakdownThresholdBytes) {}; | |
| 83 | |
| 84 TraceConfig::HeapProfilerOptions::~HeapProfilerOptions() {}; | |
| 85 | |
| 86 void TraceConfig::HeapProfilerOptions::Clear() { | |
| 87 breakdown_threshold_bytes = kDefaultBreakdownThresholdBytes; | |
| 88 } | |
| 89 | |
| 90 TraceConfig::MemoryDumpConfig::MemoryDumpConfig() {}; | |
| 91 | |
| 92 TraceConfig::MemoryDumpConfig::MemoryDumpConfig( | |
| 93 const MemoryDumpConfig& other) = default; | |
| 94 | |
| 95 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; | |
| 96 | |
| 97 void TraceConfig::MemoryDumpConfig::Clear() { | |
| 98 triggers.clear(); | |
| 99 heap_profiler_options.Clear(); | |
| 100 } | |
| 101 | |
| 102 | |
| 78 TraceConfig::TraceConfig() { | 103 TraceConfig::TraceConfig() { |
| 79 InitializeDefault(); | 104 InitializeDefault(); |
| 80 } | 105 } |
| 81 | 106 |
| 82 TraceConfig::TraceConfig(const std::string& category_filter_string, | 107 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| 83 const std::string& trace_options_string) { | 108 const std::string& trace_options_string) { |
| 84 InitializeFromStrings(category_filter_string, trace_options_string); | 109 InitializeFromStrings(category_filter_string, trace_options_string); |
| 85 } | 110 } |
| 86 | 111 |
| 87 TraceConfig::TraceConfig(const std::string& category_filter_string, | 112 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 // Otherwise, one of the filter was specifying "*" and we want to honor the | 275 // Otherwise, one of the filter was specifying "*" and we want to honor the |
| 251 // broadest filter. | 276 // broadest filter. |
| 252 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { | 277 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { |
| 253 included_categories_.insert(included_categories_.end(), | 278 included_categories_.insert(included_categories_.end(), |
| 254 config.included_categories_.begin(), | 279 config.included_categories_.begin(), |
| 255 config.included_categories_.end()); | 280 config.included_categories_.end()); |
| 256 } else { | 281 } else { |
| 257 included_categories_.clear(); | 282 included_categories_.clear(); |
| 258 } | 283 } |
| 259 | 284 |
| 260 memory_dump_config_.insert(memory_dump_config_.end(), | 285 memory_dump_config_.triggers.insert(memory_dump_config_.triggers.end(), |
| 261 config.memory_dump_config_.begin(), | 286 config.memory_dump_config_.triggers.begin(), |
| 262 config.memory_dump_config_.end()); | 287 config.memory_dump_config_.triggers.end()); |
| 263 | 288 |
| 264 disabled_categories_.insert(disabled_categories_.end(), | 289 disabled_categories_.insert(disabled_categories_.end(), |
| 265 config.disabled_categories_.begin(), | 290 config.disabled_categories_.begin(), |
| 266 config.disabled_categories_.end()); | 291 config.disabled_categories_.end()); |
| 267 excluded_categories_.insert(excluded_categories_.end(), | 292 excluded_categories_.insert(excluded_categories_.end(), |
| 268 config.excluded_categories_.begin(), | 293 config.excluded_categories_.begin(), |
| 269 config.excluded_categories_.end()); | 294 config.excluded_categories_.end()); |
| 270 synthetic_delays_.insert(synthetic_delays_.end(), | 295 synthetic_delays_.insert(synthetic_delays_.end(), |
| 271 config.synthetic_delays_.begin(), | 296 config.synthetic_delays_.begin(), |
| 272 config.synthetic_delays_.end()); | 297 config.synthetic_delays_.end()); |
| 273 } | 298 } |
| 274 | 299 |
| 275 void TraceConfig::Clear() { | 300 void TraceConfig::Clear() { |
| 276 record_mode_ = RECORD_UNTIL_FULL; | 301 record_mode_ = RECORD_UNTIL_FULL; |
| 277 enable_sampling_ = false; | 302 enable_sampling_ = false; |
| 278 enable_systrace_ = false; | 303 enable_systrace_ = false; |
| 279 enable_argument_filter_ = false; | 304 enable_argument_filter_ = false; |
| 280 included_categories_.clear(); | 305 included_categories_.clear(); |
| 281 disabled_categories_.clear(); | 306 disabled_categories_.clear(); |
| 282 excluded_categories_.clear(); | 307 excluded_categories_.clear(); |
| 283 synthetic_delays_.clear(); | 308 synthetic_delays_.clear(); |
| 284 memory_dump_config_.clear(); | 309 memory_dump_config_.Clear(); |
| 285 } | 310 } |
| 286 | 311 |
| 287 void TraceConfig::InitializeDefault() { | 312 void TraceConfig::InitializeDefault() { |
| 288 record_mode_ = RECORD_UNTIL_FULL; | 313 record_mode_ = RECORD_UNTIL_FULL; |
| 289 enable_sampling_ = false; | 314 enable_sampling_ = false; |
| 290 enable_systrace_ = false; | 315 enable_systrace_ = false; |
| 291 enable_argument_filter_ = false; | 316 enable_argument_filter_ = false; |
| 292 excluded_categories_.push_back("*Debug"); | 317 excluded_categories_.push_back("*Debug"); |
| 293 excluded_categories_.push_back("*Test"); | 318 excluded_categories_.push_back("*Test"); |
| 294 } | 319 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 ci != categories.end(); | 507 ci != categories.end(); |
| 483 ++ci) { | 508 ++ci) { |
| 484 list->AppendString(*ci); | 509 list->AppendString(*ci); |
| 485 } | 510 } |
| 486 | 511 |
| 487 dict.Set(param, std::move(list)); | 512 dict.Set(param, std::move(list)); |
| 488 } | 513 } |
| 489 | 514 |
| 490 void TraceConfig::SetMemoryDumpConfig( | 515 void TraceConfig::SetMemoryDumpConfig( |
| 491 const base::DictionaryValue& memory_dump_config) { | 516 const base::DictionaryValue& memory_dump_config) { |
| 492 memory_dump_config_.clear(); | 517 SetTriggers(memory_dump_config); |
| 518 SetHeapProfilerOptions(memory_dump_config); | |
| 519 } | |
|
Primiano Tucci (use gerrit)
2016/04/22 14:18:29
I'd just do everything in this method, just to avo
Maria
2016/04/25 18:37:24
Done.
| |
| 520 | |
| 521 void TraceConfig::SetTriggers(const base::DictionaryValue& memory_dump_config) { | |
| 522 memory_dump_config_.triggers.clear(); | |
| 493 | 523 |
| 494 const base::ListValue* trigger_list = nullptr; | 524 const base::ListValue* trigger_list = nullptr; |
| 495 if (!memory_dump_config.GetList(kTriggersParam, &trigger_list) || | 525 if (!memory_dump_config.GetList(kTriggersParam, &trigger_list) || |
| 496 trigger_list->GetSize() == 0) { | 526 trigger_list->GetSize() == 0) { |
| 497 return; | 527 return; |
| 498 } | 528 } |
| 499 | 529 |
| 500 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { | 530 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { |
| 501 const base::DictionaryValue* trigger = nullptr; | 531 const base::DictionaryValue* trigger = nullptr; |
| 502 if (!trigger_list->GetDictionary(i, &trigger)) | 532 if (!trigger_list->GetDictionary(i, &trigger)) |
| 503 continue; | 533 continue; |
| 504 | 534 |
| 505 MemoryDumpTriggerConfig dump_config; | 535 MemoryDumpTriggerConfig dump_config; |
| 506 int interval = 0; | 536 int interval = 0; |
| 507 | 537 |
| 508 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { | 538 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { |
| 509 continue; | 539 continue; |
| 510 } | 540 } |
| 511 DCHECK_GT(interval, 0); | 541 DCHECK_GT(interval, 0); |
| 512 dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); | 542 dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); |
| 513 std::string level_of_detail_str; | 543 std::string level_of_detail_str; |
| 514 trigger->GetString(kModeParam, &level_of_detail_str); | 544 trigger->GetString(kModeParam, &level_of_detail_str); |
| 515 dump_config.level_of_detail = | 545 dump_config.level_of_detail = |
| 516 StringToMemoryDumpLevelOfDetail(level_of_detail_str); | 546 StringToMemoryDumpLevelOfDetail(level_of_detail_str); |
| 517 memory_dump_config_.push_back(dump_config); | 547 memory_dump_config_.triggers.push_back(dump_config); |
| 548 } | |
| 549 } | |
| 550 | |
| 551 void TraceConfig::SetHeapProfilerOptions( | |
| 552 const base::DictionaryValue& memory_dump_config) { | |
| 553 const base::DictionaryValue* heap_profiler_options = nullptr; | |
| 554 if (!memory_dump_config.GetDictionary(kHeapProfilerOptions, | |
| 555 &heap_profiler_options)) | |
| 556 return; | |
| 557 | |
| 558 int min_size_bytes = 0; | |
| 559 if (heap_profiler_options->GetInteger(kBreakdownThresholdBytes, | |
| 560 &min_size_bytes) | |
| 561 && min_size_bytes >= 0) { | |
| 562 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = | |
| 563 static_cast<size_t>(min_size_bytes); | |
| 564 } else { | |
| 565 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = | |
| 566 HeapProfilerOptions::kDefaultBreakdownThresholdBytes; | |
| 518 } | 567 } |
| 519 } | 568 } |
| 520 | 569 |
| 521 void TraceConfig::SetDefaultMemoryDumpConfig() { | 570 void TraceConfig::SetDefaultMemoryDumpConfig() { |
| 522 memory_dump_config_.clear(); | 571 memory_dump_config_.Clear(); |
| 523 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); | 572 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
| 524 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); | 573 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
| 525 } | 574 } |
| 526 | 575 |
| 527 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 576 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
| 528 switch (record_mode_) { | 577 switch (record_mode_) { |
| 529 case RECORD_UNTIL_FULL: | 578 case RECORD_UNTIL_FULL: |
| 530 dict.SetString(kRecordModeParam, kRecordUntilFull); | 579 dict.SetString(kRecordModeParam, kRecordUntilFull); |
| 531 break; | 580 break; |
| 532 case RECORD_CONTINUOUSLY: | 581 case RECORD_CONTINUOUSLY: |
| 533 dict.SetString(kRecordModeParam, kRecordContinuously); | 582 dict.SetString(kRecordModeParam, kRecordContinuously); |
| 534 break; | 583 break; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 562 disabled_categories_.begin(), | 611 disabled_categories_.begin(), |
| 563 disabled_categories_.end()); | 612 disabled_categories_.end()); |
| 564 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 613 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
| 565 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 614 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
| 566 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 615 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
| 567 | 616 |
| 568 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 617 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 569 std::unique_ptr<base::DictionaryValue> memory_dump_config( | 618 std::unique_ptr<base::DictionaryValue> memory_dump_config( |
| 570 new base::DictionaryValue()); | 619 new base::DictionaryValue()); |
| 571 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); | 620 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
| 572 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { | 621 for (const MemoryDumpTriggerConfig& config : memory_dump_config_.triggers) { |
| 573 std::unique_ptr<base::DictionaryValue> trigger_dict( | 622 std::unique_ptr<base::DictionaryValue> trigger_dict( |
| 574 new base::DictionaryValue()); | 623 new base::DictionaryValue()); |
| 575 trigger_dict->SetInteger(kPeriodicIntervalParam, | 624 trigger_dict->SetInteger(kPeriodicIntervalParam, |
| 576 static_cast<int>(config.periodic_interval_ms)); | 625 static_cast<int>(config.periodic_interval_ms)); |
| 577 trigger_dict->SetString( | 626 trigger_dict->SetString( |
| 578 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); | 627 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); |
| 579 triggers_list->Append(std::move(trigger_dict)); | 628 triggers_list->Append(std::move(trigger_dict)); |
| 580 } | 629 } |
| 581 | 630 |
| 582 // Empty triggers will still be specified explicitly since it means that | 631 // Empty triggers will still be specified explicitly since it means that |
| 583 // the periodic dumps are not enabled. | 632 // the periodic dumps are not enabled. |
| 584 memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); | 633 memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); |
| 634 | |
| 635 if (memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes != | |
| 636 HeapProfilerOptions::kDefaultBreakdownThresholdBytes) { | |
| 637 std::unique_ptr<base::DictionaryValue> heap_profiler_options( | |
| 638 new base::DictionaryValue()); | |
| 639 heap_profiler_options->SetInteger( | |
| 640 kBreakdownThresholdBytes, | |
| 641 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes); | |
| 642 memory_dump_config->Set(kHeapProfilerOptions, | |
| 643 std::move(heap_profiler_options)); | |
| 644 } | |
| 585 dict.Set(kMemoryDumpConfigParam, std::move(memory_dump_config)); | 645 dict.Set(kMemoryDumpConfigParam, std::move(memory_dump_config)); |
| 586 } | 646 } |
| 587 } | 647 } |
| 588 | 648 |
| 589 std::string TraceConfig::ToTraceOptionsString() const { | 649 std::string TraceConfig::ToTraceOptionsString() const { |
| 590 std::string ret; | 650 std::string ret; |
| 591 switch (record_mode_) { | 651 switch (record_mode_) { |
| 592 case RECORD_UNTIL_FULL: | 652 case RECORD_UNTIL_FULL: |
| 593 ret = kRecordUntilFull; | 653 ret = kRecordUntilFull; |
| 594 break; | 654 break; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 str.at(0) == ' ' || | 732 str.at(0) == ' ' || |
| 673 str.at(str.length() - 1) == ' '; | 733 str.at(str.length() - 1) == ' '; |
| 674 } | 734 } |
| 675 | 735 |
| 676 bool TraceConfig::HasIncludedPatterns() const { | 736 bool TraceConfig::HasIncludedPatterns() const { |
| 677 return !included_categories_.empty(); | 737 return !included_categories_.empty(); |
| 678 } | 738 } |
| 679 | 739 |
| 680 } // namespace trace_event | 740 } // namespace trace_event |
| 681 } // namespace base | 741 } // namespace base |
| OLD | NEW |