packfile.c: add repo_approximate_object_count()
[git.git] / trace2.h
blobae5020d0e66e08d86e0eb1398bce884c29de4487
1 #ifndef TRACE2_H
2 #define TRACE2_H
4 struct child_process;
5 struct repository;
6 struct json_writer;
8 /*
9 * The public TRACE2 routines are grouped into the following groups:
11 * [] trace2_initialize -- initialization.
12 * [] trace2_cmd_* -- emit command/control messages.
13 * [] trace2_child* -- emit child start/stop messages.
14 * [] trace2_exec* -- emit exec start/stop messages.
15 * [] trace2_thread* -- emit thread start/stop messages.
16 * [] trace2_def* -- emit definition/parameter mesasges.
17 * [] trace2_region* -- emit region nesting messages.
18 * [] trace2_data* -- emit region/thread/repo data messages.
19 * [] trace2_printf* -- legacy trace[1] messages.
23 * Initialize TRACE2 tracing facility if any of the builtin TRACE2
24 * targets are enabled in the environment. Emits a 'version' event.
26 * Cleanup/Termination is handled automatically by a registered
27 * atexit() routine.
29 void trace2_initialize_fl(const char *file, int line);
31 #define trace2_initialize() trace2_initialize_fl(__FILE__, __LINE__)
34 * Return true if trace2 is enabled.
36 int trace2_is_enabled(void);
39 * Emit a 'start' event with the original (unmodified) argv.
41 void trace2_cmd_start_fl(const char *file, int line, const char **argv);
43 #define trace2_cmd_start(argv) trace2_cmd_start_fl(__FILE__, __LINE__, (argv))
46 * Emit an 'exit' event.
48 * Write the exit-code that will be passed to exit() or returned
49 * from main().
51 * Use this prior to actually calling exit().
52 * See "#define exit()" in git-compat-util.h
54 int trace2_cmd_exit_fl(const char *file, int line, int code);
56 #define trace2_cmd_exit(code) (trace2_cmd_exit_fl(__FILE__, __LINE__, (code)))
59 * Emit an 'error' event.
61 * Write an error message to the TRACE2 targets.
63 void trace2_cmd_error_va_fl(const char *file, int line, const char *fmt,
64 va_list ap);
66 #define trace2_cmd_error_va(fmt, ap) \
67 trace2_cmd_error_va_fl(__FILE__, __LINE__, (fmt), (ap))
70 * Emit a 'pathname' event with the canonical pathname of the current process
71 * This gives post-processors a simple field to identify the command without
72 * having to parse the argv. For example, to distinguish invocations from
73 * installed versus debug executables.
75 void trace2_cmd_path_fl(const char *file, int line, const char *pathname);
77 #define trace2_cmd_path(p) trace2_cmd_path_fl(__FILE__, __LINE__, (p))
80 * Emit a 'cmd_name' event with the canonical name of the command.
81 * This gives post-processors a simple field to identify the command
82 * without having to parse the argv.
84 void trace2_cmd_name_fl(const char *file, int line, const char *name);
86 #define trace2_cmd_name(v) trace2_cmd_name_fl(__FILE__, __LINE__, (v))
89 * Emit a 'cmd_mode' event to further describe the command being run.
90 * For example, "checkout" can checkout a single file or can checkout a
91 * different branch. This gives post-processors a simple field to compare
92 * equivalent commands without having to parse the argv.
94 void trace2_cmd_mode_fl(const char *file, int line, const char *mode);
96 #define trace2_cmd_mode(sv) trace2_cmd_mode_fl(__FILE__, __LINE__, (sv))
99 * Emit an 'alias' expansion event.
101 void trace2_cmd_alias_fl(const char *file, int line, const char *alias,
102 const char **argv);
104 #define trace2_cmd_alias(alias, argv) \
105 trace2_cmd_alias_fl(__FILE__, __LINE__, (alias), (argv))
108 * Emit one or more 'def_param' events for "interesting" configuration
109 * settings.
111 * The environment variable "GIT_TR2_CONFIG_PARAMS" can be set to a
112 * list of patterns considered important. For example:
114 * GIT_TR2_CONFIG_PARAMS="core.*,remote.*.url"
116 * Note: this routine does a read-only iteration on the config data
117 * (using read_early_config()), so it must not be called until enough
118 * of the process environment has been established. This includes the
119 * location of the git and worktree directories, expansion of any "-c"
120 * and "-C" command line options, and etc.
122 void trace2_cmd_list_config_fl(const char *file, int line);
124 #define trace2_cmd_list_config() trace2_cmd_list_config_fl(__FILE__, __LINE__)
127 * Emit a "def_param" event for the given config key/value pair IF
128 * we consider the key to be "interesting".
130 * Use this for new/updated config settings created/updated after
131 * trace2_cmd_list_config() is called.
133 void trace2_cmd_set_config_fl(const char *file, int line, const char *key,
134 const char *value);
136 #define trace2_cmd_set_config(k, v) \
137 trace2_cmd_set_config_fl(__FILE__, __LINE__, (k), (v))
140 * Emit a 'child_start' event prior to spawning a child process.
142 * Before calling optionally set "cmd->trace2_child_class" to a string
143 * describing the type of the child process. For example, "editor" or
144 * "pager".
146 void trace2_child_start_fl(const char *file, int line,
147 struct child_process *cmd);
149 #define trace2_child_start(cmd) trace2_child_start_fl(__FILE__, __LINE__, (cmd))
152 * Emit a 'child_exit' event after the child process completes.
154 void trace2_child_exit_fl(const char *file, int line, struct child_process *cmd,
155 int child_exit_code);
157 #define trace2_child_exit(cmd, code) \
158 trace2_child_exit_fl(__FILE__, __LINE__, (cmd), (code))
161 * Emit an 'exec' event prior to calling one of exec(), execv(),
162 * execvp(), and etc. On Unix-derived systems, this will be the
163 * last event emitted for the current process, unless the exec
164 * fails. On Windows, exec() behaves like 'child_start' and a
165 * waitpid(), so additional events may be emitted.
167 * Returns the "exec_id".
169 int trace2_exec_fl(const char *file, int line, const char *exe,
170 const char **argv);
172 #define trace2_exec(exe, argv) trace2_exec_fl(__FILE__, __LINE__, (exe), (argv))
175 * Emit an 'exec_result' when possible. On Unix-derived systems,
176 * this should be called after exec() returns (which only happens
177 * when there is an error starting the new process). On Windows,
178 * this should be called after the waitpid().
180 * The "exec_id" should be the value returned from trace2_exec().
182 void trace2_exec_result_fl(const char *file, int line, int exec_id, int code);
184 #define trace2_exec_result(id, code) \
185 trace2_exec_result_fl(__FILE__, __LINE__, (id), (code))
188 * Emit a 'thread_start' event. This must be called from inside the
189 * thread-proc to set up the trace2 TLS data for the thread.
191 * Thread names should be descriptive, like "preload_index".
192 * Thread names will be decorated with an instance number automatically.
194 void trace2_thread_start_fl(const char *file, int line,
195 const char *thread_name);
197 #define trace2_thread_start(thread_name) \
198 trace2_thread_start_fl(__FILE__, __LINE__, (thread_name))
201 * Emit a 'thread_exit' event. This must be called from inside the
202 * thread-proc to report thread-specific data and cleanup TLS data
203 * for the thread.
205 void trace2_thread_exit_fl(const char *file, int line);
207 #define trace2_thread_exit() trace2_thread_exit_fl(__FILE__, __LINE__)
210 * Emit a 'param' event.
212 * Write a "<param> = <value>" pair describing some aspect of the
213 * run such as an important configuration setting or command line
214 * option that significantly changes command behavior.
216 void trace2_def_param_fl(const char *file, int line, const char *param,
217 const char *value);
219 #define trace2_def_param(param, value) \
220 trace2_def_param_fl(__FILE__, __LINE__, (param), (value))
223 * Tell trace2 about a newly instantiated repo object and assign
224 * a trace2-repo-id to be used in subsequent activity events.
226 * Emits a 'worktree' event for this repo instance.
228 void trace2_def_repo_fl(const char *file, int line, struct repository *repo);
230 #define trace2_def_repo(repo) trace2_def_repo_fl(__FILE__, __LINE__, repo)
233 * Emit a 'region_enter' event for <category>.<label> with optional
234 * repo-id and printf message.
236 * Enter a new nesting level on the current thread and remember the
237 * current time. This controls the indenting of all subsequent events
238 * on this thread.
240 void trace2_region_enter_fl(const char *file, int line, const char *category,
241 const char *label, const struct repository *repo);
243 #define trace2_region_enter(category, label, repo) \
244 trace2_region_enter_fl(__FILE__, __LINE__, (category), (label), (repo))
246 void trace2_region_enter_printf_va_fl(const char *file, int line,
247 const char *category, const char *label,
248 const struct repository *repo,
249 const char *fmt, va_list ap);
251 #define trace2_region_enter_printf_va(category, label, repo, fmt, ap) \
252 trace2_region_enter_printf_va_fl(__FILE__, __LINE__, (category), \
253 (label), (repo), (fmt), (ap))
255 void trace2_region_enter_printf_fl(const char *file, int line,
256 const char *category, const char *label,
257 const struct repository *repo,
258 const char *fmt, ...);
260 #ifdef HAVE_VARIADIC_MACROS
261 #define trace2_region_enter_printf(category, label, repo, ...) \
262 trace2_region_enter_printf_fl(__FILE__, __LINE__, (category), (label), \
263 (repo), __VA_ARGS__)
264 #else
265 /* clang-format off */
266 __attribute__((format (region_enter_printf, 4, 5)))
267 void trace2_region_enter_printf(const char *category, const char *label,
268 const struct repository *repo, const char *fmt,
269 ...);
270 /* clang-format on */
271 #endif
274 * Emit a 'region_leave' event for <category>.<label> with optional
275 * repo-id and printf message.
277 * Leave current nesting level and report the elapsed time spent
278 * in this nesting level.
280 void trace2_region_leave_fl(const char *file, int line, const char *category,
281 const char *label, const struct repository *repo);
283 #define trace2_region_leave(category, label, repo) \
284 trace2_region_leave_fl(__FILE__, __LINE__, (category), (label), (repo))
286 void trace2_region_leave_printf_va_fl(const char *file, int line,
287 const char *category, const char *label,
288 const struct repository *repo,
289 const char *fmt, va_list ap);
291 #define trace2_region_leave_printf_va(category, label, repo, fmt, ap) \
292 trace2_region_leave_printf_va_fl(__FILE__, __LINE__, (category), \
293 (label), (repo), (fmt), (ap))
295 void trace2_region_leave_printf_fl(const char *file, int line,
296 const char *category, const char *label,
297 const struct repository *repo,
298 const char *fmt, ...);
300 #ifdef HAVE_VARIADIC_MACROS
301 #define trace2_region_leave_printf(category, label, repo, ...) \
302 trace2_region_leave_printf_fl(__FILE__, __LINE__, (category), (label), \
303 (repo), __VA_ARGS__)
304 #else
305 /* clang-format off */
306 __attribute__((format (region_leave_printf, 4, 5)))
307 void trace2_region_leave_printf(const char *category, const char *label,
308 const struct repository *repo, const char *fmt,
309 ...);
310 /* clang-format on */
311 #endif
314 * Emit a key-value pair 'data' event of the form <category>.<key> = <value>.
315 * This event implicitly contains information about thread, nesting region,
316 * and optional repo-id.
318 * On event-based TRACE2 targets, this generates a 'data' event suitable
319 * for post-processing. On printf-based TRACE2 targets, this is converted
320 * into a fixed-format printf message.
322 void trace2_data_string_fl(const char *file, int line, const char *category,
323 const struct repository *repo, const char *key,
324 const char *value);
326 #define trace2_data_string(category, repo, key, value) \
327 trace2_data_string_fl(__FILE__, __LINE__, (category), (repo), (key), \
328 (value))
330 void trace2_data_intmax_fl(const char *file, int line, const char *category,
331 const struct repository *repo, const char *key,
332 intmax_t value);
334 #define trace2_data_intmax(category, repo, key, value) \
335 trace2_data_intmax_fl(__FILE__, __LINE__, (category), (repo), (key), \
336 (value))
338 void trace2_data_json_fl(const char *file, int line, const char *category,
339 const struct repository *repo, const char *key,
340 const struct json_writer *jw);
342 #define trace2_data_json(category, repo, key, value) \
343 trace2_data_json_fl(__FILE__, __LINE__, (category), (repo), (key), \
344 (value))
347 * Emit a 'printf' event.
349 * Write an arbitrary formatted message to the TRACE2 targets. These
350 * text messages should be considered as human-readable strings without
351 * any formatting guidelines. Post-processors may choose to ignore
352 * them.
354 void trace2_printf_va_fl(const char *file, int line, const char *fmt,
355 va_list ap);
357 #define trace2_printf_va(fmt, ap) \
358 trace2_printf_va_fl(__FILE__, __LINE__, (fmt), (ap))
360 void trace2_printf_fl(const char *file, int line, const char *fmt, ...);
362 #ifdef HAVE_VARIADIC_MACROS
363 #define trace2_printf(...) trace2_printf_fl(__FILE__, __LINE__, __VA_ARGS__)
364 #else
365 /* clang-format off */
366 __attribute__((format (printf, 1, 2)))
367 void trace2_printf(const char *fmt, ...);
368 /* clang-format on */
369 #endif
372 * Optional platform-specific code to dump information about the
373 * current and any parent process(es). This is intended to allow
374 * post-processors to know who spawned this git instance and anything
375 * else the platform may be able to tell us about the current process.
377 #if defined(GIT_WINDOWS_NATIVE)
378 void trace2_collect_process_info(void);
379 #else
380 #define trace2_collect_process_info() \
381 do { \
382 } while (0)
383 #endif
385 #endif /* TRACE2_H */