]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add support for a --time-stamp option that causes each message output
authorTom Hughes <tom@compton.nu>
Sat, 21 Aug 2004 11:10:44 +0000 (11:10 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 21 Aug 2004 11:10:44 +0000 (11:10 +0000)
by valgrind to include a time stamp. This fixes bug #70587.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2594

coregrind/docs/coregrind_core.html
coregrind/vg_include.h
coregrind/vg_main.c
coregrind/vg_messages.c
none/tests/cmdline1.stdout.exp
none/tests/cmdline2.stdout.exp

index 1a3ea84842b87e057e37ed98ec98abdde178f8ae..384791e39e7c61e1a44e1c0e60ae1a58a3919caa 100644 (file)
@@ -557,6 +557,12 @@ These options work with all tools.
       <code>valgrind-listener</code> program.  For further details,
       see section <a href="#core-comment">2.3</a>.
       </li><br><p>
+
+  <li><code>--time-stamp=no</code> [default]<br>
+      <code>--time-stamp=yes</code>
+      <p>Specifies that valgrind should output a timestamp before
+      each message that it outputs.
+      </li><br><p>
 </ul>
 
 <h4>Error-related options</h4>
index 7bd817f394b3522d44535f9036f05b577c237b98..2fad874735118439291928c5ba811206422ef0f1 100644 (file)
@@ -204,6 +204,9 @@ extern VgLogTo VG_(clo_log_to);
 extern Int     VG_(clo_log_fd);
 extern Char*   VG_(clo_log_name);
 
+/* Add timestamps to log messages?  default: NO */
+extern Bool  VG_(clo_time_stamp);
+
 /* The file descriptor to read for input.  default: 0 == stdin */
 extern Int   VG_(clo_input_fd);
 /* The number of suppression files specified. */
index a0f96932de14e0fb5aa9353ad7d8c2a4e28045e7..ab374da9091dfaa628bb7dd967b4e5a1b50e8eb0 100644 (file)
@@ -1433,6 +1433,8 @@ VgLogTo VG_(clo_log_to)        = VgLogTo_Fd;
 Int     VG_(clo_log_fd)        = 1;
 Char*   VG_(clo_log_name)      = NULL;
 
+Bool   VG_(clo_time_stamp)     = False;
+
 Int    VG_(clo_input_fd)       = 0; /* stdin */
 Int    VG_(clo_n_suppressions) = 0;
 Char*  VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
@@ -1481,6 +1483,7 @@ void usage ( Bool debug_help )
 "    -v --verbose              be more verbose, incl counts of errors\n"
 "    --trace-children=no|yes   Valgrind-ise child processes? [no]\n"
 "    --track-fds=no|yes        track open file descriptors? [no]\n"
+"    --time-stamp=no|yes       add timestamps to log messages? [no]\n"
 "\n"
 "  uncommon user options for all Valgrind tools:\n"
 "    --run-libc-freeres=no|yes free up glibc memory at exit? [yes]\n"
@@ -1685,6 +1688,7 @@ static void process_cmd_line_options( UInt* client_auxv, const char* toolname )
       else VG_BOOL_CLO("--run-libc-freeres", VG_(clo_run_libc_freeres))
       else VG_BOOL_CLO("--show-below-main",  VG_(clo_show_below_main))
       else VG_BOOL_CLO("--single-step",      VG_(clo_single_step))
+      else VG_BOOL_CLO("--time-stamp",       VG_(clo_time_stamp))
       else VG_BOOL_CLO("--track-fds",        VG_(clo_track_fds))
       else VG_BOOL_CLO("--trace-children",   VG_(clo_trace_children))
       else VG_BOOL_CLO("--trace-sched",      VG_(clo_trace_sched))
index 5a19b0780fe326f656d4fe5e723c7d806b865b21..c7b35d109b0f8888dd81242b1e87c128302bc431 100644 (file)
@@ -32,6 +32,9 @@
 
 #include "vg_include.h"
 
+#include <time.h>
+#include <sys/time.h>
+
 
 static char vg_mbuf[M_VG_MSGBUF];
 static int vg_n_mbuf;
@@ -43,6 +46,24 @@ static void add_to_buf ( Char c )
   vg_mbuf[vg_n_mbuf]   = 0;
 }
 
+static void add_timestamp ( Char *buf )
+{
+   struct timeval tv;
+   struct tm tm;
+  
+   if ( gettimeofday( &tv, NULL ) == 0 &&
+        localtime_r( &tv.tv_sec, &tm ) == &tm ) {
+      VG_(sprintf)( buf, "%04d-%02d-%02d %02d:%02d:%02d.%03d ",
+                    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                    tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec / 1000 );
+   }
+   else {
+      VG_(strcpy)( buf, "" );
+   }
+   
+   return;
+}
+
 
 /* Publically visible from here onwards. */
 
@@ -79,9 +100,14 @@ int VG_(message) ( VgMsgKind kind, Char* format, ... )
 
 int VG_(start_msg) ( VgMsgKind kind )
 {
+   Char ts[32];
    Char c;
    vg_n_mbuf = 0;
    vg_mbuf[vg_n_mbuf] = 0;
+   if (VG_(clo_time_stamp))
+     add_timestamp(ts);
+   else
+     VG_(strcpy)(ts, "");
    switch (kind) {
       case Vg_UserMsg:       c = '='; break;
       case Vg_DebugMsg:      c = '-'; break;
@@ -89,8 +115,8 @@ int VG_(start_msg) ( VgMsgKind kind )
       case Vg_ClientMsg:     c = '*'; break;
       default:               c = '?'; break;
    }
-   return VG_(add_to_msg)( "%c%c%d%c%c ", 
-                           c,c, VG_(getpid)(), c,c );
+   return VG_(add_to_msg)( "%c%c%s%d%c%c ", 
+                           c,c, ts, VG_(getpid)(), c,c );
 }
 
 
index 1c36bca82c38e3b6deb6431d264dca5fc4647bf5..ac28bbb029f3ac1b6904bc340be5e0830c45b802 100644 (file)
@@ -9,6 +9,7 @@ usage: valgrind --tool=<toolname> [options] prog-and-args
     -v --verbose              be more verbose, incl counts of errors
     --trace-children=no|yes   Valgrind-ise child processes? [no]
     --track-fds=no|yes        track open file descriptors? [no]
+    --time-stamp=no|yes       add timestamps to log messages? [no]
 
   uncommon user options for all Valgrind tools:
     --run-libc-freeres=no|yes free up glibc memory at exit? [yes]
index c331c8d948ce2a2da7ca6ae121e58c0f1446d817..33e860734da9168600a2cfc5817ea5ebbb2a1191 100644 (file)
@@ -9,6 +9,7 @@ usage: valgrind --tool=<toolname> [options] prog-and-args
     -v --verbose              be more verbose, incl counts of errors
     --trace-children=no|yes   Valgrind-ise child processes? [no]
     --track-fds=no|yes        track open file descriptors? [no]
+    --time-stamp=no|yes       add timestamps to log messages? [no]
 
   uncommon user options for all Valgrind tools:
     --run-libc-freeres=no|yes free up glibc memory at exit? [yes]