summaryrefslogtreecommitdiff
path: root/trace.h
diff options
context:
space:
mode:
authorKarsten Blees <karsten.blees@gmail.com>2014-07-12 02:00:06 +0200
committerJunio C Hamano <gitster@pobox.com>2014-07-13 21:24:23 -0700
commit6aa3085702cc7a436c12f4c4396958281df1da44 (patch)
treea01c3df1a78b0db0334349156f1971b7eeb172b0 /trace.h
parent0d0424272f85afb5262613829cf1f48f994cebc7 (diff)
downloadgit-6aa3085702cc7a436c12f4c4396958281df1da44.tar.gz
trace: improve trace performance
The trace API currently rechecks the environment variable and reopens the trace file on every API call. This has the ugly side effect that errors (e.g. file cannot be opened, or the user specified a relative path) are also reported on every call. Performance can be improved by about factor three by remembering the environment state and keeping the file open. Replace the 'const char *key' parameter in the API with a pointer to a 'struct trace_key' that bundles the environment variable name with additional, trace-internal state. Change the call sites of these APIs to use a static 'struct trace_key' instead of a string constant. In trace.c::get_trace_fd(), save and reuse the file descriptor in 'struct trace_key'. Add a 'trace_disable()' API, so that packet_trace() can cleanly disable tracing when it encounters packed data (instead of using unsetenv()). Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'trace.h')
-rw-r--r--trace.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/trace.h b/trace.h
index 8fea50bf1d..d85ac4c652 100644
--- a/trace.h
+++ b/trace.h
@@ -4,14 +4,24 @@
#include "git-compat-util.h"
#include "strbuf.h"
+struct trace_key {
+ const char * const key;
+ int fd;
+ unsigned int initialized : 1;
+ unsigned int need_close : 1;
+};
+
+#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
+
__attribute__((format (printf, 1, 2)))
extern void trace_printf(const char *format, ...);
__attribute__((format (printf, 2, 3)))
extern void trace_argv_printf(const char **argv, const char *format, ...);
extern void trace_repo_setup(const char *prefix);
-extern int trace_want(const char *key);
+extern int trace_want(struct trace_key *key);
+extern void trace_disable(struct trace_key *key);
__attribute__((format (printf, 2, 3)))
-extern void trace_printf_key(const char *key, const char *format, ...);
-extern void trace_strbuf(const char *key, const struct strbuf *buf);
+extern void trace_printf_key(struct trace_key *key, const char *format, ...);
+extern void trace_strbuf(struct trace_key *key, const struct strbuf *buf);
#endif /* TRACE_H */