Chromium Code Reviews| Index: base/trace_event/trace_config.cc |
| diff --git a/base/trace_event/trace_config.cc b/base/trace_event/trace_config.cc |
| index e9e5a099893377e844be716845b0bbcfe90a2639..324710f833588d9e0f50114d11206cb9e318b601 100644 |
| --- a/base/trace_event/trace_config.cc |
| +++ b/base/trace_event/trace_config.cc |
| @@ -50,12 +50,14 @@ const char kMemoryDumpConfigParam[] = "memory_dump_config"; |
| const char kTriggersParam[] = "triggers"; |
| const char kPeriodicIntervalParam[] = "periodic_interval_ms"; |
| const char kModeParam[] = "mode"; |
| +const char kHeapProfilerOptions[] = "heap_profiler_options"; |
| +const char kBreakdownThresholdBytes[] = "breakdown_threshold_bytes"; |
| // Default configuration of memory dumps. |
| -const TraceConfig::MemoryDumpTriggerConfig kDefaultHeavyMemoryDumpTrigger = { |
| +const TraceConfig::MemoryDumpTrigger kDefaultHeavyMemoryDumpTrigger = { |
| 2000, // periodic_interval_ms |
| MemoryDumpLevelOfDetail::DETAILED}; |
| -const TraceConfig::MemoryDumpTriggerConfig kDefaultLightMemoryDumpTrigger = { |
| +const TraceConfig::MemoryDumpTrigger kDefaultLightMemoryDumpTrigger = { |
| 250, // periodic_interval_ms |
| MemoryDumpLevelOfDetail::LIGHT}; |
| @@ -75,6 +77,28 @@ class ConvertableTraceConfigToTraceFormat |
| } // namespace |
| + |
| +TraceConfig::MemoryDumpConfig::HeapProfilerOptions::HeapProfilerOptions() : |
| + breakdown_threshold_bytes(kDefaultBreakdownThresholdBytes) {}; |
| + |
| +TraceConfig::MemoryDumpConfig::HeapProfilerOptions::~HeapProfilerOptions() {}; |
| + |
| +void TraceConfig::MemoryDumpConfig::HeapProfilerOptions::Clear() { |
| + breakdown_threshold_bytes = kDefaultBreakdownThresholdBytes; |
| +} |
| + |
| +TraceConfig::MemoryDumpConfig::MemoryDumpConfig() {}; |
| + |
| +TraceConfig::MemoryDumpConfig::MemoryDumpConfig( |
| + const MemoryDumpConfig& other) = default; |
| + |
| +TraceConfig::MemoryDumpConfig::~MemoryDumpConfig() {}; |
| + |
| +void TraceConfig::MemoryDumpConfig::Clear() { |
| + triggers.clear(); |
| + heap_profiler_options.Clear(); |
| +} |
| + |
| TraceConfig::TraceConfig() { |
| InitializeDefault(); |
| } |
| @@ -257,9 +281,9 @@ void TraceConfig::Merge(const TraceConfig& config) { |
| included_categories_.clear(); |
| } |
| - memory_dump_config_.insert(memory_dump_config_.end(), |
| - config.memory_dump_config_.begin(), |
| - config.memory_dump_config_.end()); |
| + memory_dump_config_.triggers.insert(memory_dump_config_.triggers.end(), |
| + config.memory_dump_config_.triggers.begin(), |
| + config.memory_dump_config_.triggers.end()); |
| disabled_categories_.insert(disabled_categories_.end(), |
| config.disabled_categories_.begin(), |
| @@ -281,7 +305,7 @@ void TraceConfig::Clear() { |
| disabled_categories_.clear(); |
| excluded_categories_.clear(); |
| synthetic_delays_.clear(); |
| - memory_dump_config_.clear(); |
| + memory_dump_config_.Clear(); |
| } |
| void TraceConfig::InitializeDefault() { |
| @@ -489,39 +513,54 @@ void TraceConfig::AddCategoryToDict(base::DictionaryValue& dict, |
| void TraceConfig::SetMemoryDumpConfig( |
| const base::DictionaryValue& memory_dump_config) { |
| - memory_dump_config_.clear(); |
| + // Set triggers |
| + memory_dump_config_.triggers.clear(); |
| const base::ListValue* trigger_list = nullptr; |
| - if (!memory_dump_config.GetList(kTriggersParam, &trigger_list) || |
| - trigger_list->GetSize() == 0) { |
| - return; |
| - } |
| + if (memory_dump_config.GetList(kTriggersParam, &trigger_list) && |
| + trigger_list->GetSize() > 0) { |
| + for (size_t i = 0; i < trigger_list->GetSize(); ++i) { |
| + const base::DictionaryValue* trigger = nullptr; |
| + if (!trigger_list->GetDictionary(i, &trigger)) |
| + continue; |
| - for (size_t i = 0; i < trigger_list->GetSize(); ++i) { |
| - const base::DictionaryValue* trigger = nullptr; |
| - if (!trigger_list->GetDictionary(i, &trigger)) |
| - continue; |
| + MemoryDumpTrigger dump_config; |
| + int interval = 0; |
| - MemoryDumpTriggerConfig dump_config; |
| - int interval = 0; |
| + if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { |
| + continue; |
| + } |
| + DCHECK_GT(interval, 0); |
| + dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); |
| + std::string level_of_detail_str; |
| + trigger->GetString(kModeParam, &level_of_detail_str); |
| + dump_config.level_of_detail = |
| + StringToMemoryDumpLevelOfDetail(level_of_detail_str); |
| + memory_dump_config_.triggers.push_back(dump_config); |
| + } |
| + } |
| - if (!trigger->GetInteger(kPeriodicIntervalParam, &interval)) { |
| - continue; |
| + // Set heap profiler options |
| + const base::DictionaryValue* heap_profiler_options = nullptr; |
| + if (memory_dump_config.GetDictionary(kHeapProfilerOptions, |
| + &heap_profiler_options)) { |
| + int min_size_bytes = 0; |
| + if (heap_profiler_options->GetInteger(kBreakdownThresholdBytes, |
| + &min_size_bytes) |
| + && min_size_bytes >= 0) { |
|
Primiano Tucci (use gerrit)
2016/04/28 07:33:45
are you sure you want the && min_size_bytes >= 0 p
Maria
2016/04/28 17:23:39
Sorry, maybe I am not seeing something, but my rea
Primiano Tucci (use gerrit)
2016/04/28 20:55:11
oops sorry somehow I didn't see the "=" part of t
|
| + memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = |
| + static_cast<size_t>(min_size_bytes); |
| + } else { |
| + memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes = |
| + MemoryDumpHeapProfilerOptions::kDefaultBreakdownThresholdBytes; |
| } |
| - DCHECK_GT(interval, 0); |
| - dump_config.periodic_interval_ms = static_cast<uint32_t>(interval); |
| - std::string level_of_detail_str; |
| - trigger->GetString(kModeParam, &level_of_detail_str); |
| - dump_config.level_of_detail = |
| - StringToMemoryDumpLevelOfDetail(level_of_detail_str); |
| - memory_dump_config_.push_back(dump_config); |
| } |
| } |
| void TraceConfig::SetDefaultMemoryDumpConfig() { |
| - memory_dump_config_.clear(); |
| - memory_dump_config_.push_back(kDefaultHeavyMemoryDumpTrigger); |
| - memory_dump_config_.push_back(kDefaultLightMemoryDumpTrigger); |
| + memory_dump_config_.Clear(); |
| + memory_dump_config_.triggers.push_back(kDefaultHeavyMemoryDumpTrigger); |
| + memory_dump_config_.triggers.push_back(kDefaultLightMemoryDumpTrigger); |
|
Primiano Tucci (use gerrit)
2016/04/28 07:33:45
don't you want also to set kDefaultBreakdownThresh
Maria
2016/04/28 17:23:39
memory_dump_config_.Clear() does that
Primiano Tucci (use gerrit)
2016/04/28 20:55:11
Acknowledged.
|
| } |
| void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
| @@ -569,7 +608,7 @@ void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
| std::unique_ptr<base::DictionaryValue> memory_dump_config( |
| new base::DictionaryValue()); |
| std::unique_ptr<base::ListValue> triggers_list(new base::ListValue()); |
| - for (const MemoryDumpTriggerConfig& config : memory_dump_config_) { |
| + for (const MemoryDumpTrigger& config : memory_dump_config_.triggers) { |
| std::unique_ptr<base::DictionaryValue> trigger_dict( |
| new base::DictionaryValue()); |
| trigger_dict->SetInteger(kPeriodicIntervalParam, |
| @@ -582,6 +621,17 @@ void TraceConfig::ToDict(base::DictionaryValue& dict) const { |
| // Empty triggers will still be specified explicitly since it means that |
| // the periodic dumps are not enabled. |
| memory_dump_config->Set(kTriggersParam, std::move(triggers_list)); |
| + |
| + if (memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes != |
| + MemoryDumpHeapProfilerOptions::kDefaultBreakdownThresholdBytes) { |
| + std::unique_ptr<base::DictionaryValue> heap_profiler_options( |
| + new base::DictionaryValue()); |
| + heap_profiler_options->SetInteger( |
| + kBreakdownThresholdBytes, |
| + memory_dump_config_.heap_profiler_options.breakdown_threshold_bytes); |
| + memory_dump_config->Set(kHeapProfilerOptions, |
| + std::move(heap_profiler_options)); |
| + } |
| dict.Set(kMemoryDumpConfigParam, std::move(memory_dump_config)); |
| } |
| } |