Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: base/trace_event/trace_config.cc

Issue 2041583003: [tracing] Introduce "allowed_dump_modes" for memory dump config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@background_config
Patch Set: Change mode to int. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/trace_config.h ('k') | base/trace_event/trace_config_memory_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 const char kEnableArgumentFilterParam[] = "enable_argument_filter"; 40 const char kEnableArgumentFilterParam[] = "enable_argument_filter";
41 const char kIncludedCategoriesParam[] = "included_categories"; 41 const char kIncludedCategoriesParam[] = "included_categories";
42 const char kExcludedCategoriesParam[] = "excluded_categories"; 42 const char kExcludedCategoriesParam[] = "excluded_categories";
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 kAllowedDumpModesParam[] = "allowed_dump_modes";
50 const char kTriggersParam[] = "triggers"; 51 const char kTriggersParam[] = "triggers";
51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; 52 const char kPeriodicIntervalParam[] = "periodic_interval_ms";
52 const char kModeParam[] = "mode"; 53 const char kModeParam[] = "mode";
53 const char kHeapProfilerOptions[] = "heap_profiler_options"; 54 const char kHeapProfilerOptions[] = "heap_profiler_options";
54 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; 55 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes";
55 56
56 // Default configuration of memory dumps. 57 // Default configuration of memory dumps.
57 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { 58 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = {
58 2000, // periodic_interval_ms 59 2000, // periodic_interval_ms
59 MemoryDumpLevelOfDetail::DETAILED}; 60 MemoryDumpLevelOfDetail::DETAILED};
60 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { 61 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = {
61 250, // periodic_interval_ms 62 250, // periodic_interval_ms
62 MemoryDumpLevelOfDetail::LIGHT}; 63 MemoryDumpLevelOfDetail::LIGHT};
63 64
64 class ConvertableTraceConfigToTraceFormat 65 class ConvertableTraceConfigToTraceFormat
65 : public base::trace_event::ConvertableToTraceFormat { 66 : public base::trace_event::ConvertableToTraceFormat {
66 public: 67 public:
67 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) 68 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config)
68 : trace_config_(trace_config) {} 69 : trace_config_(trace_config) {}
69 ~ConvertableTraceConfigToTraceFormat() override {} 70 ~ConvertableTraceConfigToTraceFormat() override {}
70 void AppendAsTraceFormat(std::string* out) const override { 71 void AppendAsTraceFormat(std::string* out) const override {
71 out->append(trace_config_.ToString()); 72 out->append(trace_config_.ToString());
72 } 73 }
73 74
74 private: 75 private:
75 const TraceConfig trace_config_; 76 const TraceConfig trace_config_;
76 }; 77 };
77 78
79 std::set<MemoryDumpLevelOfDetail> GetDefaultAllowedMemoryDumpModes() {
80 std::set<MemoryDumpLevelOfDetail> all_modes;
81 for (uint32_t mode = static_cast<uint32_t>(MemoryDumpLevelOfDetail::FIRST);
82 mode <= static_cast<uint32_t>(MemoryDumpLevelOfDetail::LAST); mode++) {
83 all_modes.insert(static_cast<MemoryDumpLevelOfDetail>(mode));
84 }
85 return all_modes;
86 }
87
78 } // namespace 88 } // namespace
79 89
80 90
81 TraceConfig::MemoryDumpConfig::HeapProfiler::HeapProfiler() : 91 TraceConfig::MemoryDumpConfig::HeapProfiler::HeapProfiler() :
82 breakdown_threshold_bytes(kDefaultBreakdownThresholdBytes) {}; 92 breakdown_threshold_bytes(kDefaultBreakdownThresholdBytes) {};
83 93
84 void TraceConfig::MemoryDumpConfig::HeapProfiler::Clear() { 94 void TraceConfig::MemoryDumpConfig::HeapProfiler::Clear() {
85 breakdown_threshold_bytes = kDefaultBreakdownThresholdBytes; 95 breakdown_threshold_bytes = kDefaultBreakdownThresholdBytes;
86 } 96 }
87 97
88 void TraceConfig::ResetMemoryDumpConfig( 98 void TraceConfig::ResetMemoryDumpConfig(
89 const TraceConfig::MemoryDumpConfig& memory_dump_config) { 99 const TraceConfig::MemoryDumpConfig& memory_dump_config) {
90 memory_dump_config_.Clear(); 100 memory_dump_config_.Clear();
91 memory_dump_config_ = memory_dump_config; 101 memory_dump_config_ = memory_dump_config;
92 } 102 }
93 103
94 TraceConfig::MemoryDumpConfig::MemoryDumpConfig() {}; 104 TraceConfig::MemoryDumpConfig::MemoryDumpConfig() {};
95 105
96 TraceConfig::MemoryDumpConfig::MemoryDumpConfig( 106 TraceConfig::MemoryDumpConfig::MemoryDumpConfig(
97 const MemoryDumpConfig& other) = default; 107 const MemoryDumpConfig& other) = default;
98 108
99 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; 109 TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {};
100 110
101 void TraceConfig::MemoryDumpConfig::Clear() { 111 void TraceConfig::MemoryDumpConfig::Clear() {
112 allowed_dump_modes.clear();
102 triggers.clear(); 113 triggers.clear();
103 heap_profiler_options.Clear(); 114 heap_profiler_options.Clear();
104 } 115 }
105 116
106 TraceConfig::TraceConfig() { 117 TraceConfig::TraceConfig() {
107 InitializeDefault(); 118 InitializeDefault();
108 } 119 }
109 120
110 TraceConfig::TraceConfig(const std::string& category_filter_string, 121 TraceConfig::TraceConfig(const std::string& category_filter_string,
111 const std::string& trace_options_string) { 122 const std::string& trace_options_string) {
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ci != categories.end(); 519 ci != categories.end();
509 ++ci) { 520 ++ci) {
510 list->AppendString(*ci); 521 list->AppendString(*ci);
511 } 522 }
512 523
513 dict.Set(param, std::move(list)); 524 dict.Set(param, std::move(list));
514 } 525 }
515 526
516 void TraceConfig::SetMemoryDumpConfigFromConfigDict( 527 void TraceConfig::SetMemoryDumpConfigFromConfigDict(
517 const base::DictionaryValue& memory_dump_config) { 528 const base::DictionaryValue& memory_dump_config) {
529 // Set allowed dump modes.
530 memory_dump_config_.allowed_dump_modes.clear();
531 const base::ListValue* allowed_modes_list;
532 if (memory_dump_config.GetList(kAllowedDumpModesParam, &allowed_modes_list)) {
533 for (size_t i = 0; i < allowed_modes_list->GetSize(); ++i) {
534 std::string level_of_detail_str;
535 allowed_modes_list->GetString(i, &level_of_detail_str);
536 memory_dump_config_.allowed_dump_modes.insert(
537 StringToMemoryDumpLevelOfDetail(level_of_detail_str));
538 }
539 } else {
540 // If allowed modes param is not given then allow all modes by default.
541 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes();
542 }
543
518 // Set triggers 544 // Set triggers
519 memory_dump_config_.triggers.clear(); 545 memory_dump_config_.triggers.clear();
520
521 const base::ListValue* trigger_list = nullptr; 546 const base::ListValue* trigger_list = nullptr;
522 if (memory_dump_config.GetList(kTriggersParam, &trigger_list) && 547 if (memory_dump_config.GetList(kTriggersParam, &trigger_list) &&
523 trigger_list->GetSize() > 0) { 548 trigger_list->GetSize() > 0) {
524 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { 549 for (size_t i = 0; i < trigger_list->GetSize(); ++i) {
525 const base::DictionaryValue* trigger = nullptr; 550 const base::DictionaryValue* trigger = nullptr;
526 if (!trigger_list->GetDictionary(i, &trigger)) 551 if (!trigger_list->GetDictionary(i, &trigger))
527 continue; 552 continue;
528 553
529 MemoryDumpConfig::Trigger dump_config; 554 MemoryDumpConfig::Trigger dump_config;
530 int interval = 0; 555 int interval = 0;
(...skipping 25 matching lines...) Expand all
556 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = 581 memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes =
557 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes; 582 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes;
558 } 583 }
559 } 584 }
560 } 585 }
561 586
562 void TraceConfig::SetDefaultMemoryDumpConfig() { 587 void TraceConfig::SetDefaultMemoryDumpConfig() {
563 memory_dump_config_.Clear(); 588 memory_dump_config_.Clear();
564 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); 589 memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger);
565 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); 590 memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger);
591 memory_dump_config_.allowed_dump_modes = GetDefaultAllowedMemoryDumpModes();
566 } 592 }
567 593
568 void TraceConfig::ToDict(base::DictionaryValue& dict) const { 594 void TraceConfig::ToDict(base::DictionaryValue& dict) const {
569 switch (record_mode_) { 595 switch (record_mode_) {
570 case RECORD_UNTIL_FULL: 596 case RECORD_UNTIL_FULL:
571 dict.SetString(kRecordModeParam, kRecordUntilFull); 597 dict.SetString(kRecordModeParam, kRecordUntilFull);
572 break; 598 break;
573 case RECORD_CONTINUOUSLY: 599 case RECORD_CONTINUOUSLY:
574 dict.SetString(kRecordModeParam, kRecordContinuously); 600 dict.SetString(kRecordModeParam, kRecordContinuously);
575 break; 601 break;
(...skipping 26 matching lines...) Expand all
602 categories.insert(categories.end(), 628 categories.insert(categories.end(),
603 disabled_categories_.begin(), 629 disabled_categories_.begin(),
604 disabled_categories_.end()); 630 disabled_categories_.end());
605 AddCategoryToDict(dict, kIncludedCategoriesParam, categories); 631 AddCategoryToDict(dict, kIncludedCategoriesParam, categories);
606 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_); 632 AddCategoryToDict(dict, kExcludedCategoriesParam, excluded_categories_);
607 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_); 633 AddCategoryToDict(dict, kSyntheticDelaysParam, synthetic_delays_);
608 634
609 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) { 635 if (IsCategoryEnabled(MemoryDumpManager::kTraceCategory)) {
610 std::unique_ptr<base::DictionaryValue> memory_dump_config( 636 std::unique_ptr<base::DictionaryValue> memory_dump_config(
611 new base::DictionaryValue()); 637 new base::DictionaryValue());
638 std::unique_ptr<base::ListValue> allowed_modes_list(new base::ListValue());
639 for (MemoryDumpLevelOfDetail dump_mode :
640 memory_dump_config_.allowed_dump_modes) {
641 allowed_modes_list->AppendString(
642 MemoryDumpLevelOfDetailToString(dump_mode));
643 }
644 memory_dump_config->Set(kAllowedDumpModesParam,
645 std::move(allowed_modes_list));
646
612 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); 647 std::unique_ptr<base::ListValue> triggers_list(new base::ListValue());
613 for (const MemoryDumpConfig::Trigger& config 648 for (const MemoryDumpConfig::Trigger& config
614 : memory_dump_config_.triggers) { 649 : memory_dump_config_.triggers) {
615 std::unique_ptr<base::DictionaryValue> trigger_dict( 650 std::unique_ptr<base::DictionaryValue> trigger_dict(
616 new base::DictionaryValue()); 651 new base::DictionaryValue());
617 trigger_dict->SetInteger(kPeriodicIntervalParam, 652 trigger_dict->SetInteger(kPeriodicIntervalParam,
618 static_cast<int>(config.periodic_interval_ms)); 653 static_cast<int>(config.periodic_interval_ms));
619 trigger_dict->SetString( 654 trigger_dict->SetString(
620 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); 655 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail));
621 triggers_list->Append(std::move(trigger_dict)); 656 triggers_list->Append(std::move(trigger_dict));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 str.at(0) == ' ' || 760 str.at(0) == ' ' ||
726 str.at(str.length() - 1) == ' '; 761 str.at(str.length() - 1) == ' ';
727 } 762 }
728 763
729 bool TraceConfig::HasIncludedPatterns() const { 764 bool TraceConfig::HasIncludedPatterns() const {
730 return !included_categories_.empty(); 765 return !included_categories_.empty();
731 } 766 }
732 767
733 } // namespace trace_event 768 } // namespace trace_event
734 } // namespace base 769 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_config.h ('k') | base/trace_event/trace_config_memory_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698