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

Unified Diff: chromeos/system/cpu_temperature_reader.h

Issue 2823583002: chromeos: Add CPU temperature reader (Closed)
Patch Set: Handle trailing newline in sysfs 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
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..c31f0defaa702641e20febb0c4409aec0d33d361
--- /dev/null
+++ b/chromeos/system/cpu_temperature_reader.h
@@ -0,0 +1,57 @@
+// 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/macros.h"
+
+namespace chromeos {
+namespace system {
+
+// Used to read CPU temperature info from sysfs hwmon.
+class CPUTemperatureReader {
+ public:
+ // Contains info from a CPU temperature sensor.
+ struct CPUTemperatureInfo {
Daniel Erat 2017/04/21 21:01:20 i think you need to declare a c'tor and d'tor here
Simon Que 2017/04/24 13:59:17 Done.
+ // 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;
+
+ bool operator<(const CPUTemperatureInfo& other) const {
Daniel Erat 2017/04/21 21:01:20 move this method above the members; also move the
Simon Que 2017/04/24 13:59:17 Done.
+ return std::make_pair(temp_celsius, label) <
Daniel Erat 2017/04/21 21:01:20 sorting by temperature is a bit surprising. consid
Simon Que 2017/04/24 13:59:17 Done.
+ std::make_pair(other.temp_celsius, label);
+ }
+ };
+
+ CPUTemperatureReader();
+
Daniel Erat 2017/04/21 21:01:20 nit: delete blank line here
Simon Que 2017/04/24 13:59:17 Done.
+ ~CPUTemperatureReader();
+
+ void set_hwmon_dir_for_test(const std::string& dir) { hwmon_dir_ = dir; }
+
+ // Read temperature from each thermal sensor of the CPU. Returns a vector
+ // containing a reading from each sensor to |callback|. This is a blocking
Daniel Erat 2017/04/21 21:01:20 fix comment; there's no callback now. also s/Read/
Simon Que 2017/04/24 13:59:17 Done.
+ // function that should be run on a thread that allows blocking operations.
+ std::vector<CPUTemperatureInfo> GetCPUTemperatures();
+
+ private:
+ // Sysfs hwmon directory path.
+ std::string hwmon_dir_;
+
+ DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader);
+};
+
+} // namespace system
+} // namespace chromeos
+
+#endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_

Powered by Google App Engine
This is Rietveld 408576698