mirror of
https://github.com/google/benchmark.git
synced 2025-01-13 13:20:13 +08:00
finish selection of clock with debug information
This commit is contained in:
parent
48c4c9cf50
commit
d3e0671a87
@ -54,6 +54,7 @@ endif()
|
||||
cxx_feature_check(STD_REGEX)
|
||||
cxx_feature_check(GNU_POSIX_REGEX)
|
||||
cxx_feature_check(POSIX_REGEX)
|
||||
cxx_feature_check(STEADY_CLOCK)
|
||||
|
||||
# Set up directories
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
|
7
cmake/steady_clock.cpp
Normal file
7
cmake/steady_clock.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <chrono>
|
||||
|
||||
int main() {
|
||||
typedef std::chrono::steady_clock Clock;
|
||||
Clock::time_point tp = Clock::now();
|
||||
((void)tp);
|
||||
}
|
@ -103,7 +103,7 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
||||
|
||||
if (context.cpu_scaling_enabled) {
|
||||
fprintf(stdout, "***WARNING*** CPU scaling is enabled, the benchmark "
|
||||
"timings may be noisy\n");
|
||||
"timings may be noisy and will incure extra overhead.\n");
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "arraysize.h"
|
||||
#include "check.h"
|
||||
#include "cycleclock.h"
|
||||
#include "log.h"
|
||||
#include "sysinfo.h"
|
||||
|
||||
namespace benchmark {
|
||||
@ -36,6 +37,26 @@ namespace walltime {
|
||||
|
||||
namespace {
|
||||
|
||||
#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 typename ChooseSteadyClock<>::type type;
|
||||
#else
|
||||
typedef std::chrono::high_resolution_clock type;
|
||||
#endif
|
||||
};
|
||||
|
||||
class WallTimeImp
|
||||
{
|
||||
public:
|
||||
@ -151,7 +172,7 @@ WallTime CPUWalltimeNow() {
|
||||
}
|
||||
|
||||
WallTime ChronoWalltimeNow() {
|
||||
typedef std::chrono::system_clock Clock;
|
||||
typedef ChooseClockType::type Clock;
|
||||
typedef std::chrono::duration<WallTime, std::chrono::seconds::period>
|
||||
FPSeconds;
|
||||
static_assert(std::chrono::treat_as_floating_point<WallTime>::value,
|
||||
@ -160,13 +181,23 @@ WallTime ChronoWalltimeNow() {
|
||||
return std::chrono::duration_cast<FPSeconds>(now).count();
|
||||
}
|
||||
|
||||
bool UseCpuCycleClock() {
|
||||
bool useWallTime = !CpuScalingEnabled();
|
||||
if (useWallTime) {
|
||||
VLOG(1) << "Using the CPU cycle clock to provide walltime::Now().\n";
|
||||
} else {
|
||||
VLOG(1) << "Using std::chrono to provide walltime::Now().\n";
|
||||
}
|
||||
return useWallTime;
|
||||
}
|
||||
|
||||
// WallTimeImp doesn't work when CPU Scaling is enabled. If CPU Scaling is
|
||||
// enabled at the start of the program then std::chrono::system_clock is used
|
||||
// instead.
|
||||
WallTime Now()
|
||||
{
|
||||
static bool useWallTime = !CpuScalingEnabled();
|
||||
if (useWallTime) {
|
||||
static bool useCPUClock = UseCpuCycleClock();
|
||||
if (useCPUClock) {
|
||||
return CPUWalltimeNow();
|
||||
} else {
|
||||
return ChronoWalltimeNow();
|
||||
@ -182,14 +213,11 @@ std::string DateTimeString(bool local) {
|
||||
char storage[128];
|
||||
|
||||
std::tm timeinfo;
|
||||
std::memset(&timeinfo, 0, sizeof(std::tm));
|
||||
if (local) {
|
||||
std::tm* ret = std::localtime(&now);
|
||||
CHECK(ret != nullptr);
|
||||
timeinfo = *ret;
|
||||
::localtime_r(&now, &timeinfo);
|
||||
} else {
|
||||
std::tm* ret = std::gmtime(&now);
|
||||
CHECK(ret != nullptr);
|
||||
timeinfo = *ret;
|
||||
::gmtime_r(&now, &timeinfo);
|
||||
}
|
||||
std::size_t written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||
CHECK(written < arraysize(storage));
|
||||
|
Loading…
Reference in New Issue
Block a user