summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrofl0r <rofl0r@users.noreply.github.com>2020-09-30 05:20:09 +0100
committerrofl0r <rofl0r@users.noreply.github.com>2020-09-30 05:20:09 +0100
commitf55c46eb397e0371b03ba91276beea9e8dd95d87 (patch)
tree54db4a8c332cd6040996eb5a98005252bacf3358 /src
parent10494cab8c19843aa415229e3b796d0322384cb3 (diff)
log: print timestamps with millisecond precision
this allows easier time measurements for benchmarks.
Diffstat (limited to 'src')
-rw-r--r--src/log.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/log.c b/src/log.c
index dc76c1a..873abb2 100644
--- a/src/log.c
+++ b/src/log.c
@@ -108,7 +108,7 @@ void set_log_level (int level)
void log_message (int level, const char *fmt, ...)
{
va_list args;
- time_t nowtime;
+ struct timespec nowtime;
char time_string[TIME_LENGTH];
char str[STRING_LENGTH];
@@ -174,13 +174,14 @@ void log_message (int level, const char *fmt, ...)
} else {
char *p;
- nowtime = time (NULL);
+ clock_gettime(CLOCK_REALTIME, &nowtime);
/* Format is month day hour:minute:second (24 time) */
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
- localtime (&nowtime));
+ localtime (&nowtime.tv_sec));
- snprintf (str, STRING_LENGTH, "%-9s %s [%ld]: ",
+ snprintf (str, STRING_LENGTH, "%-9s %s.%03u [%ld]: ",
syslog_level[level], time_string,
+ nowtime.tv_nsec/1000000u,
(long int) getpid ());
/*