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

Side by Side Diff: chromeos/system/cpu_temperature_reader.h

Issue 2823583002: chromeos: Add CPU temperature reader (Closed)
Patch Set: one last fix Created 3 years, 8 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
« no previous file with comments | « chromeos/BUILD.gn ('k') | chromeos/system/cpu_temperature_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 base::FilePath& dir) { hwmon_dir_ = dir; }
44
45 // Reads temperature from each thermal sensor of the CPU. Returns a vector
46 // containing a reading from each sensor. This is a blocking function that
47 // should be run on a thread that allows blocking operations.
48 std::vector<CPUTemperatureInfo> GetCPUTemperatures();
49
50 private:
51 // Sysfs hwmon directory path.
52 base::FilePath hwmon_dir_;
53
54 DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader);
55 };
56
57 } // namespace system
58 } // namespace chromeos
59
60 #endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
OLDNEW
« no previous file with comments | « chromeos/BUILD.gn ('k') | chromeos/system/cpu_temperature_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698