From 05abc8f3468a7e2340a88a8fe1a97dd5c779c777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1=D1?= =?UTF-8?q?=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Sat, 18 Jun 2011 15:26:14 +0400 Subject: [PATCH 1/2] Add milliseconds to the log --- src/util/common_logging.c | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-) diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 9540049..81cdd36 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -134,6 +134,13 @@ static unsigned int skip_log; */ static FILE *GNUNET_stderr; +#if defined(WINDOWS) +/** + * Contains the number of performance counts per second. + */ +LARGE_INTEGER performance_frequency; +#endif + /** * Convert a textual description of a loglevel * to the respective GNUNET_GE_KIND. @@ -173,6 +180,9 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) int dirwarn; char *fn; +#if defined(WINDOWS) + QueryPerformanceFrequency (&performance_frequency); +#endif GNUNET_free_non_null (component); GNUNET_asprintf (&component, "%s-%d", @@ -355,7 +365,9 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, va_list va) { char date[DATE_STR_SIZE]; + char date2[DATE_STR_SIZE]; time_t timetmp; + struct timeval timeofday; struct tm *tmptr; size_t size; char *buf; @@ -378,8 +390,20 @@ mylog (enum GNUNET_ErrorType kind, time (&timetmp); memset (date, 0, DATE_STR_SIZE); tmptr = localtime (&timetmp); + gettimeofday(&timeofday, NULL); if (NULL != tmptr) - strftime (date, DATE_STR_SIZE, "%b %d %H:%M:%S", tmptr); + { +#if !defined(WINDOWS) + strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S %%06u", tmptr); + snprintf (date, sizeof date, date2, timeofday.tv_usec); +#else + LARGE_INTEGER pc; + pc.QuadPart = 0; + QueryPerformanceCounter (&pc); + strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S %%020llu", tmptr); + snprintf (date, sizeof date, date2, (long long) (pc.QuadPart / (performance_frequency.QuadPart / 1000))); +#endif + } else strcpy (date, "localtime error"); if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && -- 1.7.4