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

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

Issue 2542853002: [tracing] Introduce config to setup memory-infra peak detection (Closed)
Patch Set: Fixes. Created 4 years 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
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 30 matching lines...) Expand all
41 const char kExcludedCategoriesParam[] = "excluded_categories"; 41 const char kExcludedCategoriesParam[] = "excluded_categories";
42 const char kSyntheticDelaysParam[] = "synthetic_delays"; 42 const char kSyntheticDelaysParam[] = "synthetic_delays";
43 43
44 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY("; 44 const char kSyntheticDelayCategoryFilterPrefix[] = "DELAY(";
45 45
46 // String parameters that is used to parse memory dump config in trace config 46 // String parameters that is used to parse memory dump config in trace config
47 // string. 47 // string.
48 const char kMemoryDumpConfigParam[] = "memory_dump_config"; 48 const char kMemoryDumpConfigParam[] = "memory_dump_config";
49 const char kAllowedDumpModesParam[] = "allowed_dump_modes"; 49 const char kAllowedDumpModesParam[] = "allowed_dump_modes";
50 const char kTriggersParam[] = "triggers"; 50 const char kTriggersParam[] = "triggers";
51 const char kPeriodicIntervalParam[] = "periodic_interval_ms"; 51 const char kTriggerModeParam[] = "mode";
52 const char kModeParam[] = "mode"; 52 const char kMinTimeBetweenDumps[] = "min_time_between_dumps_ms";
53 const char kTriggerTypeParam[] = "type";
54 const char kPeriodicIntervalLegacyParam[] = "periodic_interval_ms";
53 const char kHeapProfilerOptions[] = "heap_profiler_options"; 55 const char kHeapProfilerOptions[] = "heap_profiler_options";
54 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; 56 const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes";
55 57
56 // String parameters used to parse category event filters. 58 // String parameters used to parse category event filters.
57 const char kEventFiltersParam[] = "event_filters"; 59 const char kEventFiltersParam[] = "event_filters";
58 const char kFilterPredicateParam[] = "filter_predicate"; 60 const char kFilterPredicateParam[] = "filter_predicate";
59 const char kFilterArgsParam[] = "filter_args"; 61 const char kFilterArgsParam[] = "filter_args";
60 62
61 // Default configuration of memory dumps. 63 // Default configuration of memory dumps.
62 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = { 64 const TraceConfig::MemoryDumpConfig::Trigger kDefaultHeavyMemoryDumpTrigger = {
63 2000, // periodic_interval_ms 65 2000, // min_time_between_dumps_ms
64 MemoryDumpLevelOfDetail::DETAILED}; 66 MemoryDumpLevelOfDetail::DETAILED, MemoryDumpType::PERIODIC_INTERVAL};
65 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = { 67 const TraceConfig::MemoryDumpConfig::Trigger kDefaultLightMemoryDumpTrigger = {
66 250, // periodic_interval_ms 68 250, // min_time_between_dumps_ms
67 MemoryDumpLevelOfDetail::LIGHT}; 69 MemoryDumpLevelOfDetail::LIGHT, MemoryDumpType::PERIODIC_INTERVAL};
68 70
69 class ConvertableTraceConfigToTraceFormat 71 class ConvertableTraceConfigToTraceFormat
70 : public base::trace_event::ConvertableToTraceFormat { 72 : public base::trace_event::ConvertableToTraceFormat {
71 public: 73 public:
72 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config) 74 explicit ConvertableTraceConfigToTraceFormat(const TraceConfig& trace_config)
73 : trace_config_(trace_config) {} 75 : trace_config_(trace_config) {}
74 76
75 ~ConvertableTraceConfigToTraceFormat() override {} 77 ~ConvertableTraceConfigToTraceFormat() override {}
76 78
77 void AppendAsTraceFormat(std::string* out) const override { 79 void AppendAsTraceFormat(std::string* out) const override {
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // Set triggers 601 // Set triggers
600 memory_dump_config_.triggers.clear(); 602 memory_dump_config_.triggers.clear();
601 const ListValue* trigger_list = nullptr; 603 const ListValue* trigger_list = nullptr;
602 if (memory_dump_config.GetList(kTriggersParam, &trigger_list) && 604 if (memory_dump_config.GetList(kTriggersParam, &trigger_list) &&
603 trigger_list->GetSize() > 0) { 605 trigger_list->GetSize() > 0) {
604 for (size_t i = 0; i < trigger_list->GetSize(); ++i) { 606 for (size_t i = 0; i < trigger_list->GetSize(); ++i) {
605 const DictionaryValue* trigger = nullptr; 607 const DictionaryValue* trigger = nullptr;
606 if (!trigger_list->GetDictionary(i, &trigger)) 608 if (!trigger_list->GetDictionary(i, &trigger))
607 continue; 609 continue;
608 610
611 MemoryDumpConfig::Trigger dump_config;
609 int interval = 0; 612 int interval = 0;
610 if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) 613 if (!trigger->GetInteger(kMinTimeBetweenDumps, &interval)) {
611 continue; 614 // If "min_time_between_dumps_ms" param was not given, then the trace
615 // config uses old format where only periodic dumps are supported.
616 trigger->GetInteger(kPeriodicIntervalLegacyParam, &interval);
617 dump_config.trigger_type = MemoryDumpType::PERIODIC_INTERVAL;
618 } else {
619 std::string trigger_type_str;
620 trigger->GetString(kTriggerTypeParam, &trigger_type_str);
621 dump_config.trigger_type = StringToMemoryDumpType(trigger_type_str);
622 }
623 DCHECK_GT(interval, 0);
624 dump_config.min_time_between_dumps_ms = static_cast<uint32_t>(interval);
612 625
613 DCHECK_GT(interval, 0);
614 MemoryDumpConfig::Trigger dump_config;
615 dump_config.periodic_interval_ms = static_cast<uint32_t>(interval);
616 std::string level_of_detail_str; 626 std::string level_of_detail_str;
617 trigger->GetString(kModeParam, &level_of_detail_str); 627 trigger->GetString(kTriggerModeParam, &level_of_detail_str);
618 dump_config.level_of_detail = 628 dump_config.level_of_detail =
619 StringToMemoryDumpLevelOfDetail(level_of_detail_str); 629 StringToMemoryDumpLevelOfDetail(level_of_detail_str);
630
620 memory_dump_config_.triggers.push_back(dump_config); 631 memory_dump_config_.triggers.push_back(dump_config);
621 } 632 }
622 } 633 }
623 634
624 // Set heap profiler options 635 // Set heap profiler options
625 const DictionaryValue* heap_profiler_options = nullptr; 636 const DictionaryValue* heap_profiler_options = nullptr;
626 if (memory_dump_config.GetDictionary(kHeapProfilerOptions, 637 if (memory_dump_config.GetDictionary(kHeapProfilerOptions,
627 &heap_profiler_options)) { 638 &heap_profiler_options)) {
628 int min_size_bytes = 0; 639 int min_size_bytes = 0;
629 if (heap_profiler_options->GetInteger(kBreakdownThresholdBytes, 640 if (heap_profiler_options->GetInteger(kBreakdownThresholdBytes,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 auto allowed_modes = MakeUnique<ListValue>(); 769 auto allowed_modes = MakeUnique<ListValue>();
759 for (auto dump_mode : memory_dump_config_.allowed_dump_modes) 770 for (auto dump_mode : memory_dump_config_.allowed_dump_modes)
760 allowed_modes->AppendString(MemoryDumpLevelOfDetailToString(dump_mode)); 771 allowed_modes->AppendString(MemoryDumpLevelOfDetailToString(dump_mode));
761 772
762 auto memory_dump_config = MakeUnique<DictionaryValue>(); 773 auto memory_dump_config = MakeUnique<DictionaryValue>();
763 memory_dump_config->Set(kAllowedDumpModesParam, std::move(allowed_modes)); 774 memory_dump_config->Set(kAllowedDumpModesParam, std::move(allowed_modes));
764 775
765 auto triggers_list = MakeUnique<ListValue>(); 776 auto triggers_list = MakeUnique<ListValue>();
766 for (const auto& config : memory_dump_config_.triggers) { 777 for (const auto& config : memory_dump_config_.triggers) {
767 auto trigger_dict = MakeUnique<DictionaryValue>(); 778 auto trigger_dict = MakeUnique<DictionaryValue>();
768 trigger_dict->SetInteger(kPeriodicIntervalParam, 779 trigger_dict->SetString(kTriggerTypeParam,
769 static_cast<int>(config.periodic_interval_ms)); 780 MemoryDumpTypeToString(config.trigger_type));
781 trigger_dict->SetInteger(
782 kMinTimeBetweenDumps,
783 static_cast<int>(config.min_time_between_dumps_ms));
770 trigger_dict->SetString( 784 trigger_dict->SetString(
771 kModeParam, MemoryDumpLevelOfDetailToString(config.level_of_detail)); 785 kTriggerModeParam,
786 MemoryDumpLevelOfDetailToString(config.level_of_detail));
772 triggers_list->Append(std::move(trigger_dict)); 787 triggers_list->Append(std::move(trigger_dict));
773 } 788 }
774 789
775 // Empty triggers will still be specified explicitly since it means that 790 // Empty triggers will still be specified explicitly since it means that
776 // the periodic dumps are not enabled. 791 // the periodic dumps are not enabled.
777 memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); 792 memory_dump_config->Set(kTriggersParam, std::move(triggers_list));
778 793
779 if (memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes != 794 if (memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes !=
780 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes) { 795 MemoryDumpConfig::HeapProfiler::kDefaultBreakdownThresholdBytes) {
781 auto options = MakeUnique<DictionaryValue>(); 796 auto options = MakeUnique<DictionaryValue>();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 StringPiece str) { 878 StringPiece str) {
864 return str.empty() || str.front() == ' ' || str.back() == ' '; 879 return str.empty() || str.front() == ' ' || str.back() == ' ';
865 } 880 }
866 881
867 bool TraceConfig::HasIncludedPatterns() const { 882 bool TraceConfig::HasIncludedPatterns() const {
868 return !included_categories_.empty(); 883 return !included_categories_.empty();
869 } 884 }
870 885
871 } // namespace trace_event 886 } // namespace trace_event
872 } // namespace base 887 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698