aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-20 09:14:26 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-20 09:14:26 +0000
commitb70139ece58a5e8204990c5df406e99f948da460 (patch)
tree3bb9940848dedb561e1f7727fcd059974814d44d /src/util
parent1ad257905ce4a45bbe59b08ea52a3c3c6622da5d (diff)
downloadgnunet-b70139ece58a5e8204990c5df406e99f948da460.tar.gz
gnunet-b70139ece58a5e8204990c5df406e99f948da460.zip
high-precision LOG timers
Diffstat (limited to 'src/util')
-rw-r--r--src/util/common_logging.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 95400497e..a80321c83 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -134,6 +134,13 @@ static unsigned int skip_log;
134 */ 134 */
135static FILE *GNUNET_stderr; 135static FILE *GNUNET_stderr;
136 136
137#ifdef WINDOWS
138/**
139 * Contains the number of performance counts per second.
140 */
141LARGE_INTEGER performance_frequency;
142#endif
143
137/** 144/**
138 * Convert a textual description of a loglevel 145 * Convert a textual description of a loglevel
139 * to the respective GNUNET_GE_KIND. 146 * to the respective GNUNET_GE_KIND.
@@ -173,6 +180,9 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
173 int dirwarn; 180 int dirwarn;
174 char *fn; 181 char *fn;
175 182
183#ifdef WINDOWS
184 QueryPerformanceFrequency (&performance_frequency);
185#endif
176 GNUNET_free_non_null (component); 186 GNUNET_free_non_null (component);
177 GNUNET_asprintf (&component, 187 GNUNET_asprintf (&component,
178 "%s-%d", 188 "%s-%d",
@@ -355,7 +365,9 @@ mylog (enum GNUNET_ErrorType kind,
355 const char *comp, const char *message, va_list va) 365 const char *comp, const char *message, va_list va)
356{ 366{
357 char date[DATE_STR_SIZE]; 367 char date[DATE_STR_SIZE];
368 char date2[DATE_STR_SIZE];
358 time_t timetmp; 369 time_t timetmp;
370 struct timeval timeofday;
359 struct tm *tmptr; 371 struct tm *tmptr;
360 size_t size; 372 size_t size;
361 char *buf; 373 char *buf;
@@ -378,8 +390,20 @@ mylog (enum GNUNET_ErrorType kind,
378 time (&timetmp); 390 time (&timetmp);
379 memset (date, 0, DATE_STR_SIZE); 391 memset (date, 0, DATE_STR_SIZE);
380 tmptr = localtime (&timetmp); 392 tmptr = localtime (&timetmp);
393 gettimeofday(&timeofday, NULL);
381 if (NULL != tmptr) 394 if (NULL != tmptr)
382 strftime (date, DATE_STR_SIZE, "%b %d %H:%M:%S", tmptr); 395 {
396#ifdef WINDOWS
397 LARGE_INTEGER pc;
398 pc.QuadPart = 0;
399 QueryPerformanceCounter (&pc);
400 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
401 snprintf (date, sizeof (date), date2, (long long) (pc.QuadPart / (performance_frequency.QuadPart / 1000)));
402#else
403 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
404 snprintf (date, sizeof (date), date2, timeofday.tv_usec);
405#endif
406 }
383 else 407 else
384 strcpy (date, "localtime error"); 408 strcpy (date, "localtime error");
385 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && 409 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&