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