mirror of
https://github.com/google/benchmark.git
synced 2024-12-04 11:03:42 +00:00
cba945e37d
* Change to using per-thread timers * fix bad assertions * fix copy paste error on windows * Fix thread safety annotations * Make null-log thread safe * remove remaining globals * use chrono for walltime since it is thread safe * consolidate timer functions * Add missing ctime include * Rename to be consistent with Google style * Format patch using clang-format * cleanup -Wthread-safety configuration * Don't trust _POSIX_FEATURE macros because OS X lies. * Fix OS X thread timings * attempt to fix mingw build * Attempt to make mingw work again * Revert old mingw workaround * improve diagnostics * Drastically improve OS X measurements * Use average real time instead of max
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#ifndef BENCHMARK_TIMERS_H
|
|
#define BENCHMARK_TIMERS_H
|
|
|
|
#include <chrono>
|
|
#include <string>
|
|
|
|
namespace benchmark {
|
|
|
|
// Return the CPU usage of the current process
|
|
double ProcessCPUUsage();
|
|
|
|
// Return the CPU usage of the children of the current process
|
|
double ChildrenCPUUsage();
|
|
|
|
// Return the CPU usage of the current thread
|
|
double ThreadCPUUsage();
|
|
|
|
#if defined(HAVE_STEADY_CLOCK)
|
|
template <bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
|
|
struct ChooseSteadyClock {
|
|
typedef std::chrono::high_resolution_clock type;
|
|
};
|
|
|
|
template <>
|
|
struct ChooseSteadyClock<false> {
|
|
typedef std::chrono::steady_clock type;
|
|
};
|
|
#endif
|
|
|
|
struct ChooseClockType {
|
|
#if defined(HAVE_STEADY_CLOCK)
|
|
typedef ChooseSteadyClock<>::type type;
|
|
#else
|
|
typedef std::chrono::high_resolution_clock type;
|
|
#endif
|
|
};
|
|
|
|
inline double ChronoClockNow() {
|
|
typedef ChooseClockType::type ClockType;
|
|
using FpSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
|
|
return FpSeconds(ClockType::now().time_since_epoch()).count();
|
|
}
|
|
|
|
std::string LocalDateTimeString();
|
|
|
|
} // end namespace benchmark
|
|
|
|
#endif // BENCHMARK_TIMERS_H
|