OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 |
| 5 #ifndef BASE_TEST_ENERGY_MONITOR_MAC_H_ |
| 6 #define BASE_TEST_ENERGY_MONITOR_MAC_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/time/time.h" |
| 13 |
| 14 namespace base { |
| 15 |
| 16 class FilePath; |
| 17 |
| 18 namespace test { |
| 19 |
| 20 // Class that executes a base::RunLoop on the current thread, sampling power |
| 21 // draw from Intel Machine-Specific Registers at regular intervals. |
| 22 class EnergyMonitorMac { |
| 23 public: |
| 24 enum EnergyType { PROCESSOR, IA, NUM_ENERGY_TYPES }; |
| 25 |
| 26 EnergyMonitorMac(); |
| 27 ~EnergyMonitorMac(); |
| 28 |
| 29 // Executes a run loop on the current thread. Starts taking samples after |
| 30 // |warmup_delay|, and quits the runloop after taking num_samples. |
| 31 void Run(const base::TimeDelta& warmup_delay, size_t num_samples); |
| 32 |
| 33 // Set the sampling frequency. By default, each sample is taken after a 50 |
| 34 // millisecond delay by posting an event to the RunLoop. |
| 35 void SetSampleDelay(const base::TimeDelta& sample_delay); |
| 36 |
| 37 double GetAverageWatts(EnergyType type) const; |
| 38 double GetStdDevWatts(EnergyType type) const; |
| 39 |
| 40 void WriteTimeSeries(const base::FilePath& file); |
| 41 |
| 42 private: |
| 43 void ReadNextSample(); |
| 44 void TakeSample(); |
| 45 |
| 46 base::TimeDelta sample_delay_; |
| 47 size_t target_sample_count_ = ~0; |
| 48 base::Closure quit_closure_; |
| 49 |
| 50 struct { |
| 51 int msr_index = -1; |
| 52 std::vector<double> watts; |
| 53 } samples_[NUM_ENERGY_TYPES]; |
| 54 |
| 55 std::vector<uint64_t> rdtsc_values_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(EnergyMonitorMac); |
| 58 }; |
| 59 |
| 60 } // namespace test |
| 61 } // namespace base |
| 62 |
| 63 #endif // BASE_TEST_ENERGY_MONITOR_MAC_H_ |
OLD | NEW |