diff options
Diffstat (limited to 'chrome/browser/performance_monitor')
-rw-r--r-- | chrome/browser/performance_monitor/process_metrics_history.cc | 41 | ||||
-rw-r--r-- | chrome/browser/performance_monitor/process_metrics_history.h | 3 |
2 files changed, 43 insertions, 1 deletions
diff --git a/chrome/browser/performance_monitor/process_metrics_history.cc b/chrome/browser/performance_monitor/process_metrics_history.cc index 701a114..824444b 100644 --- a/chrome/browser/performance_monitor/process_metrics_history.cc +++ b/chrome/browser/performance_monitor/process_metrics_history.cc @@ -17,12 +17,22 @@ namespace performance_monitor { +namespace { + +const char kBrowserProcessTrigger[] = + "ProcessMetricsHistory.BrowserProcess.HighCPU"; +const char kGPUProcessTrigger[] = "ProcessMetricsHistory.GPUProcess.HighCPU"; +const char kExtensionPersistentProcessTrigger[] = + "ProcessMetricsHistory.ExtensionPersistentProcess.HighCPU"; + +} // namespace + // If a process is consistently above this CPU utilization percentage over time, // we consider it as high and may take action. const float kHighCPUUtilizationThreshold = 90.0f; ProcessMetricsHistory::ProcessMetricsHistory() - : last_update_sequence_(0), cpu_usage_(0.0) { + : last_update_sequence_(0), cpu_usage_(0.0), trace_trigger_handle_(-1) { } ProcessMetricsHistory::~ProcessMetricsHistory() { @@ -43,6 +53,28 @@ void ProcessMetricsHistory::Initialize( process_metrics_.reset( base::ProcessMetrics::CreateProcessMetrics(process_data_.handle)); #endif + + const char* trigger_name = NULL; + switch (process_data_.process_type) { + case content::PROCESS_TYPE_BROWSER: + trigger_name = kBrowserProcessTrigger; + break; + case content::PROCESS_TYPE_GPU: + trigger_name = kGPUProcessTrigger; + break; + } + switch (process_data_.process_subtype) { + case kProcessSubtypeExtensionPersistent: + trigger_name = kExtensionPersistentProcessTrigger; + break; + default: + break; + } + if (trigger_name) { + trace_trigger_handle_ = + content::BackgroundTracingManager::GetInstance()->RegisterTriggerType( + trigger_name); + } } void ProcessMetricsHistory::SampleMetrics() { @@ -136,6 +168,13 @@ void ProcessMetricsHistory::RunPerformanceTriggers() { } break; } + + if (cpu_usage_ > kHighCPUUtilizationThreshold && + trace_trigger_handle_ != -1) { + content::BackgroundTracingManager::GetInstance()->TriggerNamedEvent( + trace_trigger_handle_, + content::BackgroundTracingManager::StartedFinalizingCallback()); + } } } // namespace performance_monitor diff --git a/chrome/browser/performance_monitor/process_metrics_history.h b/chrome/browser/performance_monitor/process_metrics_history.h index 186236d..21f9209 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/background_tracing_manager.h" #include "content/public/browser/child_process_data.h" #include "content/public/common/process_type.h" @@ -65,6 +66,8 @@ class ProcessMetricsHistory { double cpu_usage_; + content::BackgroundTracingManager::TriggerHandle trace_trigger_handle_; + DISALLOW_ASSIGN(ProcessMetricsHistory); }; |