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

Unified Diff: chromeos/system/cpu_temp_reader.h

Issue 2823583002: chromeos: Add CPU temperature reader (Closed)
Patch Set: Factor out temp and label reading; Add class and unit test 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_temp_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/system/cpu_temp_reader.h
diff --git a/chromeos/system/cpu_temp_reader.h b/chromeos/system/cpu_temp_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..77f711ab544aa205f98573fc2d2dc75c0826527f
--- /dev/null
+++ b/chromeos/system/cpu_temp_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_TEMP_READER_H_
+#define CHROMEOS_SYSTEM_CPU_TEMP_READER_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/macros.h"
+
+namespace chromeos {
+namespace system {
+
+// Contains info from a CPU temperature sensor.
+struct CPUTemperatureInfo {
stevenjb 2017/04/17 16:49:00 Make this a member of the class.
Simon Que 2017/04/17 17:07:48 Done.
+ // The temperature read by a CPU temperature sensor in degrees Celsius.
+ double temp_celsius;
stevenjb 2017/04/17 16:49:00 blank line
Simon Que 2017/04/17 17:07:48 Done.
+ // 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 {
+ return std::make_pair(temp_celsius, label) <
+ std::make_pair(other.temp_celsius, label);
+ }
+};
+
+// Used to read CPU temperature info from sysfs hwmon.
+class CPUTemperatureReader {
stevenjb 2017/04/17 16:49:00 File name should match the class name.
Simon Que 2017/04/17 17:07:48 Done.
+ public:
+ CPUTemperatureReader();
+
+ // Read temperature from each thermal sensor of the CPU. Returns a vector
+ // containing a reading from each sensor.
+ //
+ // This is a blocking function that performs file operations. Users of this
+ // function can choose to call it from a task runner instead.
stevenjb 2017/04/17 16:49:00 Instead of what? Implemented this way, callers *mu
Simon Que 2017/04/17 17:07:48 Do you have an example of Chrome code that does no
stevenjb 2017/04/17 17:24:40 I'm not sure what you mean. There is no such thing
+ std::vector<CPUTemperatureInfo> GetCPUTemperatures();
+
+ void set_hwmon_dir_for_test(const std::string& dir) { hwmon_dir_ = dir; }
+
+ private:
+ // Sysfs hwmon directory path. Gets initialized to a default value but can be
+ // overriden by set_hwmon_dir_for_test().
+ std::string hwmon_dir_;
+
+ DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader);
+};
+
+} // namespace system
+} // namespace chromeos
+
+#endif // CHROMEOS_SYSTEM_CPU_TEMP_READER_H_
« no previous file with comments | « chromeos/BUILD.gn ('k') | chromeos/system/cpu_temp_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698