View Issue Details

IDProjectCategoryView StatusLast Update
0001715GNUnetutil librarypublic2011-07-02 09:26
ReporterLRN Assigned ToLRN  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product VersionGit master 
Summary0001715: Add milliseconds to the log timestamps
DescriptionMilliseconds really help to debug inter-process synchronization, at least on W32.
This patch adds normal system-time-based milliseconds (as part of current time), i.e. from 0 to 999 - on *nix, while on W32 it adds the result of the high-precision performance counter, adjusted to milliseconds (because of that milliseconds on W32 are not correlated with the timestamp).
I can't vouch that the timestamps will match when two processes are working on different cores, but for now such matching is not required.
TagsNo tags attached.
Attached Files
0001-Add-milliseconds-to-the-log.patch (2,286 bytes)   
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?= <lrn1986@gmail.com>
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

Activities

Christian Grothoff

2011-06-20 11:14

manager   ~0004440

Patch applied in SVN 15720.

Issue History

Date Modified Username Field Change
2011-06-18 13:38 LRN New Issue
2011-06-18 13:38 LRN File Added: 0001-Add-milliseconds-to-the-log.patch
2011-06-19 12:24 Christian Grothoff Status new => assigned
2011-06-19 12:24 Christian Grothoff Assigned To => Christian Grothoff
2011-06-20 11:14 Christian Grothoff Note Added: 0004440
2011-06-20 11:14 Christian Grothoff Status assigned => resolved
2011-06-20 11:14 Christian Grothoff Resolution open => fixed
2011-06-20 11:15 Christian Grothoff Assigned To Christian Grothoff => LRN
2011-07-02 09:26 Christian Grothoff Status resolved => closed