diff options
-rw-r--r-- | trace.c | 3 | ||||
-rw-r--r-- | trace.h | 59 |
2 files changed, 42 insertions, 20 deletions
@@ -25,6 +25,7 @@ #include "quote.h" struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; +struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); /* Get a trace file descriptor from "key" env variable. */ static int get_trace_fd(struct trace_key *key) @@ -172,8 +173,6 @@ void trace_strbuf_fl(const char *file, int line, struct trace_key *key, print_trace_line(key, &buf); } -static struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); - static void trace_performance_vprintf_fl(const char *file, int line, uint64_t nanos, const char *format, va_list ap) @@ -14,6 +14,7 @@ struct trace_key { extern struct trace_key trace_default_key; #define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 } +extern struct trace_key trace_perf_key; extern void trace_repo_setup(const char *prefix); extern int trace_want(struct trace_key *key); @@ -79,24 +80,42 @@ extern void trace_performance_since(uint64_t start, const char *format, ...); * comma, but this is non-standard. */ -#define trace_printf(...) \ - trace_printf_key_fl(TRACE_CONTEXT, __LINE__, &trace_default_key, __VA_ARGS__) - -#define trace_printf_key(key, ...) \ - trace_printf_key_fl(TRACE_CONTEXT, __LINE__, key, __VA_ARGS__) - -#define trace_argv_printf(argv, ...) \ - trace_argv_printf_fl(TRACE_CONTEXT, __LINE__, argv, __VA_ARGS__) - -#define trace_strbuf(key, data) \ - trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data) - -#define trace_performance(nanos, ...) \ - trace_performance_fl(TRACE_CONTEXT, __LINE__, nanos, __VA_ARGS__) - -#define trace_performance_since(start, ...) \ - trace_performance_fl(TRACE_CONTEXT, __LINE__, getnanotime() - (start), \ - __VA_ARGS__) +#define trace_printf_key(key, ...) \ + do { \ + if (trace_pass_fl(key)) \ + trace_printf_key_fl(TRACE_CONTEXT, __LINE__, key, \ + __VA_ARGS__); \ + } while (0) + +#define trace_printf(...) trace_printf_key(&trace_default_key, __VA_ARGS__) + +#define trace_argv_printf(argv, ...) \ + do { \ + if (trace_pass_fl(&trace_default_key)) \ + trace_argv_printf_fl(TRACE_CONTEXT, __LINE__, \ + argv, __VA_ARGS__); \ + } while (0) + +#define trace_strbuf(key, data) \ + do { \ + if (trace_pass_fl(key)) \ + trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data);\ + } while (0) + +#define trace_performance(nanos, ...) \ + do { \ + if (trace_pass_fl(&trace_perf_key)) \ + trace_performance_fl(TRACE_CONTEXT, __LINE__, nanos,\ + __VA_ARGS__); \ + } while (0) + +#define trace_performance_since(start, ...) \ + do { \ + if (trace_pass_fl(&trace_perf_key)) \ + trace_performance_fl(TRACE_CONTEXT, __LINE__, \ + getnanotime() - (start), \ + __VA_ARGS__); \ + } while (0) /* backend functions, use non-*fl macros instead */ __attribute__((format (printf, 4, 5))) @@ -110,6 +129,10 @@ extern void trace_strbuf_fl(const char *file, int line, struct trace_key *key, __attribute__((format (printf, 4, 5))) extern void trace_performance_fl(const char *file, int line, uint64_t nanos, const char *fmt, ...); +static inline int trace_pass_fl(struct trace_key *key) +{ + return key->fd || !key->initialized; +} #endif /* HAVE_VARIADIC_MACROS */ |