diff options
author | thestig <thestig@chromium.org> | 2014-11-05 21:36:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-06 05:36:51 +0000 |
commit | 5ef7dc8996b4708c65e377bd3938fdaec1cc82b3 (patch) | |
tree | 67451598d5f9951d446d05084cb42eaa621740da /chrome/browser/performance_monitor | |
parent | ae74d7a6124b24a2d774195ededd4bc2485071b4 (diff) | |
download | chromium_src-5ef7dc8996b4708c65e377bd3938fdaec1cc82b3.zip chromium_src-5ef7dc8996b4708c65e377bd3938fdaec1cc82b3.tar.gz chromium_src-5ef7dc8996b4708c65e377bd3938fdaec1cc82b3.tar.bz2 |
PerformanceMonitor: Monitor PPAPI Flash performance.
Review URL: https://codereview.chromium.org/696073002
Cr-Commit-Position: refs/heads/master@{#302966}
Diffstat (limited to 'chrome/browser/performance_monitor')
4 files changed, 57 insertions, 39 deletions
diff --git a/chrome/browser/performance_monitor/performance_monitor.cc b/chrome/browser/performance_monitor/performance_monitor.cc index 3e2cfdb..c27714f 100644 --- a/chrome/browser/performance_monitor/performance_monitor.cc +++ b/chrome/browser/performance_monitor/performance_monitor.cc @@ -20,7 +20,8 @@ namespace { // The default interval at which PerformanceMonitor performs its timed // collections. const int kGatherIntervalInSeconds = 120; -} + +} // namespace namespace performance_monitor { @@ -56,8 +57,9 @@ void PerformanceMonitor::GatherMetricsMapOnUIThread() { content::RenderProcessHost::AllHostsIterator(); !rph_iter.IsAtEnd(); rph_iter.Advance()) { base::ProcessHandle handle = rph_iter.GetCurrentValue()->GetHandle(); - MarkProcessAsAlive(handle, content::PROCESS_TYPE_RENDERER, - current_update_sequence); + content::ChildProcessData data(content::PROCESS_TYPE_RENDERER); + data.handle = handle; + MarkProcessAsAlive(data, current_update_sequence); } BrowserThread::PostTask( @@ -68,19 +70,20 @@ void PerformanceMonitor::GatherMetricsMapOnUIThread() { current_update_sequence)); } -void PerformanceMonitor::MarkProcessAsAlive(const base::ProcessHandle& handle, - int process_type, - int current_update_sequence) { - if (handle == 0) { +void PerformanceMonitor::MarkProcessAsAlive( + const content::ChildProcessData& process_data, + int current_update_sequence) { + if (process_data.handle == base::kNullProcessHandle) { // Process may not be valid yet. return; } - MetricsMap::iterator process_metrics_iter = metrics_map_.find(handle); + MetricsMap::iterator process_metrics_iter = + metrics_map_.find(process_data.handle); if (process_metrics_iter == metrics_map_.end()) { // If we're not already watching the process, let's initialize it. - metrics_map_[handle] - .Initialize(handle, process_type, current_update_sequence); + metrics_map_[process_data.handle].Initialize(process_data, + current_update_sequence); } else { // If we are watching the process, touch it to keep it alive. ProcessMetricsHistory& process_metrics = process_metrics_iter->second; @@ -94,16 +97,13 @@ void PerformanceMonitor::GatherMetricsMapOnIOThread( // Find all child processes (does not include renderers), which has to be // done on the IO thread. - for (content::BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { - const content::ChildProcessData& child_process_data = iter.GetData(); - base::ProcessHandle handle = child_process_data.handle; - MarkProcessAsAlive(handle, child_process_data.process_type, - current_update_sequence); - } + for (content::BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) + MarkProcessAsAlive(iter.GetData(), current_update_sequence); // Add the current (browser) process. - MarkProcessAsAlive(base::GetCurrentProcessHandle(), - content::PROCESS_TYPE_BROWSER, current_update_sequence); + content::ChildProcessData browser_process_data(content::PROCESS_TYPE_BROWSER); + browser_process_data.handle = base::GetCurrentProcessHandle(); + MarkProcessAsAlive(browser_process_data, current_update_sequence); double cpu_usage = 0.0; size_t private_memory_sum = 0; diff --git a/chrome/browser/performance_monitor/performance_monitor.h b/chrome/browser/performance_monitor/performance_monitor.h index afab37c..47d991f 100644 --- a/chrome/browser/performance_monitor/performance_monitor.h +++ b/chrome/browser/performance_monitor/performance_monitor.h @@ -14,6 +14,10 @@ template <typename Type> struct DefaultSingletonTraits; +namespace content { +struct ChildProcessData; +} + namespace performance_monitor { // PerformanceMonitor is a tool which periodically monitors performance metrics @@ -21,8 +25,6 @@ namespace performance_monitor { // performance degradation. class PerformanceMonitor { public: - typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap; - // Returns the current PerformanceMonitor instance if one exists; otherwise // constructs a new PerformanceMonitor. static PerformanceMonitor* GetInstance(); @@ -31,6 +33,8 @@ class PerformanceMonitor { void StartGatherCycle(); private: + typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap; + friend struct DefaultSingletonTraits<PerformanceMonitor>; PerformanceMonitor(); @@ -42,8 +46,7 @@ class PerformanceMonitor { // Mark the given process as alive in the current update iteration. // This means adding an entry to the map of watched processes if it's not // already present. - void MarkProcessAsAlive(const base::ProcessHandle& handle, - int process_type, + void MarkProcessAsAlive(const content::ChildProcessData& process_data, int current_update_sequence); // Updates the ProcessMetrics map with the current list of processes and diff --git a/chrome/browser/performance_monitor/process_metrics_history.cc b/chrome/browser/performance_monitor/process_metrics_history.cc index 30bd921..92655f4 100644 --- a/chrome/browser/performance_monitor/process_metrics_history.cc +++ b/chrome/browser/performance_monitor/process_metrics_history.cc @@ -2,17 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/performance_monitor/process_metrics_history.h" + #include <limits> #include "base/logging.h" #include "base/metrics/histogram.h" #include "base/process/process_metrics.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/common/content_constants.h" +#include "content/public/common/process_type.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/common/process_type.h" namespace performance_monitor { @@ -21,8 +24,7 @@ namespace performance_monitor { const float kHighCPUUtilizationThreshold = 90.0f; ProcessMetricsHistory::ProcessMetricsHistory() - : process_handle_(0), - process_type_(content::PROCESS_TYPE_UNKNOWN), + : process_data_(content::PROCESS_TYPE_UNKNOWN), last_update_sequence_(0) { ResetCounters(); } @@ -37,20 +39,20 @@ void ProcessMetricsHistory::ResetCounters() { 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; +void ProcessMetricsHistory::Initialize( + const content::ChildProcessData& process_data, + int initial_update_sequence) { + DCHECK_EQ(base::kNullProcessHandle, process_data_.handle); + process_data_ = process_data; last_update_sequence_ = initial_update_sequence; #if defined(OS_MACOSX) process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics( - process_handle_, content::BrowserChildProcessHost::GetPortProvider())); + process_data_.handle, + content::BrowserChildProcessHost::GetPortProvider())); #else process_metrics_.reset( - base::ProcessMetrics::CreateProcessMetrics(process_handle_)); + base::ProcessMetrics::CreateProcessMetrics(process_data_.handle)); #endif } @@ -89,7 +91,7 @@ void ProcessMetricsHistory::RunPerformanceTriggers() { // The histogram macros don't support variables as histogram names, // hence the macro duplication for each process type. - switch (process_type_) { + switch (process_data_.process_type) { case content::PROCESS_TYPE_BROWSER: UMA_HISTOGRAM_CUSTOM_COUNTS( "PerformanceMonitor.AverageCPU.BrowserProcess", average_cpu_usage, @@ -130,6 +132,16 @@ void ProcessMetricsHistory::RunPerformanceTriggers() { kHistogramMin, kHistogramMax, kHistogramBucketCount); if (min_cpu_usage_ > kHighCPUUtilizationThreshold) UMA_HISTOGRAM_BOOLEAN("PerformanceMonitor.HighCPU.PPAPIProcess", true); + if (process_data_.name == base::ASCIIToUTF16(content::kFlashPluginName)) { + UMA_HISTOGRAM_CUSTOM_COUNTS( + "PerformanceMonitor.AverageCPU.PPAPIFlashProcess", + average_cpu_usage, kHistogramMin, kHistogramMax, + kHistogramBucketCount); + if (min_cpu_usage_ > kHighCPUUtilizationThreshold) { + UMA_HISTOGRAM_BOOLEAN("PerformanceMonitor.HighCPU.PPAPIFlashProcess", + true); + } + } break; default: break; diff --git a/chrome/browser/performance_monitor/process_metrics_history.h b/chrome/browser/performance_monitor/process_metrics_history.h index 8837e1f..1cfcb46 100644 --- a/chrome/browser/performance_monitor/process_metrics_history.h +++ b/chrome/browser/performance_monitor/process_metrics_history.h @@ -7,6 +7,7 @@ #include "base/memory/linked_ptr.h" #include "base/process/process_handle.h" +#include "content/public/browser/child_process_data.h" namespace base { class ProcessMetrics; @@ -20,8 +21,7 @@ class ProcessMetricsHistory { ~ProcessMetricsHistory(); // Configure this to monitor a specific process. - void Initialize(base::ProcessHandle process_handle, - int process_type, + void Initialize(const content::ChildProcessData& process_data, int initial_update_sequence); // End of a measurement cycle; check for performance issues and reset @@ -55,8 +55,9 @@ class ProcessMetricsHistory { void ResetCounters(); void RunPerformanceTriggers(); - base::ProcessHandle process_handle_; - int process_type_; + // May not be fully populated. e.g. no |id| and no |name| for browser and + // renderer processes. + content::ChildProcessData process_data_; linked_ptr<base::ProcessMetrics> process_metrics_; int last_update_sequence_; @@ -65,6 +66,8 @@ class ProcessMetricsHistory { size_t accumulated_private_bytes_; size_t accumulated_shared_bytes_; int sample_count_; + + DISALLOW_ASSIGN(ProcessMetricsHistory); }; } // namespace performance_monitor |