| 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::MemoryDumpConfig::Trigger 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::MemoryDumpConfig::Trigger 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::MemoryDumpConfig::HeapProfiler::HeapProfiler() : |
| 82 breakdown_threshold_bytes(kDefaultBreakdownThresholdBytes) {}; |
| 83 |
| 84 void TraceConfig::MemoryDumpConfig::HeapProfiler::Clear() { |
| 85 breakdown_threshold_bytes = kDefaultBreakdownThresholdBytes; |
| 86 } |
| 87 |
| 88 TraceConfig::MemoryDumpConfig::MemoryDumpConfig() {}; |
| 89 |
| 90 TraceConfig::MemoryDumpConfig::MemoryDumpConfig( |
| 91 const MemoryDumpConfig& other) = default; |
| 92 |
| 93 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; |
| 94 |
| 95 void TraceConfig::MemoryDumpConfig::Clear() { |
| 96 triggers.clear(); |
| 97 heap_profiler_options.Clear(); |
| 98 } |
| 99 |
| 78 TraceConfig::TraceConfig() { | 100 TraceConfig::TraceConfig() { |
| 79 InitializeDefault(); | 101 InitializeDefault(); |
| 80 } | 102 } |
| 81 | 103 |
| 82 TraceConfig::TraceConfig(const std::string& category_filter_string, | 104 TraceConfig::TraceConfig(const std::string& category_filter_string, |
| 83 const std::string& trace_options_string) { | 105 const std::string& trace_options_string) { |
| 84 InitializeFromStrings(category_filter_string, trace_options_string); | 106 InitializeFromStrings(category_filter_string, trace_options_string); |
| 85 } | 107 } |
| 86 | 108 |
| 87 TraceConfig::TraceConfig(const std::string& category_filter_string, | 109 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 | 272 // Otherwise, one of the filter was specifying "*" and we want to honor the |
| 251 // broadest filter. | 273 // broadest filter. |
| 252 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { | 274 if (HasIncludedPatterns() && config.HasIncludedPatterns()) { |
| 253 included_categories_.insert(included_categories_.end(), | 275 included_categories_.insert(included_categories_.end(), |
| 254 config.included_categories_.begin(), | 276 config.included_categories_.begin(), |
| 255 config.included_categories_.end()); | 277 config.included_categories_.end()); |
| 256 } else { | 278 } else { |
| 257 included_categories_.clear(); | 279 included_categories_.clear(); |
| 258 } | 280 } |
| 259 | 281 |
| 260 memory_dump_config_.insert(memory_dump_config_.end(), | 282 memory_dump_config_.triggers.insert(memory_dump_config_.triggers.end(), |
| 261 config.memory_dump_config_.begin(), | 283 config.memory_dump_config_.triggers.begin(), |
| 262 config.memory_dump_config_.end()); | 284 config.memory_dump_config_.triggers.end()); |
| 263 | 285 |
| 264 disabled_categories_.insert(disabled_categories_.end(), | 286 disabled_categories_.insert(disabled_categories_.end(), |
| 265 config.disabled_categories_.begin(), | 287 config.disabled_categories_.begin(), |
| 266 config.disabled_categories_.end()); | 288 config.disabled_categories_.end()); |
| 267 excluded_categories_.insert(excluded_categories_.end(), | 289 excluded_categories_.insert(excluded_categories_.end(), |
| 268 config.excluded_categories_.begin(), | 290 config.excluded_categories_.begin(), |
| 269 config.excluded_categories_.end()); | 291 config.excluded_categories_.end()); |
| 270 synthetic_delays_.insert(synthetic_delays_.end(), | 292 synthetic_delays_.insert(synthetic_delays_.end(), |
| 271 config.synthetic_delays_.begin(), | 293 config.synthetic_delays_.begin(), |
| 272 config.synthetic_delays_.end()); | 294 config.synthetic_delays_.end()); |
| 273 } | 295 } |
| 274 | 296 |
| 275 void TraceConfig::Clear() { | 297 void TraceConfig::Clear() { |
| 276 record_mode_ = RECORD_UNTIL_FULL; | 298 record_mode_ = RECORD_UNTIL_FULL; |
| 277 enable_sampling_ = false; | 299 enable_sampling_ = false; |
| 278 enable_systrace_ = false; | 300 enable_systrace_ = false; |
| 279 enable_argument_filter_ = false; | 301 enable_argument_filter_ = false; |
| 280 included_categories_.clear(); | 302 included_categories_.clear(); |
| 281 disabled_categories_.clear(); | 303 disabled_categories_.clear(); |
| 282 excluded_categories_.clear(); | 304 excluded_categories_.clear(); |
| 283 synthetic_delays_.clear(); | 305 synthetic_delays_.clear(); |
| 284 memory_dump_config_.clear(); | 306 memory_dump_config_.Clear(); |
| 285 } | 307 } |
| 286 | 308 |
| 287 void TraceConfig::InitializeDefault() { | 309 void TraceConfig::InitializeDefault() { |
| 288 record_mode_ = RECORD_UNTIL_FULL; | 310 record_mode_ = RECORD_UNTIL_FULL; |
| 289 enable_sampling_ = false; | 311 enable_sampling_ = false; |
| 290 enable_systrace_ = false; | 312 enable_systrace_ = false; |
| 291 enable_argument_filter_ = false; | 313 enable_argument_filter_ = false; |
| 292 excluded_categories_.push_back("*Debug"); | 314 excluded_categories_.push_back("*Debug"); |
| 293 excluded_categories_.push_back("*Test"); | 315 excluded_categories_.push_back("*Test"); |
| 294 } | 316 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 ci != categories.end(); | 504 ci != categories.end(); |
| 483 ++ci) { | 505 ++ci) { |
| 484 list->AppendString(*ci); | 506 list->AppendString(*ci); |
| 485 } | 507 } |
| 486 | 508 |
| 487 dict.Set(param, std::move(list)); | 509 dict.Set(param, std::move(list)); |
| 488 } | 510 } |
| 489 | 511 |
| 490 void TraceConfig::SetMemoryDumpConfig( | 512 void TraceConfig::SetMemoryDumpConfig( |
| 491 const base::DictionaryValue& memory_dump_config) { | 513 const base::DictionaryValue& memory_dump_config) { |
| 492 memory_dump_config_.clear(); | 514 // Set triggers |
| 515 memory_dump_config_.triggers.clear(); |
| 493 | 516 |
| 494 const base::ListValue* trigger_list = nullptr; | 517 const base::ListValue* trigger_list = nullptr; |
| 495 if (!memory_dump_config.GetList(kTriggersParam, &trigger_list) || | 518 if (memory_dump_config.GetList(kTriggersParam, &trigger_list) && |
| 496 trigger_list->GetSize() == 0) { | 519 trigger_list->GetSize() > 0) { |
| 497 return; | 520 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { |
| 521 const base::DictionaryValue* trigger = nullptr; |
| 522 if (!trigger_list->GetDictionary(i, &trigger)) |
| 523 continue; |
| 524 |
| 525 MemoryDumpConfig::Trigger dump_config; |
| 526 int interval = 0; |
| 527 |
| 528 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { |
| 529 continue; |
| 530 } |
| 531 DCHECK_GT(interval, 0); |
| 532 dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); |
| 533 std::string level_of_detail_str; |
| 534 trigger->GetString(kModeParam, &level_of_detail_str); |
| 535 dump_config.level_of_detail = |
| 536 StringToMemoryDumpLevelOfDetail(level_of_detail_str); |
| 537 memory_dump_config_.triggers.push_back(dump_config); |
| 538 } |
| 498 } | 539 } |
| 499 | 540 |
| 500 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { | 541 // Set heap profiler options |
| 501 const base::DictionaryValue* trigger = nullptr; | 542 const base::DictionaryValue* heap_profiler_options = nullptr; |
| 502 if (!trigger_list->GetDictionary(i, &trigger)) | 543 if (memory_dump_config.GetDictionary(kHeapProfilerOptions, |
| 503 continue; | 544 &heap_profiler_options)) { |
| 504 | 545 int min_size_bytes = 0; |
| 505 MemoryDumpTriggerConfig dump_config; | 546 if (heap_profiler_options->GetInteger(kBreakdownThresholdBytes, |
| 506 int interval = 0; | 547 &min_size_bytes) |
| 507 | 548 && min_size_bytes >= 0) { |
| 508 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { | 549 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = |
| 509 continue; | 550 static_cast<size_t>(min_size_bytes); |
| 551 } else { |
| 552 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = |
| 553 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; |
| 510 } | 554 } |
| 511 DCHECK_GT(interval, 0); | |
| 512 dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); | |
| 513 std::string level_of_detail_str; | |
| 514 trigger->GetString(kModeParam, &level_of_detail_str); | |
| 515 dump_config.level_of_detail = | |
| 516 StringToMemoryDumpLevelOfDetail(level_of_detail_str); | |
| 517 memory_dump_config_.push_back(dump_config); | |
| 518 } | 555 } |
| 519 } | 556 } |
| 520 | 557 |
| 521 void TraceConfig::SetDefaultMemoryDumpConfig() { | 558 void TraceConfig::SetDefaultMemoryDumpConfig() { |
| 522 memory_dump_config_.clear(); | 559 memory_dump_config_.Clear(); |
| 523 memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); | 560 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
| 524 memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); | 561 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
| 525 } | 562 } |
| 526 | 563 |
| 527 void TraceConfig::ToDict(base::DictionaryValue& dict) const { | 564 void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
| 528 switch (record_mode_) { | 565 switch (record_mode_) { |
| 529 case RECORD_UNTIL_FULL: | 566 case RECORD_UNTIL_FULL: |
| 530 dict.SetString(kRecordModeParam, kRecordUntilFull); | 567 dict.SetString(kRecordModeParam, kRecordUntilFull); |
| 531 break; | 568 break; |
| 532 case RECORD_CONTINUOUSLY: | 569 case RECORD_CONTINUOUSLY: |
| 533 dict.SetString(kRecordModeParam, kRecordContinuously); | 570 dict.SetString(kRecordModeParam, kRecordContinuously); |
| 534 break; | 571 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 562 disabled_categories_.begin(), | 599 disabled_categories_.begin(), |
| 563 disabled_categories_.end()); | 600 disabled_categories_.end()); |
| 564 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); | 601 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); |
| 565 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); | 602 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); |
| 566 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); | 603 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); |
| 567 | 604 |
| 568 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { | 605 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { |
| 569 std::unique_ptr<base::DictionaryValue> memory_dump_config( | 606 std::unique_ptr<base::DictionaryValue> memory_dump_config( |
| 570 new base::DictionaryValue()); | 607 new base::DictionaryValue()); |
| 571 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); | 608 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
| 572 for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { | 609 for (const MemoryDumpConfig::Trigger& config |
| 610 : memory_dump_config_.triggers) { |
| 573 std::unique_ptr<base::DictionaryValue> trigger_dict( | 611 std::unique_ptr<base::DictionaryValue> trigger_dict( |
| 574 new base::DictionaryValue()); | 612 new base::DictionaryValue()); |
| 575 trigger_dict->SetInteger(kPeriodicIntervalParam, | 613 trigger_dict->SetInteger(kPeriodicIntervalParam, |
| 576 static_cast<int>(config.periodic_interval_ms)); | 614 static_cast<int>(config.periodic_interval_ms)); |
| 577 trigger_dict->SetString( | 615 trigger_dict->SetString( |
| 578 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); | 616 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); |
| 579 triggers_list->Append(std::move(trigger_dict)); | 617 triggers_list->Append(std::move(trigger_dict)); |
| 580 } | 618 } |
| 581 | 619 |
| 582 // Empty triggers will still be specified explicitly since it means that | 620 // Empty triggers will still be specified explicitly since it means that |
| 583 // the periodic dumps are not enabled. | 621 // the periodic dumps are not enabled. |
| 584 memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); | 622 memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); |
| 623 |
| 624 if (memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes != |
| 625 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes) { |
| 626 std::unique_ptr<base::DictionaryValue> heap_profiler_options( |
| 627 new base::DictionaryValue()); |
| 628 heap_profiler_options->SetInteger( |
| 629 kBreakdownThresholdBytes, |
| 630 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes); |
| 631 memory_dump_config->Set(kHeapProfilerOptions, |
| 632 std::move(heap_profiler_options)); |
| 633 } |
| 585 dict.Set(kMemoryDumpConfigParam, std::move(memory_dump_config)); | 634 dict.Set(kMemoryDumpConfigParam, std::move(memory_dump_config)); |
| 586 } | 635 } |
| 587 } | 636 } |
| 588 | 637 |
| 589 std::string TraceConfig::ToTraceOptionsString() const { | 638 std::string TraceConfig::ToTraceOptionsString() const { |
| 590 std::string ret; | 639 std::string ret; |
| 591 switch (record_mode_) { | 640 switch (record_mode_) { |
| 592 case RECORD_UNTIL_FULL: | 641 case RECORD_UNTIL_FULL: |
| 593 ret = kRecordUntilFull; | 642 ret = kRecordUntilFull; |
| 594 break; | 643 break; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 str.at(0) == ' ' || | 721 str.at(0) == ' ' || |
| 673 str.at(str.length() - 1) == ' '; | 722 str.at(str.length() - 1) == ' '; |
| 674 } | 723 } |
| 675 | 724 |
| 676 bool TraceConfig::HasIncludedPatterns() const { | 725 bool TraceConfig::HasIncludedPatterns() const { |
| 677 return !included_categories_.empty(); | 726 return !included_categories_.empty(); |
| 678 } | 727 } |
| 679 | 728 |
| 680 } // namespace trace_event | 729 } // namespace trace_event |
| 681 } // namespace base | 730 } // namespace base |
| OLD | NEW |