transport: pass summary_width down the callchain
[git/git-svn.git] / trace.h
blob179b249c597125ac8ad3ed2d0c0e6b00a94773eb
1 #ifndef TRACE_H
2 #define TRACE_H
4 #include "git-compat-util.h"
5 #include "strbuf.h"
7 struct trace_key {
8 const char * const key;
9 int fd;
10 unsigned int initialized : 1;
11 unsigned int need_close : 1;
14 #define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
16 extern void trace_repo_setup(const char *prefix);
17 extern int trace_want(struct trace_key *key);
18 extern void trace_disable(struct trace_key *key);
19 extern uint64_t getnanotime(void);
20 extern void trace_command_performance(const char **argv);
21 extern void trace_verbatim(struct trace_key *key, const void *buf, unsigned len);
23 #ifndef HAVE_VARIADIC_MACROS
25 __attribute__((format (printf, 1, 2)))
26 extern void trace_printf(const char *format, ...);
28 __attribute__((format (printf, 2, 3)))
29 extern void trace_printf_key(struct trace_key *key, const char *format, ...);
31 __attribute__((format (printf, 2, 3)))
32 extern void trace_argv_printf(const char **argv, const char *format, ...);
34 extern void trace_strbuf(struct trace_key *key, const struct strbuf *data);
36 /* Prints elapsed time (in nanoseconds) if GIT_TRACE_PERFORMANCE is enabled. */
37 __attribute__((format (printf, 2, 3)))
38 extern void trace_performance(uint64_t nanos, const char *format, ...);
40 /* Prints elapsed time since 'start' if GIT_TRACE_PERFORMANCE is enabled. */
41 __attribute__((format (printf, 2, 3)))
42 extern void trace_performance_since(uint64_t start, const char *format, ...);
44 #else
47 * Macros to add file:line - see above for C-style declarations of how these
48 * should be used.
52 * TRACE_CONTEXT may be set to __FUNCTION__ if the compiler supports it. The
53 * default is __FILE__, as it is consistent with assert(), and static function
54 * names are not necessarily unique.
56 * __FILE__ ":" __FUNCTION__ doesn't work with GNUC, as __FILE__ is supplied
57 * by the preprocessor as a string literal, and __FUNCTION__ is filled in by
58 * the compiler as a string constant.
60 #ifndef TRACE_CONTEXT
61 # define TRACE_CONTEXT __FILE__
62 #endif
65 * Note: with C99 variadic macros, __VA_ARGS__ must include the last fixed
66 * parameter ('format' in this case). Otherwise, a call without variable
67 * arguments will have a surplus ','. E.g.:
69 * #define foo(format, ...) bar(format, __VA_ARGS__)
70 * foo("test");
72 * will expand to
74 * bar("test",);
76 * which is invalid (note the ',)'). With GNUC, '##__VA_ARGS__' drops the
77 * comma, but this is non-standard.
80 #define trace_printf(...) \
81 trace_printf_key_fl(TRACE_CONTEXT, __LINE__, NULL, __VA_ARGS__)
83 #define trace_printf_key(key, ...) \
84 trace_printf_key_fl(TRACE_CONTEXT, __LINE__, key, __VA_ARGS__)
86 #define trace_argv_printf(argv, ...) \
87 trace_argv_printf_fl(TRACE_CONTEXT, __LINE__, argv, __VA_ARGS__)
89 #define trace_strbuf(key, data) \
90 trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data)
92 #define trace_performance(nanos, ...) \
93 trace_performance_fl(TRACE_CONTEXT, __LINE__, nanos, __VA_ARGS__)
95 #define trace_performance_since(start, ...) \
96 trace_performance_fl(TRACE_CONTEXT, __LINE__, getnanotime() - (start), \
97 __VA_ARGS__)
99 /* backend functions, use non-*fl macros instead */
100 __attribute__((format (printf, 4, 5)))
101 extern void trace_printf_key_fl(const char *file, int line, struct trace_key *key,
102 const char *format, ...);
103 __attribute__((format (printf, 4, 5)))
104 extern void trace_argv_printf_fl(const char *file, int line, const char **argv,
105 const char *format, ...);
106 extern void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
107 const struct strbuf *data);
108 __attribute__((format (printf, 4, 5)))
109 extern void trace_performance_fl(const char *file, int line,
110 uint64_t nanos, const char *fmt, ...);
112 #endif /* HAVE_VARIADIC_MACROS */
114 #endif /* TRACE_H */