OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 #ifndef CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ | |
6 #define CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/process/process_handle.h" | |
12 #include "base/process/process_metrics.h" | |
13 #include "components/power/origin_power_map_factory.h" | |
14 #include "url/gurl.h" | |
15 | |
16 class Profile; | |
17 | |
18 namespace content { | |
19 class RenderProcessHost; | |
20 } | |
21 | |
22 // Manages regular updates of the profile power consumption. | |
23 class ProcessPowerCollector { | |
24 public: | |
25 ProcessPowerCollector(); | |
26 ~ProcessPowerCollector(); | |
27 | |
28 // Begin periodically updating the power consumption numbers by profile. | |
29 void StartUpdating(); | |
30 | |
31 private: | |
32 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, NoSite); | |
33 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, OneSite); | |
34 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, MultipleSites); | |
35 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, | |
36 IncognitoDoesntRecordPowerUsage); | |
37 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, | |
38 MultipleProfilesRecordSeparately); | |
39 FRIEND_TEST_ALL_PREFIXES(BrowserProcessPowerTest, AppsRecordPowerUsage); | |
40 | |
41 struct PerProcessData { | |
42 explicit PerProcessData(base::ProcessMetrics* metrics) | |
43 : metrics(metrics), last_cpu(-1) {} | |
44 PerProcessData() {} | |
45 ~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.
| |
46 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.
| |
47 | |
48 Profile* profile; | |
49 GURL last_origin; | |
50 double total_usage; | |
51 int last_cpu; | |
52 }; | |
53 | |
54 // A map from all process handles to a metric. | |
55 typedef std::map<base::ProcessHandle, PerProcessData> ProcessMetricsMap; | |
56 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.
| |
57 | |
58 // Callback from the timer to update. Invokes the update power consumption | |
59 // procedure. | |
60 void UpdatePowerConsumptionCallback(); | |
61 | |
62 // 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.
| |
63 void UpdateMetricsMap(); | |
64 | |
65 // Updates the |metrics_map_| with updated CPU usage information and | |
66 // removes all inactive processes from the |metrics_map_|. | |
67 double PopulateCpuUsageByOrigin(); | |
68 | |
69 // Attributes the power usage to the profiles and origins given a total amount | |
70 // of CPU used in this cycle, |cpu_cycle|. | |
71 void RecordCpuUsageByOrigin(double cpu_cycle); | |
72 | |
73 // Iterates over all tabs to determine the power usage since the last sweep. | |
74 void UpdatePowerConsumption(); | |
75 | |
76 // Adds the information from a given RenderProcessHost to the map at the for | |
77 // a given origin. | |
78 void AddProcessToMap(const content::RenderProcessHost* render_process, | |
79 const GURL& origin); | |
80 | |
81 ProcessMetricsMap* GetMetricsMapForTesting() { return metrics_map_.get(); } | |
82 | |
83 int update_requests_; | |
84 base::WeakPtrFactory<ProcessPowerCollector> weak_ptr_factory_; | |
85 }; | |
86 | |
87 #endif // CHROME_BROWSER_POWER_PROCESS_POWER_COLLECTOR_H_ | |
OLD | NEW |