summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2014-07-12 00:03:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-14 04:25:19 (GMT)
commitb72be02cfb402bbd6abac07af7231613cd37d594 (patch)
tree5d295bfd9891b37fe2fa674b5bb2b709b092ad58
parent124647c4b007eff04144d75042d9d95f63e303f7 (diff)
downloadgit-b72be02cfb402bbd6abac07af7231613cd37d594.zip
git-b72be02cfb402bbd6abac07af7231613cd37d594.tar.gz
git-b72be02cfb402bbd6abac07af7231613cd37d594.tar.bz2
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>
-rw-r--r--trace.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/trace.c b/trace.c
index a194b16..18e5d93 100644
--- a/trace.c
+++ b/trace.c
@@ -88,6 +88,9 @@ static const char err_msg[] = "Could not trace into fd given by "
static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
{
static struct trace_key trace_bare = TRACE_KEY_INIT(BARE);
+ struct timeval tv;
+ struct tm tm;
+ time_t secs;
if (!trace_want(key))
return 0;
@@ -98,7 +101,12 @@ static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
if (trace_want(&trace_bare))
return 1;
- /* add line prefix here */
+ /* print current timestamp */
+ gettimeofday(&tv, NULL);
+ secs = tv.tv_sec;
+ localtime_r(&secs, &tm);
+ strbuf_addf(buf, "%02d:%02d:%02d.%06ld ", tm.tm_hour, tm.tm_min,
+ tm.tm_sec, (long) tv.tv_usec);
return 1;
}