| 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 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/sys_info.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "components/nacl/common/nacl_process_type.h" | 18 #include "components/nacl/common/nacl_process_type.h" |
| 18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
| 20 #include "content/public/common/process_type.h" | 21 #include "content/public/common/process_type.h" |
| 21 #include "ppapi/features/features.h" | 22 #include "ppapi/features/features.h" |
| 22 | 23 |
| 23 MemoryGrowthTracker::MemoryGrowthTracker() { | 24 MemoryGrowthTracker::MemoryGrowthTracker() { |
| 24 } | 25 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 49 } | 50 } |
| 50 // Skip if a last record is found less than 30 minutes ago. | 51 // Skip if a last record is found less than 30 minutes ago. |
| 51 } else { | 52 } else { |
| 52 // Not reporting if it's the first record for |pid|. | 53 // Not reporting if it's the first record for |pid|. |
| 53 times_[pid] = current_time; | 54 times_[pid] = current_time; |
| 54 memory_sizes_[pid] = sample; | 55 memory_sizes_[pid] = sample; |
| 55 } | 56 } |
| 56 return false; | 57 return false; |
| 57 } | 58 } |
| 58 | 59 |
| 60 PeakMemoryUsageTracker::PeakMemoryUsageTracker() : peak_(0) {} |
| 61 |
| 62 bool PeakMemoryUsageTracker::Update(int memory_usage) { |
| 63 if (memory_usage > peak_) { |
| 64 peak_ = memory_usage; |
| 65 return true; |
| 66 } |
| 67 return false; |
| 68 } |
| 69 |
| 59 MetricsMemoryDetails::MetricsMemoryDetails( | 70 MetricsMemoryDetails::MetricsMemoryDetails( |
| 60 const base::Closure& callback, | 71 const base::Closure& callback, |
| 61 MemoryGrowthTracker* memory_growth_tracker) | 72 MemoryGrowthTracker* memory_growth_tracker, |
| 73 PeakMemoryUsageTracker* peak_memory_usage_tracker) |
| 62 : callback_(callback), | 74 : callback_(callback), |
| 63 memory_growth_tracker_(memory_growth_tracker), | 75 memory_growth_tracker_(memory_growth_tracker), |
| 76 peak_memory_usage_tracker_(peak_memory_usage_tracker), |
| 64 generate_histograms_(true) {} | 77 generate_histograms_(true) {} |
| 65 | 78 |
| 66 MetricsMemoryDetails::~MetricsMemoryDetails() { | 79 MetricsMemoryDetails::~MetricsMemoryDetails() { |
| 67 } | 80 } |
| 68 | 81 |
| 69 void MetricsMemoryDetails::OnDetailsAvailable() { | 82 void MetricsMemoryDetails::OnDetailsAvailable() { |
| 70 if (generate_histograms_) | 83 if (generate_histograms_) |
| 71 UpdateHistograms(); | 84 UpdateHistograms(); |
| 72 AnalyzeMemoryGrowth(); | 85 AnalyzeMemoryGrowth(); |
| 73 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); | 86 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount", | 205 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount", |
| 193 pepper_plugin_broker_count); | 206 pepper_plugin_broker_count); |
| 194 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); | 207 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); |
| 195 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 208 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
| 196 // TODO(viettrungluu): Do we want separate counts for the other | 209 // TODO(viettrungluu): Do we want separate counts for the other |
| 197 // (platform-specific) process types? | 210 // (platform-specific) process types? |
| 198 | 211 |
| 199 int total_sample = static_cast<int>(aggregate_memory / 1024); | 212 int total_sample = static_cast<int>(aggregate_memory / 1024); |
| 200 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total2", total_sample); | 213 UMA_HISTOGRAM_MEMORY_LARGE_MB("Memory.Total2", total_sample); |
| 201 | 214 |
| 215 if (peak_memory_usage_tracker_) { |
| 216 int previous_peak = peak_memory_usage_tracker_->peak(); |
| 217 if (peak_memory_usage_tracker_->Update( |
| 218 static_cast<int>(aggregate_memory))) { |
| 219 int physical_memory = |
| 220 static_cast<int>(base::SysInfo::AmountOfPhysicalMemory()); |
| 221 int previous_peak_percentage = std::min( |
| 222 static_cast<int>(100.0 * previous_peak / physical_memory), 100); |
| 223 int new_peak_percentage = |
| 224 std::min(static_cast<int>(100.0 * peak_memory_usage_tracker_->peak() / |
| 225 physical_memory), |
| 226 100); |
| 227 for (int i = previous_peak_percentage + 1; i <= new_peak_percentage; |
| 228 ++i) { |
| 229 UMA_HISTOGRAM_COUNTS_100("Memory.Total2.RelativePeak", i); |
| 230 } |
| 231 } |
| 232 } |
| 233 |
| 202 // Predict the number of processes needed when isolating all sites and when | 234 // Predict the number of processes needed when isolating all sites and when |
| 203 // isolating only HTTPS sites. | 235 // isolating only HTTPS sites. |
| 204 int all_renderer_count = renderer_count + chrome_count + extension_count; | 236 int all_renderer_count = renderer_count + chrome_count + extension_count; |
| 205 int non_renderer_count = browser.processes.size() - all_renderer_count; | 237 int non_renderer_count = browser.processes.size() - all_renderer_count; |
| 206 DCHECK_GE(non_renderer_count, 1); | 238 DCHECK_GE(non_renderer_count, 1); |
| 207 SiteDetails::UpdateHistograms(browser.site_data, all_renderer_count, | 239 SiteDetails::UpdateHistograms(browser.site_data, all_renderer_count, |
| 208 non_renderer_count); | 240 non_renderer_count); |
| 209 | 241 |
| 210 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
| 211 UpdateSwapHistograms(); | 243 UpdateSwapHistograms(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 memory_growth_tracker_->UpdateSample(process_entry.pid, sample, | 349 memory_growth_tracker_->UpdateSample(process_entry.pid, sample, |
| 318 &diff) && | 350 &diff) && |
| 319 generate_histograms_) { | 351 generate_histograms_) { |
| 320 if (diff < 0) | 352 if (diff < 0) |
| 321 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff); | 353 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererShrinkIn30Min", -diff); |
| 322 else | 354 else |
| 323 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff); | 355 UMA_HISTOGRAM_MEMORY_KB("Memory.RendererGrowthIn30Min", diff); |
| 324 } | 356 } |
| 325 } | 357 } |
| 326 } | 358 } |
| OLD | NEW |