Chromium Code Reviews| Index: chrome/browser/power/process_power_collector.h |
| diff --git a/chrome/browser/power/process_power_collector.h b/chrome/browser/power/process_power_collector.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab2b05b99d4587ad4977b33a5eb409506405d541 |
| --- /dev/null |
| +++ b/chrome/browser/power/process_power_collector.h |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |
| +#define CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/process/process_handle.h" |
| +#include "base/process/process_metrics.h" |
| +#include "components/power/origin_power_map_factory.h" |
| +#include "url/gurl.h" |
| + |
| +class Profile; |
| + |
| +namespace content { |
| +class RenderProcessHost; |
| +} |
| + |
| +// Manages regular updates of the profile power consumption. |
| +class ProcessPowerCollector { |
| + public: |
| + ProcessPowerCollector(); |
| + ~ProcessPowerCollector(); |
| + |
| + // Begin periodically updating the power consumption numbers by profile. |
| + void StartUpdating(); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, NoSite); |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, OneSite); |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, MultipleSites); |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, |
| + IncognitoDoesntRecordPowerUsage); |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, |
| + MultipleProfilesRecordSeparately); |
| + FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, AppsRecordPowerUsage); |
| + |
| + struct PerProcessData { |
| + explicit PerProcessData(base::ProcessMetrics* metrics) |
| + : metrics(metrics), last_cpu(-1) {} |
| + PerProcessData() {} |
| + ~PerProcessData() {} |
|
Daniel Erat
2014/08/15 20:22:13
nit: add a blank line after this one
Daniel Nishi
2014/08/18 17:38:48
Done.
|
| + base::ProcessMetrics* metrics; |
|
Daniel Erat
2014/08/15 20:22:13
nit: add comments documenting ownership of |metric
Daniel Nishi
2014/08/18 17:38:48
Done.
|
| + |
| + Profile* profile; |
| + GURL last_origin; |
| + double total_usage; |
| + int last_cpu; |
| + }; |
| + |
| + // A map from all process handles to a metric. |
| + typedef std::map<base::ProcessHandle, PerProcessData> ProcessMetricsMap; |
| + scoped_ptr<ProcessMetricsMap> metrics_map_; |
|
Daniel Erat
2014/08/15 20:22:13
move this data member declaration below all of the
Daniel Nishi
2014/08/18 17:38:48
Done.
|
| + |
| + // Callback from the timer to update. Invokes the update power consumption |
| + // procedure. |
| + void UpdatePowerConsumptionCallback(); |
| + |
| + // Update the |metrics_map_| with currently active processes. |
|
Daniel Erat
2014/08/15 20:22:13
nit: s/Update/Updates/
Daniel Nishi
2014/08/18 17:38:48
Done.
|
| + void UpdateMetricsMap(); |
| + |
| + // Updates the |metrics_map_| with updated CPU usage information and |
| + // removes all inactive processes from the |metrics_map_|. |
| + double PopulateCpuUsageByOrigin(); |
| + |
| + // Attributes the power usage to the profiles and origins given a total amount |
| + // of CPU used in this cycle, |cpu_cycle|. |
| + void RecordCpuUsageByOrigin(double cpu_cycle); |
| + |
| + // Iterates over all tabs to determine the power usage since the last sweep. |
| + void UpdatePowerConsumption(); |
| + |
| + // Adds the information from a given RenderProcessHost to the map at the for |
| + // a given origin. |
| + void AddProcessToMap(const content::RenderProcessHost* render_process, |
| + const GURL& origin); |
| + |
| + ProcessMetricsMap* GetMetricsMapForTesting() { return metrics_map_.get(); } |
| + |
| + int update_requests_; |
| + base::WeakPtrFactory<ProcessPowerCollector> weak_ptr_factory_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ |