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

Side by Side Diff: chrome/browser/chromeos/power/power_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: read sysfs on blocking pool via a non-member function Created 6 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/chromeos/power/cpu_data_collector.h"
13 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/power_manager_client.h" 15 #include "chromeos/dbus/power_manager_client.h"
15 16
16 namespace power_manager { 17 namespace power_manager {
17 class PowerSupplyProperties; 18 class PowerSupplyProperties;
18 } 19 }
19 20
20 namespace chromeos { 21 namespace chromeos {
21 22
22 // A class which starts collecting power metrics, like the battery charge, as 23 // A class which starts collecting power metrics, like the battery charge, as
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 }; 57 };
57 58
58 const std::deque<PowerSupplySample>& power_supply_data() const { 59 const std::deque<PowerSupplySample>& power_supply_data() const {
59 return power_supply_data_; 60 return power_supply_data_;
60 } 61 }
61 62
62 const std::deque<SystemResumedSample>& system_resumed_data() const { 63 const std::deque<SystemResumedSample>& system_resumed_data() const {
63 return system_resumed_data_; 64 return system_resumed_data_;
64 } 65 }
65 66
67 const CpuDataCollector& cpu_data_collector() const {
68 return cpu_data_collector_;
69 }
70
66 // Can be called only after DBusThreadManager is initialized. 71 // Can be called only after DBusThreadManager is initialized.
67 static void Initialize(); 72 static void Initialize();
68 73
74 // Same as Initialize, but does not start the CpuDataCollector.
75 static void InitializeForTesting();
76
69 // Can be called only if initialized via Initialize, and before 77 // Can be called only if initialized via Initialize, and before
70 // DBusThreadManager is destroyed. 78 // DBusThreadManager is destroyed.
71 static void Shutdown(); 79 static void Shutdown();
72 80
73 // Returns the global instance of PowerDataCollector. 81 // Returns the global instance of PowerDataCollector.
74 static PowerDataCollector* Get(); 82 static PowerDataCollector* Get();
75 83
76 // PowerManagerClient::Observer implementation: 84 // PowerManagerClient::Observer implementation:
77 virtual void PowerChanged( 85 virtual void PowerChanged(
78 const power_manager::PowerSupplyProperties& prop) OVERRIDE; 86 const power_manager::PowerSupplyProperties& prop) OVERRIDE;
79 virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE; 87 virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE;
80 88
81 // Only those power data samples which fall within the last 89 // Only those power data samples which fall within the last
82 // |kSampleTimeLimitSec| are stored in memory. 90 // |kSampleTimeLimitSec| are stored in memory.
83 static const int kSampleTimeLimitSec; 91 static const int kSampleTimeLimitSec;
84 92
85 private: 93 private:
86 PowerDataCollector(); 94 explicit PowerDataCollector(const bool start_cpu_data_collector);
87 95
88 virtual ~PowerDataCollector(); 96 virtual ~PowerDataCollector();
89 97
90 std::deque<PowerSupplySample> power_supply_data_; 98 std::deque<PowerSupplySample> power_supply_data_;
91 std::deque<SystemResumedSample> system_resumed_data_; 99 std::deque<SystemResumedSample> system_resumed_data_;
100 CpuDataCollector cpu_data_collector_;
92 101
93 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector); 102 DISALLOW_COPY_AND_ASSIGN(PowerDataCollector);
94 }; 103 };
95 104
96 // Adds |sample| to |sample_deque|. 105 // Adds |sample| to |sample_deque|.
97 // It dumps samples |PowerDataCollector::kSampleTimeLimitSec| or more older than 106 // It dumps samples |PowerDataCollector::kSampleTimeLimitSec| or more older than
98 // |sample|. 107 // |sample|.
99 template <typename SampleType> 108 template <typename SampleType>
100 void AddSample(std::deque<SampleType>* sample_queue, const SampleType& sample) { 109 void AddSample(std::deque<SampleType>* sample_queue, const SampleType& sample) {
101 while (!sample_queue->empty()) { 110 while (!sample_queue->empty()) {
102 const SampleType& first = sample_queue->front(); 111 const SampleType& first = sample_queue->front();
103 if (sample.time - first.time > 112 if (sample.time - first.time >
104 base::TimeDelta::FromSeconds(PowerDataCollector::kSampleTimeLimitSec)) { 113 base::TimeDelta::FromSeconds(PowerDataCollector::kSampleTimeLimitSec)) {
105 sample_queue->pop_front(); 114 sample_queue->pop_front();
106 } else { 115 } else {
107 break; 116 break;
108 } 117 }
109 } 118 }
110 sample_queue->push_back(sample); 119 sample_queue->push_back(sample);
111 } 120 }
112 121
113 } // namespace chromeos 122 } // namespace chromeos
114 123
115 #endif // CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_ 124 #endif // CHROME_BROWSER_CHROMEOS_POWER_POWER_DATA_COLLECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/power/cpu_data_collector.cc ('k') | chrome/browser/chromeos/power/power_data_collector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698