mirror of
https://github.com/google/benchmark.git
synced 2025-01-30 22:00:16 +08:00
Fix printing of time
This commit is contained in:
parent
e390e4ebc3
commit
9a25f47250
@ -341,10 +341,9 @@ bool ConsoleReporter::ReportContext(const BenchmarkContextData& context) {
|
|||||||
<< ((context.num_cpus > 1) ? "s" : "") << "\n";
|
<< ((context.num_cpus > 1) ? "s" : "") << "\n";
|
||||||
|
|
||||||
int remainder_ms;
|
int remainder_ms;
|
||||||
char time_buf[32];
|
|
||||||
std::cout << walltime::Print(walltime::Now(), "%Y/%m/%d-%H:%M:%S",
|
std::cout << walltime::Print(walltime::Now(), "%Y/%m/%d-%H:%M:%S",
|
||||||
true, // use local timezone
|
true, // use local timezone
|
||||||
time_buf, &remainder_ms) << "\n";
|
&remainder_ms) << "\n";
|
||||||
|
|
||||||
// Show details of CPU model, caches, TLBs etc.
|
// Show details of CPU model, caches, TLBs etc.
|
||||||
// if (!context.cpu_info.empty())
|
// if (!context.cpu_info.empty())
|
||||||
|
@ -119,21 +119,22 @@ WallTime Now() {
|
|||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Print(WallTime time, const char *format, bool local,
|
std::string Print(WallTime time, const char *format, bool local,
|
||||||
char* storage, int *remainder_us) {
|
int *remainder_us) {
|
||||||
struct tm split;
|
char storage[32];
|
||||||
double subsecond;
|
struct tm split;
|
||||||
if (!SplitTimezone(time, local, &split, &subsecond)) {
|
double subsecond;
|
||||||
snprintf(storage, sizeof(storage), "Invalid time: %f", time);
|
if (!SplitTimezone(time, local, &split, &subsecond)) {
|
||||||
} else {
|
snprintf(storage, sizeof(storage), "Invalid time: %f", time);
|
||||||
if (remainder_us != NULL) {
|
} else {
|
||||||
*remainder_us = static_cast<int>((subsecond * 1000000) + 0.5);
|
if (remainder_us != NULL) {
|
||||||
if (*remainder_us > 999999) *remainder_us = 999999;
|
*remainder_us = static_cast<int>((subsecond * 1000000) + 0.5);
|
||||||
if (*remainder_us < 0) *remainder_us = 0;
|
if (*remainder_us > 999999) *remainder_us = 999999;
|
||||||
}
|
if (*remainder_us < 0) *remainder_us = 0;
|
||||||
strftime(storage, sizeof(storage), format, &split);
|
|
||||||
}
|
}
|
||||||
return storage;
|
strftime(storage, sizeof(storage), format, &split);
|
||||||
|
}
|
||||||
|
return std::string(storage);
|
||||||
}
|
}
|
||||||
} // end namespace walltime
|
} // end namespace walltime
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef BENCHMARK_WALLTIME_H_
|
#ifndef BENCHMARK_WALLTIME_H_
|
||||||
#define BENCHMARK_WALLTIME_H_
|
#define BENCHMARK_WALLTIME_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace benchmark {
|
namespace benchmark {
|
||||||
typedef double WallTime;
|
typedef double WallTime;
|
||||||
|
|
||||||
@ -10,11 +12,11 @@ WallTime Now();
|
|||||||
|
|
||||||
// GIVEN: walltime, generic format string (as understood by strftime),
|
// GIVEN: walltime, generic format string (as understood by strftime),
|
||||||
// a boolean flag specifying if the time is local or UTC (true=local).
|
// a boolean flag specifying if the time is local or UTC (true=local).
|
||||||
// RETURNS: the formatted string. ALSO RETURNS: the storage printbuffer
|
// RETURNS: the formatted string. ALSO RETURNS: the remaining number of
|
||||||
// passed and the remaining number of microseconds (never printed in
|
// microseconds (never printed in the string since strftime does not understand
|
||||||
// the string since strftime does not understand it)
|
// it)
|
||||||
const char* Print(WallTime time, const char *format, bool local,
|
std::string Print(WallTime time, const char *format, bool local,
|
||||||
char* storage, int *remainder_us);
|
int *remainder_us);
|
||||||
} // end namespace walltime
|
} // end namespace walltime
|
||||||
} // end namespace benchmark
|
} // end namespace benchmark
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user