Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/chromeos/power/cpu_data_collector.h

Issue 149973002: [chromeos/about:power] Collect cpuidle and cpufreq stats (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_
7
8 #include <deque>
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h"
17
18 namespace chromeos {
19
20 // A class to sample CPU idle state occupancy and freq state occupancy.
21 // Collects raw data from sysfs and does not convert it to percentage
22 // occupancy. As CPUs can be offline at times, or the system can be suspended at
23 // other times, it is best for the consumer of this data to calculate percentage
24 // occupancy information using suspend time data got from
25 // PowerDataCollector::system_resumed_data.
26 class CpuDataCollector {
27 public:
28 struct StateOccupancySample {
29 StateOccupancySample();
30
31 // The time when the data was sampled.
32 base::Time time;
33
34 // Indicates whether the CPU is online.
35 bool cpu_online;
36
37 // A mapping from CPU state name to time spent in that state in
38 // milliseconds.
39 std::map<std::string, int64> state_occupancy;
40 };
41
42 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque;
43
44 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const {
45 return cpu_idle_state_data_;
46 }
47
48 const std::vector<StateOccupancySampleDeque>& cpu_freq_state_data() const {
49 return cpu_freq_state_data_;
50 }
51
52 CpuDataCollector();
53
54 void Start();
55
56 private:
57 void PostSampleCpuState();
58
59 // Samples CPU idle and CPU freq data from sysfs. This function should run on
60 // the blocking pool as reading from sysfs is a blocking task. Elements at
61 // index i in |idle_samples| and |freq_samples| correspond to the idle and
62 // freq samples of CPU i.
63 void SampleCpuStateOnBlockingPool(
64 std::vector<StateOccupancySample>* idle_samples,
65 std::vector<StateOccupancySample>* freq_samples);
66
67 // This function commits the samples read by SampleCpuStateOnBlockingPool to
68 // |cpu_idle_state_data_| and |cpu_freq_state_data_|. Since UI is the consumer
69 // of CPU idle and freq data, this function should run on the UI thread.
70 void SaveCpuStateSamplesOnUIThread(
71 const std::vector<StateOccupancySample>* idle_samples,
72 const std::vector<StateOccupancySample>* freq_samples);
73
74 base::RepeatingTimer<CpuDataCollector> timer_;
75
76 // The deque at index <i> in the vector corresponds to the idle state
77 // occupancy data of CPU<i>.
78 std::vector<StateOccupancySampleDeque> cpu_idle_state_data_;
79
80 // The deque at index <i> in the vector corresponds to the frequency state
81 // occupancy data of CPU<i>.
82 std::vector<StateOccupancySampleDeque> cpu_freq_state_data_;
83
84 // The number of CPUs on the system.
85 int cpu_count_;
86
87 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_;
88 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector);
89 };
90
91 } // namespace chromeos
92
93 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698