Commit 3c7169e7 authored by Patrick Monette's avatar Patrick Monette Committed by Chromium LUCI CQ

Add OnAggregatedMetricsSampled to ProcessMonitor::Observer

This new method returns the aggregated metrics across all processes.

Bug: 1166820
Change-Id: I0de27c86533073ff9934dbebb6c7cd32891ba9d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2643229
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846331}
parent 5c56a4db
......@@ -73,6 +73,28 @@ void GatherMetricsForRenderProcess(content::RenderProcessHost* host,
#endif
}
// Adds the values from |rhs| to |lhs|.
ProcessMonitor::Metrics& operator+=(ProcessMonitor::Metrics& lhs,
const ProcessMonitor::Metrics& rhs) {
lhs.cpu_usage += rhs.cpu_usage;
#if defined(OS_WIN)
lhs.disk_usage += rhs.disk_usage;
#endif
#if defined(OS_MAC) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \
defined(OS_AIX)
lhs.idle_wakeups += rhs.idle_wakeups;
#endif
#if defined(OS_MAC)
lhs.package_idle_wakeups += rhs.package_idle_wakeups;
lhs.energy_impact += rhs.energy_impact;
#endif
return lhs;
}
} // namespace
// static
......@@ -181,6 +203,8 @@ void ProcessMonitor::GatherMetricsMapOnIOThread(int current_update_sequence) {
MarkProcessAsAlive(browser_process_data, current_update_sequence);
// Update metrics for all watched processes; remove dead entries from the map.
Metrics aggregated_metrics;
auto iter = metrics_map_.begin();
while (iter != metrics_map_.end()) {
ProcessMetricsHistory* process_metrics = iter->second.get();
......@@ -189,11 +213,15 @@ void ProcessMonitor::GatherMetricsMapOnIOThread(int current_update_sequence) {
metrics_map_.erase(iter++);
} else {
Metrics metrics = process_metrics->SampleMetrics();
aggregated_metrics += metrics;
for (auto& observer : observer_list_)
observer.OnMetricsSampled(process_metrics->metadata(), metrics);
++iter;
}
}
for (auto& observer : observer_list_)
observer.OnAggregatedMetricsSampled(aggregated_metrics);
}
} // namespace performance_monitor
......@@ -71,8 +71,15 @@ class ProcessMonitor {
class Observer : public base::CheckedObserver {
public:
// Provides the sampled metrics for every Chrome process. This is called
// once per process at a regular interval.
virtual void OnMetricsSampled(const ProcessMetadata& process_metadata,
const Metrics& metrics) = 0;
const Metrics& metrics) {}
// Provides the aggregated sampled metrics from every Chrome process. This
// is called once at a regular interval regardless of the number of
// processes.
virtual void OnAggregatedMetricsSampled(const Metrics& metrics) {}
};
// Creates and returns the application-wide ProcessMonitor. Can only be called
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment