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

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

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