timers.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef BENCHMARK_TIMERS_H
  2. #define BENCHMARK_TIMERS_H
  3. #include <chrono>
  4. #include <string>
  5. namespace benchmark {
  6. // Return the CPU usage of the current process
  7. double ProcessCPUUsage();
  8. // Return the CPU usage of the children of the current process
  9. double ChildrenCPUUsage();
  10. // Return the CPU usage of the current thread
  11. double ThreadCPUUsage();
  12. #if defined(HAVE_STEADY_CLOCK)
  13. template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
  14. struct ChooseSteadyClock {
  15. typedef std::chrono::high_resolution_clock type;
  16. };
  17. template <>
  18. struct ChooseSteadyClock<false> {
  19. typedef std::chrono::steady_clock type;
  20. };
  21. #endif
  22. struct ChooseClockType {
  23. #if defined(HAVE_STEADY_CLOCK)
  24. typedef ChooseSteadyClock<>::type type;
  25. #else
  26. typedef std::chrono::high_resolution_clock type;
  27. #endif
  28. };
  29. inline double ChronoClockNow() {
  30. typedef ChooseClockType::type ClockType;
  31. using FpSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
  32. return FpSeconds(ClockType::now().time_since_epoch()).count();
  33. }
  34. std::string LocalDateTimeString();
  35. } // end namespace benchmark
  36. #endif // BENCHMARK_TIMERS_H