OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/process/process_metrics.h" | 9 #include "base/process/process_metrics.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
46 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( | 46 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( |
47 process_handle_, content::BrowserChildProcessHost::GetPortProvider())); | 47 process_handle_, content::BrowserChildProcessHost::GetPortProvider())); |
48 #else | 48 #else |
49 process_metrics_.reset( | 49 process_metrics_.reset( |
50 base::ProcessMetrics::CreateProcessMetrics(process_handle_)); | 50 base::ProcessMetrics::CreateProcessMetrics(process_handle_)); |
51 #endif | 51 #endif |
52 } | 52 } |
53 | 53 |
54 void ProcessMetricsHistory::SampleMetrics() { | 54 void ProcessMetricsHistory::SampleMetrics() { |
55 double cpu_usage = process_metrics_->GetCPUUsage(); | 55 double cpu_usage = process_metrics_->GetPlatformIndependentCPUUsage(); |
56 min_cpu_usage_ = std::min(min_cpu_usage_, cpu_usage); | 56 min_cpu_usage_ = std::min(min_cpu_usage_, cpu_usage); |
57 accumulated_cpu_usage_ += cpu_usage; | 57 accumulated_cpu_usage_ += cpu_usage; |
58 | 58 |
59 size_t private_bytes = 0; | 59 size_t private_bytes = 0; |
60 size_t shared_bytes = 0; | 60 size_t shared_bytes = 0; |
61 if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes)) | 61 if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes)) |
62 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; | 62 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; |
63 | 63 |
64 accumulated_private_bytes_ += private_bytes; | 64 accumulated_private_bytes_ += private_bytes; |
65 accumulated_shared_bytes_ += shared_bytes; | 65 accumulated_shared_bytes_ += shared_bytes; |
66 | 66 |
67 sample_count_++; | 67 sample_count_++; |
68 } | 68 } |
69 | 69 |
70 void ProcessMetricsHistory::EndOfCycle() { | 70 void ProcessMetricsHistory::EndOfCycle() { |
71 RunPerformanceTriggers(); | 71 RunPerformanceTriggers(); |
72 ResetCounters(); | 72 ResetCounters(); |
73 } | 73 } |
74 | 74 |
75 void ProcessMetricsHistory::RunPerformanceTriggers() { | 75 void ProcessMetricsHistory::RunPerformanceTriggers() { |
76 // As an initial step, we only care about browser processes. | 76 // As an initial step, we only care about browser processes. |
77 if (process_type_ != content::PROCESS_TYPE_BROWSER) | 77 if (process_type_ != content::PROCESS_TYPE_BROWSER || sample_count_ == 0) |
78 return; | 78 return; |
79 | 79 |
| 80 // We scale up to the equivalent of 64 CPU cores fully loaded. More than this |
| 81 // doesn't really matter, as we're already in a terrible place. |
| 82 UMA_HISTOGRAM_CUSTOM_COUNTS("PerformanceMonitor.AverageCPU.BrowserProcess", |
| 83 accumulated_cpu_usage_ / sample_count_, |
| 84 0, 6400, 50); |
| 85 |
80 // If CPU usage has consistently been above our threshold, | 86 // If CPU usage has consistently been above our threshold, |
81 // we *may* have an issue. | 87 // we *may* have an issue. |
82 if (min_cpu_usage_ > kHighCPUUtilizationThreshold) | 88 if (min_cpu_usage_ > kHighCPUUtilizationThreshold) |
83 UMA_HISTOGRAM_BOOLEAN("PerformanceMonitor.HighCPU.BrowserProcess", true); | 89 UMA_HISTOGRAM_BOOLEAN("PerformanceMonitor.HighCPU.BrowserProcess", true); |
84 } | 90 } |
85 | 91 |
86 } // namespace performance_monitor | 92 } // namespace performance_monitor |
OLD | NEW |