trace: add current timestamp to all trace output
This is useful to tell apart trace output of separate test runs. It can also be used for basic, coarse-grained performance analysis. Note that the accuracy is tainted by writing to the trace file, and you have to calculate the deltas yourself (which is next to impossible if multiple threads or processes are involved). Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karsten Blees committed
Jul 12, 2014 at 02:03 UTC
b72be02cfb402bbd6abac07af7231613cd37d594
1 file changed
+9
-1
trace.c
+9
-1
@@ -88,6 +88,9 @@ static const char err_msg[] = "Could not trace into fd given by "
88
static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
89
{
90
static struct trace_key trace_bare = TRACE_KEY_INIT(BARE);
91
+ struct timeval tv;
92
+ struct tm tm;
93
+ time_t secs;
94
95
if (!trace_want(key))
96
return 0;
@@ -98,7 +101,12 @@ static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
101
if (trace_want(&trace_bare))
102
return 1;
103
101
- /* add line prefix here */
104
+ /* print current timestamp */
105
+ gettimeofday(&tv, NULL);
106
+ secs = tv.tv_sec;
107
+ localtime_r(&secs, &tm);
108
+ strbuf_addf(buf, "%02d:%02d:%02d.%06ld ", tm.tm_hour, tm.tm_min,
109
+ tm.tm_sec, (long) tv.tv_usec);
110
111
return 1;
112
}