123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // Copyright 2021 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.
- #include "services/device/compute_pressure/pressure_test_support.h"
- #include <ostream>
- #include "base/location.h"
- #include "base/sequence_checker.h"
- #include "base/synchronization/lock.h"
- #include "base/threading/scoped_blocking_call.h"
- #include "services/device/compute_pressure/pressure_sample.h"
- namespace device {
- bool operator==(const PressureSample& lhs, const PressureSample& rhs) noexcept {
- return lhs.cpu_utilization == rhs.cpu_utilization;
- }
- std::ostream& operator<<(std::ostream& os, const PressureSample& sample) {
- os << "[utilization: " << sample.cpu_utilization << "]";
- return os;
- }
- constexpr PressureSample FakeCpuProbe::kInitialSample;
- FakeCpuProbe::FakeCpuProbe() : last_sample_(kInitialSample) {
- DETACH_FROM_SEQUENCE(sequence_checker_);
- }
- FakeCpuProbe::~FakeCpuProbe() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- }
- void FakeCpuProbe::Update() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- // In DCHECKed builds, the ScopedBlockingCall ensures that Update() is only
- // called on sequences where I/O is allowed.
- base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
- base::BlockingType::MAY_BLOCK);
- }
- PressureSample FakeCpuProbe::LastSample() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::AutoLock auto_lock(lock_);
- return last_sample_;
- }
- void FakeCpuProbe::SetLastSample(PressureSample sample) {
- base::AutoLock auto_lock(lock_);
- last_sample_ = sample;
- }
- } // namespace device
|