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

Unified Diff: chrome/browser/performance_monitor/process_metrics_history.cc

Issue 23825004: PerformanceMonitor: UMA alert for high browser CPU usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed dependencies. Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/performance_monitor/process_metrics_history.cc
diff --git a/chrome/browser/performance_monitor/process_metrics_history.cc b/chrome/browser/performance_monitor/process_metrics_history.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97b3c15b383ae87a79a1d197174297021959b2c8
--- /dev/null
+++ b/chrome/browser/performance_monitor/process_metrics_history.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
Devlin 2013/09/12 00:44:47 no (c)
oystein (OOO til 10th of July) 2013/09/12 15:02:31 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <limits>
+
+#include "base/logging.h"
+#include "base/process/process_metrics.h"
+
+#include "chrome/browser/performance_monitor/constants.h"
+#include "chrome/browser/performance_monitor/process_metrics_history.h"
+#if defined(OS_MACOSX)
+#include "content/public/browser/browser_child_process_host.h"
+#endif
+#include "content/public/browser/user_metrics.h"
+#include "content/public/common/process_type.h"
+
+namespace performance_monitor {
+
+ProcessMetricsHistory::ProcessMetricsHistory()
+ : process_handle_(0),
+ process_type_(content::PROCESS_TYPE_UNKNOWN),
+ last_update_sequence_(0) {
+ ResetCounters();
+}
+
+ProcessMetricsHistory::~ProcessMetricsHistory() {}
+
+void ProcessMetricsHistory::ResetCounters() {
+ min_cpu_usage_ = std::numeric_limits<double>::max();
+ accumulated_cpu_usage_ = 0.0;
+ accumulated_private_bytes_ = 0;
+ accumulated_shared_bytes_ = 0;
+ sample_count_ = 0;
+}
+
+void ProcessMetricsHistory::Initialize(base::ProcessHandle process_handle,
+ int process_type,
+ int initial_update_sequence) {
+ DCHECK(process_handle_ == 0);
+ process_handle_ = process_handle;
+ process_type_ = process_type;
+ last_update_sequence_ = initial_update_sequence;
+
+#if defined(OS_MACOSX)
+ process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(
+ process_handle_, content::BrowserChildProcessHost::GetPortProvider()));
+#else
+ process_metrics_.reset(
+ base::ProcessMetrics::CreateProcessMetrics(process_handle_));
+#endif
+}
+
+void ProcessMetricsHistory::SampleMetrics() {
+ double cpu_usage = process_metrics_->GetCPUUsage();
+ min_cpu_usage_ = std::min(min_cpu_usage_, cpu_usage);
+ accumulated_cpu_usage_ += cpu_usage;
+
+ size_t private_bytes = 0;
+ size_t shared_bytes = 0;
+ if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes)) {
Devlin 2013/09/12 00:44:47 nit: no brackets
oystein (OOO til 10th of July) 2013/09/12 15:02:31 Done.
+ LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)";
+ }
+
+ accumulated_private_bytes_ += private_bytes;
+ accumulated_shared_bytes_ += shared_bytes;
+
+ sample_count_++;
+}
+
+void ProcessMetricsHistory::EndOfCycle() {
+ RunPerformanceTriggers();
+ ResetCounters();
+}
+
+void ProcessMetricsHistory::RunPerformanceTriggers() {
+ // As an initial step, we only care about browser processes.
+ if (process_type_ != content::PROCESS_TYPE_BROWSER) {
Devlin 2013/09/12 00:44:47 nit: no brackets
oystein (OOO til 10th of July) 2013/09/12 15:02:31 Done.
+ return;
+ }
+
+ // If CPU usage has consistently been above our threshold,
+ // we *may* have an issue.
+ if (min_cpu_usage_ > kHighCPUUtilizationThreshold) {
+ content::RecordAction(
+ content::UserMetricsAction("PerformanceMonitor.HighCPU.Browser"));
+ }
+}
+
+} // namespace performance_monitor

Powered by Google App Engine
This is Rietveld 408576698