| 96 | } |
| 97 | |
| 98 | static int prepare_trace_line(const char *file, int line, |
| 99 | struct trace_key *key, struct strbuf *buf) |
| 100 | { |
| 101 | static struct trace_key trace_bare = TRACE_KEY_INIT(BARE); |
| 102 | struct timeval tv; |
| 103 | struct tm tm; |
| 104 | time_t secs; |
| 105 | |
| 106 | if (!trace_want(key)) |
| 107 | return 0; |
| 108 | |
| 109 | /* unit tests may want to disable additional trace output */ |
| 110 | if (trace_want(&trace_bare)) |
| 111 | return 1; |
| 112 | |
| 113 | /* print current timestamp */ |
| 114 | gettimeofday(&tv, NULL); |
| 115 | secs = tv.tv_sec; |
| 116 | localtime_r(&secs, &tm); |
| 117 | strbuf_addf(buf, "%02d:%02d:%02d.%06ld %s:%d", tm.tm_hour, tm.tm_min, |
| 118 | tm.tm_sec, (long) tv.tv_usec, file, line); |
| 119 | /* align trace output (column 40 catches most files names in git) */ |
| 120 | while (buf->len < 40) |
| 121 | strbuf_addch(buf, ' '); |
| 122 | |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | static void trace_write(struct trace_key *key, const void *buf, unsigned len) |
| 127 | { |
no test coverage detected