| Index: base/test/energy_monitor_mac.h
|
| diff --git a/base/test/energy_monitor_mac.h b/base/test/energy_monitor_mac.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..eaed60de80badfbedf6259b73968f0f9f083744d
|
| --- /dev/null
|
| +++ b/base/test/energy_monitor_mac.h
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2015 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 BASE_TEST_ENERGY_MONITOR_MAC_H_
|
| +#define BASE_TEST_ENERGY_MONITOR_MAC_H_
|
| +
|
| +#include <stdint.h>
|
| +#include <vector>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/time/time.h"
|
| +
|
| +namespace base {
|
| +
|
| +class FilePath;
|
| +
|
| +namespace test {
|
| +
|
| +// Class that executes a base::RunLoop on the current thread, sampling power
|
| +// draw from Intel Machine-Specific Registers at regular intervals.
|
| +class EnergyMonitorMac {
|
| + public:
|
| + enum EnergyType { PROCESSOR, IA, NUM_ENERGY_TYPES };
|
| +
|
| + EnergyMonitorMac();
|
| + ~EnergyMonitorMac();
|
| +
|
| + // Executes a run loop on the current thread. Starts taking samples after
|
| + // |warmup_delay|, and quits the runloop after taking num_samples.
|
| + void Run(const base::TimeDelta& warmup_delay, size_t num_samples);
|
| +
|
| + // Set the sampling frequency. By default, each sample is taken after a 50
|
| + // millisecond delay by posting an event to the RunLoop.
|
| + void SetSampleDelay(const base::TimeDelta& sample_delay);
|
| +
|
| + double GetAverageWatts(EnergyType type) const;
|
| + double GetStdDevWatts(EnergyType type) const;
|
| +
|
| + void WriteTimeSeries(const base::FilePath& file);
|
| +
|
| + private:
|
| + void ReadNextSample();
|
| + void TakeSample();
|
| +
|
| + base::TimeDelta sample_delay_;
|
| + size_t target_sample_count_ = ~0;
|
| + base::Closure quit_closure_;
|
| +
|
| + struct {
|
| + int msr_index = -1;
|
| + std::vector<double> watts;
|
| + } samples_[NUM_ENERGY_TYPES];
|
| +
|
| + std::vector<uint64_t> rdtsc_values_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(EnergyMonitorMac);
|
| +};
|
| +
|
| +} // namespace test
|
| +} // namespace base
|
| +
|
| +#endif // BASE_TEST_ENERGY_MONITOR_MAC_H_
|
|
|