Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/metrics/metrics_memory_details.h" | 5 #include "chrome/browser/metrics/metrics_memory_details.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 // Skip if a last record is found less than 30 minutes ago. | 49 // Skip if a last record is found less than 30 minutes ago. |
| 50 } else { | 50 } else { |
| 51 // Not reporting if it's the first record for |pid|. | 51 // Not reporting if it's the first record for |pid|. |
| 52 times_[pid] = current_time; | 52 times_[pid] = current_time; |
| 53 memory_sizes_[pid] = sample; | 53 memory_sizes_[pid] = sample; |
| 54 } | 54 } |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 MetricsMemoryDetails::MetricsMemoryDetails( | 58 MetricsMemoryDetails::MetricsMemoryDetails( |
| 59 const base::Closure& callback, | 59 const base::Closure& callback, MemoryGrowthTracker* memory_growth_tracker) |
|
Alexei Svitkine (slow)
2016/10/12 21:46:12
Nit: I think convention is 1 param per line if fir
mwlodar
2016/10/12 22:45:39
Done.
| |
| 60 MemoryGrowthTracker* memory_growth_tracker) | 60 : callback_(callback), memory_growth_tracker_(memory_growth_tracker), |
| 61 : callback_(callback), memory_growth_tracker_(memory_growth_tracker) { | 61 generate_histograms_(true) {} |
| 62 memory_growth_tracker_ = memory_growth_tracker; | 62 |
| 63 } | 63 MetricsMemoryDetails::MetricsMemoryDetails( |
| 64 const base::Closure& callback, MemoryGrowthTracker* memory_growth_tracker, | |
| 65 bool generate_histograms) | |
| 66 : callback_(callback), memory_growth_tracker_(memory_growth_tracker), | |
| 67 generate_histograms_(generate_histograms) {} | |
|
Alexei Svitkine (slow)
2016/10/12 21:46:12
Hmm, instead of a separate constructor, why not ju
mwlodar
2016/10/12 22:45:39
Done.
| |
| 64 | 68 |
| 65 MetricsMemoryDetails::~MetricsMemoryDetails() { | 69 MetricsMemoryDetails::~MetricsMemoryDetails() { |
| 66 } | 70 } |
| 67 | 71 |
| 68 void MetricsMemoryDetails::OnDetailsAvailable() { | 72 void MetricsMemoryDetails::OnDetailsAvailable() { |
| 69 UpdateHistograms(); | 73 if (generate_histograms_) |
| 74 UpdateHistograms(); | |
| 75 AnalyzeMemoryGrowth(); | |
| 70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); | 76 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); |
| 71 } | 77 } |
| 72 | 78 |
| 73 void MetricsMemoryDetails::UpdateHistograms() { | 79 void MetricsMemoryDetails::UpdateHistograms() { |
| 74 // Reports a set of memory metrics to UMA. | 80 // Reports a set of memory metrics to UMA. |
| 75 | 81 |
| 76 const ProcessData& browser = *ChromeBrowser(); | 82 const ProcessData& browser = *ChromeBrowser(); |
| 77 size_t aggregate_memory = 0; | 83 size_t aggregate_memory = 0; |
| 78 int chrome_count = 0; | 84 int chrome_count = 0; |
| 79 int extension_count = 0; | 85 int extension_count = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 case ProcessMemoryInformation::RENDERER_UNKNOWN: | 119 case ProcessMemoryInformation::RENDERER_UNKNOWN: |
| 114 NOTREACHED() << "Unknown renderer process type."; | 120 NOTREACHED() << "Unknown renderer process type."; |
| 115 continue; | 121 continue; |
| 116 case ProcessMemoryInformation::RENDERER_NORMAL: | 122 case ProcessMemoryInformation::RENDERER_NORMAL: |
| 117 default: | 123 default: |
| 118 // TODO(erikkay): Should we bother splitting out the other subtypes? | 124 // TODO(erikkay): Should we bother splitting out the other subtypes? |
| 119 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Large2", | 125 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Large2", |
| 120 sample / 1024); | 126 sample / 1024); |
| 121 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Committed", | 127 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Committed", |
| 122 committed / 1024); | 128 committed / 1024); |
| 123 int diff; | |
| 124 if (memory_growth_tracker_ && | |
| 125 memory_growth_tracker_->UpdateSample( | |
| 126 browser.processes[index].pid, sample, &diff)) { | |
| 127 if (diff < 0) | |
| 128 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff); | |
| 129 else | |
| 130 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff); | |
| 131 } | |
| 132 renderer_count++; | 129 renderer_count++; |
| 133 continue; | 130 continue; |
| 134 } | 131 } |
| 135 } | 132 } |
| 136 case content::PROCESS_TYPE_UTILITY: | 133 case content::PROCESS_TYPE_UTILITY: |
| 137 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); | 134 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); |
| 138 other_count++; | 135 other_count++; |
| 139 continue; | 136 continue; |
| 140 case content::PROCESS_TYPE_ZYGOTE: | 137 case content::PROCESS_TYPE_ZYGOTE: |
| 141 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); | 138 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites", swap_info().num_writes, | 301 UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites", swap_info().num_writes, |
| 305 1, 100000000, 100); | 302 1, 100000000, 100); |
| 306 | 303 |
| 307 if (swap_info().orig_data_size > 0 && swap_info().compr_data_size > 0) { | 304 if (swap_info().orig_data_size > 0 && swap_info().compr_data_size > 0) { |
| 308 UMA_HISTOGRAM_CUSTOM_COUNTS( | 305 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 309 "Memory.Swap.CompressionRatio", | 306 "Memory.Swap.CompressionRatio", |
| 310 swap_info().orig_data_size / swap_info().compr_data_size, 1, 20, 20); | 307 swap_info().orig_data_size / swap_info().compr_data_size, 1, 20, 20); |
| 311 } | 308 } |
| 312 } | 309 } |
| 313 #endif // defined(OS_CHROMEOS) | 310 #endif // defined(OS_CHROMEOS) |
| 311 | |
| 312 void MetricsMemoryDetails::AnalyzeMemoryGrowth() { | |
| 313 const ProcessData& browser = *ChromeBrowser(); | |
| 314 for (size_t index = 0; index < browser.processes.size(); index++) { | |
|
Alexei Svitkine (slow)
2016/10/12 21:46:12
Nit: use a C++ for loop:
for (const auto& process
mwlodar
2016/10/12 22:45:39
Done.
| |
| 315 int sample = static_cast<int>(browser.processes[index].working_set.priv); | |
| 316 | |
| 317 int diff; | |
| 318 if (memory_growth_tracker_ && memory_growth_tracker_->UpdateSample( | |
| 319 browser.processes[index].pid, sample, &diff)) { | |
| 320 if (generate_histograms_) { | |
|
Alexei Svitkine (slow)
2016/10/12 21:46:12
Nit: Merge this if with the one you have above.
mwlodar
2016/10/12 22:45:39
Done. This part is non-trivial though and I added
| |
| 321 if (diff < 0) | |
| 322 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff); | |
| 323 else | |
| 324 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff); | |
| 325 } | |
| 326 } | |
| 327 } | |
| 328 } | |
| OLD | NEW |