126
void trace_verbatim(struct trace_key *key, const void *buf, unsigned len);
127
uint64_t trace_performance_enter(void);
128
129
-#ifndef HAVE_VARIADIC_MACROS
130
-
131
-/**
132
- * Prints a formatted message, similar to printf.
133
- */
134
-__attribute__((format (printf, 1, 2)))
135
-void trace_printf(const char *format, ...);
136
-
137
-__attribute__((format (printf, 2, 3)))
138
-void trace_printf_key(struct trace_key *key, const char *format, ...);
139
-
140
-/**
141
- * Prints a formatted message, followed by a quoted list of arguments.
142
- */
143
-__attribute__((format (printf, 2, 3)))
144
-void trace_argv_printf(const char **argv, const char *format, ...);
145
-
146
-/**
147
- * Prints the strbuf, without additional formatting (i.e. doesn't
148
- * choke on `%` or even `\0`).
149
- */
150
-void trace_strbuf(struct trace_key *key, const struct strbuf *data);
151
-
152
-/**
153
- * Prints elapsed time (in nanoseconds) if GIT_TRACE_PERFORMANCE is enabled.
154
- *
155
- * Example:
156
- * ------------
157
- * uint64_t t = 0;
158
- * for (;;) {
159
- * // ignore
160
- * t -= getnanotime();
161
- * // code section to measure
162
- * t += getnanotime();
163
- * // ignore
164
- * }
165
- * trace_performance(t, "frotz");
166
- * ------------
167
- */
168
-__attribute__((format (printf, 2, 3)))
169
-void trace_performance(uint64_t nanos, const char *format, ...);
170
-
171
-/**
172
- * Prints elapsed time since 'start' if GIT_TRACE_PERFORMANCE is enabled.
173
- *
174
- * Example:
175
- * ------------
176
- * uint64_t start = getnanotime();
177
- * // code section to measure
178
- * trace_performance_since(start, "foobar");
179
- * ------------
180
- */
181
-__attribute__((format (printf, 2, 3)))
182
-void trace_performance_since(uint64_t start, const char *format, ...);
183
-
184
-__attribute__((format (printf, 1, 2)))
185
-void trace_performance_leave(const char *format, ...);
186
-
187
-#else
188
-
189
-/*
190
- * Macros to add file:line - see above for C-style declarations of how these
191
- * should be used.
192
- */
193
-
129
/*
130
* TRACE_CONTEXT may be set to __FUNCTION__ if the compiler supports it. The
131
* default is __FILE__, as it is consistent with assert(), and static function
139
# define TRACE_CONTEXT __FILE__
140
#endif
141
207
-/*
142
+/**
143
+ * Macros to add the file:line of the calling code, instead of that of
144
+ * the trace function itself.
145
+ *
146
* Note: with C99 variadic macros, __VA_ARGS__ must include the last fixed
147
* parameter ('format' in this case). Otherwise, a call without variable
148
* arguments will have a surplus ','. E.g.:
158
* comma, but this is non-standard.
159
*/
160
161
+/**
162
+ * trace_printf(), accepts "const char *format, ...".
163
+ *
164
+ * Prints a formatted message, similar to printf.
165
+ */
166
+#define trace_printf(...) trace_printf_key(&trace_default_key, __VA_ARGS__)
167
+
168
+/**
169
+ * trace_printf_key(), accepts "struct trace_key *key, const char *format, ...".
170
+ */
171
#define trace_printf_key(key, ...) \
172
do { \
173
if (trace_pass_fl(key)) \
175
__VA_ARGS__); \
176
} while (0)
177
230
-#define trace_printf(...) trace_printf_key(&trace_default_key, __VA_ARGS__)
231
-
178
+/**
179
+ * trace_argv_printf(), accepts "struct trace_key *key, const char *format, ...)".
180
+ *
181
+ * Prints a formatted message, followed by a quoted list of arguments.
182
+ */
183
#define trace_argv_printf(argv, ...) \
184
do { \
185
if (trace_pass_fl(&trace_default_key)) \
187
argv, __VA_ARGS__); \
188
} while (0)
189
190
+/**
191
+ * trace_strbuf(), accepts "struct trace_key *key, const struct strbuf *data".
192
+ *
193
+ * Prints the strbuf, without additional formatting (i.e. doesn't
194
+ * choke on `%` or even `\0`).
195
+ */
196
#define trace_strbuf(key, data) \
197
do { \
198
if (trace_pass_fl(key)) \
199
trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data);\
200
} while (0)
201
202
+/**
203
+ * trace_performance(), accepts "uint64_t nanos, const char *format, ...".
204
+ *
205
+ * Prints elapsed time (in nanoseconds) if GIT_TRACE_PERFORMANCE is enabled.
206
+ *
207
+ * Example:
208
+ * ------------
209
+ * uint64_t t = 0;
210
+ * for (;;) {
211
+ * // ignore
212
+ * t -= getnanotime();
213
+ * // code section to measure
214
+ * t += getnanotime();
215
+ * // ignore
216
+ * }
217
+ * trace_performance(t, "frotz");
218
+ * ------------
219
+ */
220
#define trace_performance(nanos, ...) \
221
do { \
222
if (trace_pass_fl(&trace_perf_key)) \
224
__VA_ARGS__); \
225
} while (0)
226
227
+/**
228
+ * trace_performance_since(), accepts "uint64_t start, const char *format, ...".
229
+ *
230
+ * Prints elapsed time since 'start' if GIT_TRACE_PERFORMANCE is enabled.
231
+ *
232
+ * Example:
233
+ * ------------
234
+ * uint64_t start = getnanotime();
235
+ * // code section to measure
236
+ * trace_performance_since(start, "foobar");
237
+ * ------------
238
+ */
239
#define trace_performance_since(start, ...) \
240
do { \
241
if (trace_pass_fl(&trace_perf_key)) \
244
__VA_ARGS__); \
245
} while (0)
246
247
+/**
248
+ * trace_performance_leave(), accepts "const char *format, ...".
249
+ */
250
#define trace_performance_leave(...) \
251
do { \
252
if (trace_pass_fl(&trace_perf_key)) \
275
return key->fd || !key->initialized;
276
}
277
288
-#endif /* HAVE_VARIADIC_MACROS */
289
-
278
#endif /* TRACE_H */