Shows microsecs instead of millisecs

This commit is contained in:
Bob Polis 2023-08-03 11:03:11 +02:00
parent a4ae9bc6e1
commit eab2f57bb3

View File

@ -17,7 +17,6 @@
#include <cstdarg> #include <cstdarg>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <cmath>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -35,13 +34,12 @@ void print_timestamp()
// retrieve accurate time for milliseconds display // retrieve accurate time for milliseconds display
struct timeval secs; struct timeval secs;
(void)::gettimeofday(&secs, nullptr); (void)::gettimeofday(&secs, nullptr);
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
// create a date/time stamp // create a date/time stamp
char dtstamp[20]; char dtstamp[20];
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec)); std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
std::cerr << dtstamp << "." << std::setw(3) << ms << " "; std::cerr << dtstamp << "." << std::setw(6) << secs.tv_usec << " ";
#if __APPLE__ #if __APPLE__
std::cerr << getprogname() << "[" << getpid() << "] "; std::cerr << getprogname() << "[" << getpid() << "] ";
#elif __linux__ #elif __linux__