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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/BUILD.gn ('k') | chromeos/system/cpu_temperature_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/system/cpu_temperature_reader.h
diff --git a/chromeos/system/cpu_temperature_reader.h b/chromeos/system/cpu_temperature_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..d32672525f8f7d6ea06069d8f459de0efd6546f6
--- /dev/null
+++ b/chromeos/system/cpu_temperature_reader.h
@@ -0,0 +1,61 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
+#define CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "chromeos/chromeos_export.h"
+
+namespace chromeos {
+namespace system {
+
+// Used to read CPU temperature info from sysfs hwmon.
+class CHROMEOS_EXPORT CPUTemperatureReader {
+ public:
+ // Contains info from a CPU temperature sensor.
+ struct CPUTemperatureInfo {
+ CPUTemperatureInfo();
+ ~CPUTemperatureInfo();
+
+ bool operator<(const CPUTemperatureInfo& other) const {
+ return std::make_pair(label, temp_celsius) <
+ std::make_pair(other.label, other.temp_celsius);
+ }
+
+ // The temperature read by a CPU temperature sensor in degrees Celsius.
+ double temp_celsius;
+
+ // The name of the CPU temperature zone monitored by this sensor. Used to
+ // identify the source of each temperature reading. Taken from sysfs "name"
+ // or "label" field, if it exists.
+ std::string label;
+ };
+
+ CPUTemperatureReader();
+ ~CPUTemperatureReader();
+
+ void set_hwmon_dir_for_test(const base::FilePath& dir) { hwmon_dir_ = dir; }
+
+ // Reads temperature from each thermal sensor of the CPU. Returns a vector
+ // containing a reading from each sensor. This is a blocking function that
+ // should be run on a thread that allows blocking operations.
+ std::vector<CPUTemperatureInfo> GetCPUTemperatures();
+
+ private:
+ // Sysfs hwmon directory path.
+ base::FilePath hwmon_dir_;
+
+ DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader);
+};
+
+} // namespace system
+} // namespace chromeos
+
+#endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
« 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