m1_sensors_mac.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2021 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. // The Apple M1 chip has sensors to monitor its power consumption and
  5. // temperature. This file defines a class to retrieve data from these sensors.
  6. #ifndef COMPONENTS_POWER_METRICS_M1_SENSORS_MAC_H_
  7. #define COMPONENTS_POWER_METRICS_M1_SENSORS_MAC_H_
  8. #include <memory>
  9. #include <IOKit/hidsystem/IOHIDEventSystemClient.h>
  10. #include "base/mac/scoped_cftyperef.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace power_metrics {
  13. class M1SensorsReader {
  14. public:
  15. struct TemperaturesCelsius {
  16. TemperaturesCelsius();
  17. TemperaturesCelsius(const TemperaturesCelsius&) noexcept;
  18. ~TemperaturesCelsius();
  19. absl::optional<double> p_cores;
  20. absl::optional<double> e_cores;
  21. };
  22. virtual ~M1SensorsReader();
  23. // Creates an M1SensorsReader. Returns nullptr on failure.
  24. static std::unique_ptr<M1SensorsReader> Create();
  25. // Reads temperature sensors. Virtual for testing.
  26. virtual TemperaturesCelsius ReadTemperatures();
  27. protected:
  28. M1SensorsReader(base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system);
  29. private:
  30. base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system_;
  31. };
  32. } // namespace power_metrics
  33. #endif // COMPONENTS_POWER_METRICS_M1_SENSORS_MAC_H_