Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <limits> | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/process/process_metrics.h" | |
| 9 | |
| 10 #include "chrome/browser/performance_monitor/constants.h" | |
| 11 #include "chrome/browser/performance_monitor/process_metrics_history.h" | |
| 12 #if defined(OS_MACOSX) | |
| 13 #include "content/public/browser/browser_child_process_host.h" | |
| 14 #endif | |
| 15 #include "content/public/browser/user_metrics.h" | |
| 16 #include "content/public/common/process_type.h" | |
| 17 | |
| 18 namespace performance_monitor { | |
| 19 | |
| 20 ProcessMetricsHistory::ProcessMetricsHistory() | |
| 21 : process_handle_(0), | |
| 22 process_type_(content::PROCESS_TYPE_UNKNOWN), | |
| 23 last_update_sequence_(0) { | |
| 24 ResetCounters(); | |
| 25 } | |
| 26 | |
| 27 ProcessMetricsHistory::~ProcessMetricsHistory() {} | |
| 28 | |
| 29 void ProcessMetricsHistory::ResetCounters() { | |
| 30 min_cpu_usage_ = std::numeric_limits<double>::max(); | |
| 31 accumulated_cpu_usage_ = 0.0; | |
| 32 accumulated_private_bytes_ = 0; | |
| 33 accumulated_shared_bytes_ = 0; | |
| 34 sample_count_ = 0; | |
| 35 } | |
| 36 | |
| 37 void ProcessMetricsHistory::Initialize(base::ProcessHandle process_handle, | |
| 38 int process_type, | |
| 39 int initial_update_sequence) { | |
| 40 DCHECK(process_handle_ == 0); | |
| 41 process_handle_ = process_handle; | |
| 42 process_type_ = process_type; | |
| 43 last_update_sequence_ = initial_update_sequence; | |
| 44 | |
| 45 #if defined(OS_MACOSX) | |
| 46 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( | |
| 47 process_handle_, content::BrowserChildProcessHost::GetPortProvider())); | |
| 48 #else | |
| 49 process_metrics_.reset( | |
| 50 base::ProcessMetrics::CreateProcessMetrics(process_handle_)); | |
| 51 #endif | |
| 52 } | |
| 53 | |
| 54 void ProcessMetricsHistory::SampleMetrics() { | |
| 55 double cpu_usage = process_metrics_->GetCPUUsage(); | |
| 56 min_cpu_usage_ = std::min(min_cpu_usage_, cpu_usage); | |
| 57 accumulated_cpu_usage_ += cpu_usage; | |
| 58 | |
| 59 size_t private_bytes = 0; | |
| 60 size_t shared_bytes = 0; | |
| 61 if (!process_metrics_->GetMemoryBytes(&private_bytes, &shared_bytes)) | |
| 62 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; | |
| 63 | |
| 64 accumulated_private_bytes_ += private_bytes; | |
| 65 accumulated_shared_bytes_ += shared_bytes; | |
| 66 | |
| 67 sample_count_++; | |
|
Devlin
2013/09/13 18:14:09
nit: ++sample_count;
oystein (OOO til 10th of July)
2013/09/13 20:41:55
Why? This is a POD, not an iterator or another com
Devlin
2013/09/13 21:38:08
http://google-styleguide.googlecode.com/svn/trunk/
oystein (OOO til 10th of July)
2013/09/13 21:57:50
Yeah that's my point. "For simple scalar (non-obje
| |
| 68 } | |
| 69 | |
| 70 void ProcessMetricsHistory::EndOfCycle() { | |
| 71 RunPerformanceTriggers(); | |
| 72 ResetCounters(); | |
| 73 } | |
| 74 | |
| 75 void ProcessMetricsHistory::RunPerformanceTriggers() { | |
| 76 // As an initial step, we only care about browser processes. | |
| 77 if (process_type_ != content::PROCESS_TYPE_BROWSER) | |
| 78 return; | |
| 79 | |
| 80 // If CPU usage has consistently been above our threshold, | |
| 81 // we *may* have an issue. | |
| 82 if (min_cpu_usage_ > kHighCPUUtilizationThreshold) { | |
|
Devlin
2013/09/13 18:14:09
Just FYI:
The different OSs report the CPU usage
oystein (OOO til 10th of July)
2013/09/13 20:41:55
That's fine; for this initial test we want to catc
| |
| 83 content::RecordAction( | |
| 84 content::UserMetricsAction("PerformanceMonitor.HighCPU.Browser")); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 } // namespace performance_monitor | |
| OLD | NEW |