OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ | |
6 #define CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ | |
7 | |
8 #include <string> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
12 #include "base/files/file_path.h" | |
13 #include "base/macros.h" | |
14 | |
15 namespace chromeos { | |
16 namespace system { | |
17 | |
18 // Used to read CPU temperature info from sysfs hwmon. | |
19 class CPUTemperatureReader { | |
20 public: | |
21 // Contains info from a CPU temperature sensor. | |
22 struct CPUTemperatureInfo { | |
23 CPUTemperatureInfo(); | |
24 ~CPUTemperatureInfo(); | |
25 | |
26 bool operator<(const CPUTemperatureInfo& other) const { | |
27 return std::make_pair(label, temp_celsius) < | |
28 std::make_pair(other.label, other.temp_celsius); | |
29 } | |
30 | |
31 // The temperature read by a CPU temperature sensor in degrees Celsius. | |
32 double temp_celsius; | |
33 | |
34 // The name of the CPU temperature zone monitored by this sensor. Used to | |
35 // identify the source of each temperature reading. Taken from sysfs "name" | |
36 // or "label" field, if it exists. | |
37 std::string label; | |
38 }; | |
39 | |
40 CPUTemperatureReader(); | |
41 ~CPUTemperatureReader(); | |
42 | |
43 void set_hwmon_dir_for_test(const std::string& dir) { | |
Daniel Erat
2017/04/24 22:29:43
this should take a const base::FilePath&. it's bet
Simon Que
2017/04/24 22:31:41
Done.
| |
44 hwmon_dir_ = base::FilePath(dir); | |
45 } | |
46 | |
47 // Reads temperature from each thermal sensor of the CPU. Returns a vector | |
48 // containing a reading from each sensor. This is a blocking function that | |
49 // should be run on a thread that allows blocking operations. | |
50 std::vector<CPUTemperatureInfo> GetCPUTemperatures(); | |
51 | |
52 private: | |
53 // Sysfs hwmon directory path. | |
54 base::FilePath hwmon_dir_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader); | |
57 }; | |
58 | |
59 } // namespace system | |
60 } // namespace chromeos | |
61 | |
62 #endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ | |
OLD | NEW |