host_processor_info_scanner.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2022 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. #ifndef SERVICES_DEVICE_COMPUTE_PRESSURE_HOST_PROCESSOR_INFO_SCANNER_H_
  5. #define SERVICES_DEVICE_COMPUTE_PRESSURE_HOST_PROCESSOR_INFO_SCANNER_H_
  6. #include <vector>
  7. #include "base/sequence_checker.h"
  8. #include "base/thread_annotations.h"
  9. #include "services/device/compute_pressure/core_times.h"
  10. namespace device {
  11. // Parses CPU time usage stats from host_processor_info.
  12. //
  13. // This class is not thread-safe. Each instance must be used on the same
  14. // sequence, which must allow blocking I/O. The constructor may be used on a
  15. // different sequence.
  16. class HostProcessorInfoScanner {
  17. public:
  18. HostProcessorInfoScanner();
  19. ~HostProcessorInfoScanner();
  20. HostProcessorInfoScanner(const HostProcessorInfoScanner&) = delete;
  21. HostProcessorInfoScanner& operator=(const HostProcessorInfoScanner&) = delete;
  22. const std::vector<CoreTimes>& core_times() const {
  23. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  24. return core_times_;
  25. }
  26. bool Update();
  27. private:
  28. SEQUENCE_CHECKER(sequence_checker_);
  29. std::vector<CoreTimes> core_times_ GUARDED_BY_CONTEXT(sequence_checker_);
  30. };
  31. } // namespace device
  32. #endif // SERVICES_DEVICE_COMPUTE_PRESSURE_HOST_PROCESSOR_INFO_SCANNER_H_