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

Side by Side Diff: chrome/browser/metrics/metrics_memory_details.cc

Issue 2396743002: Leak reports collect information about the memory usage (Closed)
Patch Set: Added setter for |generate_histograms_| Created 4 years, 2 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 | « chrome/browser/metrics/metrics_memory_details.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
60 MemoryGrowthTracker* memory_growth_tracker) 60 MemoryGrowthTracker* memory_growth_tracker)
61 : callback_(callback), memory_growth_tracker_(memory_growth_tracker) { 61 : callback_(callback),
62 memory_growth_tracker_ = memory_growth_tracker; 62 memory_growth_tracker_(memory_growth_tracker),
63 } 63 generate_histograms_(true) {}
64 64
65 MetricsMemoryDetails::~MetricsMemoryDetails() { 65 MetricsMemoryDetails::~MetricsMemoryDetails() {
66 } 66 }
67 67
68 void MetricsMemoryDetails::OnDetailsAvailable() { 68 void MetricsMemoryDetails::OnDetailsAvailable() {
69 UpdateHistograms(); 69 if (generate_histograms_)
70 UpdateHistograms();
71 AnalyzeMemoryGrowth();
70 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); 72 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_);
71 } 73 }
72 74
73 void MetricsMemoryDetails::UpdateHistograms() { 75 void MetricsMemoryDetails::UpdateHistograms() {
74 // Reports a set of memory metrics to UMA. 76 // Reports a set of memory metrics to UMA.
75 77
76 const ProcessData& browser = *ChromeBrowser(); 78 const ProcessData& browser = *ChromeBrowser();
77 size_t aggregate_memory = 0; 79 size_t aggregate_memory = 0;
78 int chrome_count = 0; 80 int chrome_count = 0;
79 int extension_count = 0; 81 int extension_count = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 case ProcessMemoryInformation::RENDERER_UNKNOWN: 115 case ProcessMemoryInformation::RENDERER_UNKNOWN:
114 NOTREACHED() << "Unknown renderer process type."; 116 NOTREACHED() << "Unknown renderer process type.";
115 continue; 117 continue;
116 case ProcessMemoryInformation::RENDERER_NORMAL: 118 case ProcessMemoryInformation::RENDERER_NORMAL:
117 default: 119 default:
118 // TODO(erikkay): Should we bother splitting out the other subtypes? 120 // TODO(erikkay): Should we bother splitting out the other subtypes?
119 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Large2", 121 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Large2",
120 sample / 1024); 122 sample / 1024);
121 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Committed", 123 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Renderer.Committed",
122 committed / 1024); 124 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++; 125 renderer_count++;
133 continue; 126 continue;
134 } 127 }
135 } 128 }
136 case content::PROCESS_TYPE_UTILITY: 129 case content::PROCESS_TYPE_UTILITY:
137 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); 130 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample);
138 other_count++; 131 other_count++;
139 continue; 132 continue;
140 case content::PROCESS_TYPE_ZYGOTE: 133 case content::PROCESS_TYPE_ZYGOTE:
141 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); 134 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites", swap_info().num_writes, 297 UMA_HISTOGRAM_CUSTOM_COUNTS("Memory.Swap.NumWrites", swap_info().num_writes,
305 1, 100000000, 100); 298 1, 100000000, 100);
306 299
307 if (swap_info().orig_data_size > 0 && swap_info().compr_data_size > 0) { 300 if (swap_info().orig_data_size > 0 && swap_info().compr_data_size > 0) {
308 UMA_HISTOGRAM_CUSTOM_COUNTS( 301 UMA_HISTOGRAM_CUSTOM_COUNTS(
309 "Memory.Swap.CompressionRatio", 302 "Memory.Swap.CompressionRatio",
310 swap_info().orig_data_size / swap_info().compr_data_size, 1, 20, 20); 303 swap_info().orig_data_size / swap_info().compr_data_size, 1, 20, 20);
311 } 304 }
312 } 305 }
313 #endif // defined(OS_CHROMEOS) 306 #endif // defined(OS_CHROMEOS)
307
308 void MetricsMemoryDetails::AnalyzeMemoryGrowth() {
309 for (const auto& process_entry : ChromeBrowser()->processes) {
310 int sample = static_cast<int>(process_entry.working_set.priv);
311 int diff;
312
313 // UpdateSample changes state of |memory_growth_tracker_| and it should be
314 // called even if |generate_histograms_| is false.
315 if (memory_growth_tracker_ &&
316 memory_growth_tracker_->UpdateSample(process_entry.pid, sample,
317 &diff) &&
318 generate_histograms_) {
319 if (diff < 0)
320 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff);
321 else
322 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff);
323 }
324 }
325 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_memory_details.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698