49 lines · c
1#ifndef BENCHMARK_TIMERS_H2#define BENCHMARK_TIMERS_H3 4#include <chrono>5#include <string>6 7namespace benchmark {8 9// Return the CPU usage of the current process10double ProcessCPUUsage();11 12// Return the CPU usage of the children of the current process13double ChildrenCPUUsage();14 15// Return the CPU usage of the current thread16double ThreadCPUUsage();17 18#if defined(HAVE_STEADY_CLOCK)19template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>20struct ChooseSteadyClock {21 typedef std::chrono::high_resolution_clock type;22};23 24template <>25struct ChooseSteadyClock<false> {26 typedef std::chrono::steady_clock type;27};28#endif29 30struct ChooseClockType {31#if defined(HAVE_STEADY_CLOCK)32 typedef ChooseSteadyClock<>::type type;33#else34 typedef std::chrono::high_resolution_clock type;35#endif36};37 38inline double ChronoClockNow() {39 typedef ChooseClockType::type ClockType;40 using FpSeconds = std::chrono::duration<double, std::chrono::seconds::period>;41 return FpSeconds(ClockType::now().time_since_epoch()).count();42}43 44std::string LocalDateTimeString();45 46} // end namespace benchmark47 48#endif // BENCHMARK_TIMERS_H49