log: display time in microseconds when DEBUG_TIMING is set

This commit is contained in:
Michael Stapelberg 2011-07-10 23:11:21 +02:00
parent 937a80511a
commit 48f5166daf
1 changed files with 7 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h>
#include "util.h" #include "util.h"
#include "log.h" #include "log.h"
@ -89,7 +90,13 @@ void vlog(char *fmt, va_list args) {
struct tm *tmp = localtime(&t); struct tm *tmp = localtime(&t);
/* Generate time prefix */ /* Generate time prefix */
strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp); strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp);
#ifdef DEBUG_TIMING
struct timeval tv;
gettimeofday(&tv, NULL);
printf("%s%d.%d - ", timebuf, tv.tv_sec, tv.tv_usec);
#else
printf("%s", timebuf); printf("%s", timebuf);
#endif
vprintf(fmt, args); vprintf(fmt, args);
} }