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