1 #include "git-compat-util.h"
3 #include "repository.h"
4 #include "run-command.h"
6 #include "thread-utils.h"
9 #include "trace2/tr2_cfg.h"
10 #include "trace2/tr2_cmd_name.h"
11 #include "trace2/tr2_ctr.h"
12 #include "trace2/tr2_dst.h"
13 #include "trace2/tr2_sid.h"
14 #include "trace2/tr2_sysenv.h"
15 #include "trace2/tr2_tgt.h"
16 #include "trace2/tr2_tls.h"
17 #include "trace2/tr2_tmr.h"
19 static int trace2_enabled
;
20 static int trace2_redact
= 1;
22 static int tr2_next_child_id
; /* modify under lock */
23 static int tr2_next_exec_id
; /* modify under lock */
24 static int tr2_next_repo_id
= 1; /* modify under lock. zero is reserved */
27 * A table of the builtin TRACE2 targets. Each of these may be independently
28 * enabled or disabled. Each TRACE2 API method will try to write an event to
29 * *each* of the enabled targets.
31 /* clang-format off */
32 static struct tr2_tgt
*tr2_tgt_builtins
[] =
41 /* clang-format off */
42 #define for_each_builtin(j, tgt_j) \
43 for (j = 0, tgt_j = tr2_tgt_builtins[j]; \
45 j++, tgt_j = tr2_tgt_builtins[j])
48 /* clang-format off */
49 #define for_each_wanted_builtin(j, tgt_j) \
50 for_each_builtin(j, tgt_j) \
51 if (tr2_dst_trace_want(tgt_j->pdst))
55 * Force (rather than lazily) initialize any of the requested
56 * builtin TRACE2 targets at startup (and before we've seen an
57 * actual TRACE2 event call) so we can see if we need to setup
58 * private data structures and thread-local storage.
60 * Return the number of builtin targets enabled.
62 static int tr2_tgt_want_builtins(void)
64 struct tr2_tgt
*tgt_j
;
68 for_each_builtin (j
, tgt_j
)
69 if (tgt_j
->pfn_init())
76 * Properly terminate each builtin target. Give each target
77 * a chance to write a summary event and/or flush if necessary
78 * and then close the fd.
80 static void tr2_tgt_disable_builtins(void)
82 struct tr2_tgt
*tgt_j
;
85 for_each_builtin (j
, tgt_j
)
90 * The signature of this function must match the pfn_timer
91 * method in the targets. (Think of this is an apply operation
92 * across the set of active targets.)
94 static void tr2_tgt_emit_a_timer(const struct tr2_timer_metadata
*meta
,
95 const struct tr2_timer
*timer
,
98 struct tr2_tgt
*tgt_j
;
101 for_each_wanted_builtin (j
, tgt_j
)
102 if (tgt_j
->pfn_timer
)
103 tgt_j
->pfn_timer(meta
, timer
, is_final_data
);
107 * The signature of this function must match the pfn_counter
108 * method in the targets.
110 static void tr2_tgt_emit_a_counter(const struct tr2_counter_metadata
*meta
,
111 const struct tr2_counter
*counter
,
114 struct tr2_tgt
*tgt_j
;
117 for_each_wanted_builtin (j
, tgt_j
)
118 if (tgt_j
->pfn_counter
)
119 tgt_j
->pfn_counter(meta
, counter
, is_final_data
);
122 static int tr2main_exit_code
;
125 * Our atexit routine should run after everything has finished.
127 * Note that events generated here might not actually appear if
128 * we are writing to fd 1 or 2 and our atexit routine runs after
129 * the pager's atexit routine (since it closes them to shutdown
132 static void tr2main_atexit_handler(void)
134 struct tr2_tgt
*tgt_j
;
137 uint64_t us_elapsed_absolute
;
139 us_now
= getnanotime() / 1000;
140 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
143 * Clear any unbalanced regions so that our atexit message
144 * does not appear nested. This improves the appearance of
145 * the trace output if someone calls die(), for example.
147 tr2tls_pop_unwind_self();
150 * Some timers want per-thread details. If the main thread
151 * used one of those timers, emit the details now (before
152 * we emit the aggregate timer values).
154 * Likewise for counters.
156 tr2_emit_per_thread_timers(tr2_tgt_emit_a_timer
);
157 tr2_emit_per_thread_counters(tr2_tgt_emit_a_counter
);
160 * Add stopwatch timer and counter data for the main thread to
161 * the final totals. And then emit the final values.
163 * Technically, we shouldn't need to hold the lock to update
164 * and output the final_timer_block and final_counter_block
165 * (since all other threads should be dead by now), but it
166 * doesn't hurt anything.
169 tr2_update_final_timers();
170 tr2_update_final_counters();
171 tr2_emit_final_timers(tr2_tgt_emit_a_timer
);
172 tr2_emit_final_counters(tr2_tgt_emit_a_counter
);
175 for_each_wanted_builtin (j
, tgt_j
)
176 if (tgt_j
->pfn_atexit
)
177 tgt_j
->pfn_atexit(us_elapsed_absolute
,
180 tr2_tgt_disable_builtins();
184 tr2_cmd_name_release();
185 tr2_cfg_free_patterns();
186 tr2_cfg_free_env_vars();
187 tr2_sysenv_release();
192 static void tr2main_signal_handler(int signo
)
194 struct tr2_tgt
*tgt_j
;
197 uint64_t us_elapsed_absolute
;
199 us_now
= getnanotime() / 1000;
200 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
202 for_each_wanted_builtin (j
, tgt_j
)
203 if (tgt_j
->pfn_signal
)
204 tgt_j
->pfn_signal(us_elapsed_absolute
, signo
);
210 void trace2_initialize_clock(void)
212 tr2tls_start_process_clock();
215 void trace2_initialize_fl(const char *file
, int line
)
217 struct tr2_tgt
*tgt_j
;
225 if (!tr2_tgt_want_builtins())
228 if (!git_env_bool("GIT_TRACE2_REDACT", 1))
233 atexit(tr2main_atexit_handler
);
234 sigchain_push(SIGPIPE
, tr2main_signal_handler
);
238 * Emit 'version' message on each active builtin target.
240 for_each_wanted_builtin (j
, tgt_j
)
241 if (tgt_j
->pfn_version_fl
)
242 tgt_j
->pfn_version_fl(file
, line
);
245 int trace2_is_enabled(void)
247 return trace2_enabled
;
251 * Redacts an argument, i.e. ensures that no password in
252 * https://user:password@host/-style URLs is logged.
254 * Returns the original if nothing needed to be redacted.
255 * Returns a pointer that needs to be `free()`d otherwise.
257 static const char *redact_arg(const char *arg
)
259 const char *p
, *colon
;
262 if (!trace2_redact
||
263 (!skip_prefix(arg
, "https://", &p
) &&
264 !skip_prefix(arg
, "http://", &p
)))
267 at
= strcspn(p
, "@/");
271 colon
= memchr(p
, ':', at
);
275 return xstrfmt("%.*s:<REDACTED>%s", (int)(colon
- arg
), arg
, p
+ at
);
279 * Redacts arguments in an argument list.
281 * Returns the original if nothing needed to be redacted.
282 * Otherwise, returns a new array that needs to be released
283 * via `free_redacted_argv()`.
285 static const char **redact_argv(const char **argv
)
288 const char *redacted
= NULL
;
294 for (i
= 0; argv
[i
]; i
++)
295 if ((redacted
= redact_arg(argv
[i
])) != argv
[i
])
301 for (j
= 0; argv
[j
]; j
++)
302 ; /* keep counting */
304 ALLOC_ARRAY(ret
, j
+ 1);
307 for (j
= 0; j
< i
; j
++)
310 for (++i
; argv
[i
]; i
++) {
311 redacted
= redact_arg(argv
[i
]);
312 ret
[i
] = redacted
? redacted
: argv
[i
];
318 static void free_redacted_argv(const char **redacted
, const char **argv
)
322 if (redacted
!= argv
) {
323 for (i
= 0; argv
[i
]; i
++)
324 if (redacted
[i
] != argv
[i
])
325 free((void *)redacted
[i
]);
326 free((void *)redacted
);
330 void trace2_cmd_start_fl(const char *file
, int line
, const char **argv
)
332 struct tr2_tgt
*tgt_j
;
335 uint64_t us_elapsed_absolute
;
336 const char **redacted
;
341 us_now
= getnanotime() / 1000;
342 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
344 redacted
= redact_argv(argv
);
346 for_each_wanted_builtin (j
, tgt_j
)
347 if (tgt_j
->pfn_start_fl
)
348 tgt_j
->pfn_start_fl(file
, line
, us_elapsed_absolute
,
351 free_redacted_argv(redacted
, argv
);
354 void trace2_cmd_exit_fl(const char *file
, int line
, int code
)
356 struct tr2_tgt
*tgt_j
;
359 uint64_t us_elapsed_absolute
;
364 trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT
);
366 tr2main_exit_code
= code
;
368 us_now
= getnanotime() / 1000;
369 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
371 for_each_wanted_builtin (j
, tgt_j
)
372 if (tgt_j
->pfn_exit_fl
)
373 tgt_j
->pfn_exit_fl(file
, line
, us_elapsed_absolute
,
377 void trace2_cmd_error_va_fl(const char *file
, int line
, const char *fmt
,
380 struct tr2_tgt
*tgt_j
;
387 * We expect each target function to treat 'ap' as constant
388 * and use va_copy (because an 'ap' can only be walked once).
390 for_each_wanted_builtin (j
, tgt_j
)
391 if (tgt_j
->pfn_error_va_fl
)
392 tgt_j
->pfn_error_va_fl(file
, line
, fmt
, ap
);
395 void trace2_cmd_path_fl(const char *file
, int line
, const char *pathname
)
397 struct tr2_tgt
*tgt_j
;
403 for_each_wanted_builtin (j
, tgt_j
)
404 if (tgt_j
->pfn_command_path_fl
)
405 tgt_j
->pfn_command_path_fl(file
, line
, pathname
);
408 void trace2_cmd_ancestry_fl(const char *file
, int line
, const char **parent_names
)
410 struct tr2_tgt
*tgt_j
;
416 for_each_wanted_builtin (j
, tgt_j
)
417 if (tgt_j
->pfn_command_ancestry_fl
)
418 tgt_j
->pfn_command_ancestry_fl(file
, line
, parent_names
);
421 void trace2_cmd_name_fl(const char *file
, int line
, const char *name
)
423 struct tr2_tgt
*tgt_j
;
424 const char *hierarchy
;
430 tr2_cmd_name_append_hierarchy(name
);
431 hierarchy
= tr2_cmd_name_get_hierarchy();
433 for_each_wanted_builtin (j
, tgt_j
)
434 if (tgt_j
->pfn_command_name_fl
)
435 tgt_j
->pfn_command_name_fl(file
, line
, name
, hierarchy
);
438 void trace2_cmd_mode_fl(const char *file
, int line
, const char *mode
)
440 struct tr2_tgt
*tgt_j
;
446 for_each_wanted_builtin (j
, tgt_j
)
447 if (tgt_j
->pfn_command_mode_fl
)
448 tgt_j
->pfn_command_mode_fl(file
, line
, mode
);
451 void trace2_cmd_alias_fl(const char *file
, int line
, const char *alias
,
454 struct tr2_tgt
*tgt_j
;
460 for_each_wanted_builtin (j
, tgt_j
)
461 if (tgt_j
->pfn_alias_fl
)
462 tgt_j
->pfn_alias_fl(file
, line
, alias
, argv
);
465 void trace2_cmd_list_config_fl(const char *file
, int line
)
467 static int emitted
= 0;
476 tr2_cfg_list_config_fl(file
, line
);
479 void trace2_cmd_list_env_vars_fl(const char *file
, int line
)
481 static int emitted
= 0;
490 tr2_list_env_vars_fl(file
, line
);
493 void trace2_cmd_set_config_fl(const char *file
, int line
, const char *key
,
499 tr2_cfg_set_fl(file
, line
, key
, value
);
502 void trace2_child_start_fl(const char *file
, int line
,
503 struct child_process
*cmd
)
505 struct tr2_tgt
*tgt_j
;
508 uint64_t us_elapsed_absolute
;
509 const char **orig_argv
= cmd
->args
.v
;
514 us_now
= getnanotime() / 1000;
515 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
517 cmd
->trace2_child_id
= tr2tls_locked_increment(&tr2_next_child_id
);
518 cmd
->trace2_child_us_start
= us_now
;
521 * The `pfn_child_start_fl` API takes a `struct child_process`
522 * rather than a simple `argv` for the child because some
523 * targets make use of the additional context bits/values. So
524 * temporarily replace the original argv (inside the `strvec`)
525 * with a possibly redacted version.
527 cmd
->args
.v
= redact_argv(orig_argv
);
529 for_each_wanted_builtin (j
, tgt_j
)
530 if (tgt_j
->pfn_child_start_fl
)
531 tgt_j
->pfn_child_start_fl(file
, line
,
532 us_elapsed_absolute
, cmd
);
534 if (cmd
->args
.v
!= orig_argv
) {
535 free_redacted_argv(cmd
->args
.v
, orig_argv
);
536 cmd
->args
.v
= orig_argv
;
540 void trace2_child_exit_fl(const char *file
, int line
, struct child_process
*cmd
,
543 struct tr2_tgt
*tgt_j
;
546 uint64_t us_elapsed_absolute
;
547 uint64_t us_elapsed_child
;
552 us_now
= getnanotime() / 1000;
553 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
555 if (cmd
->trace2_child_us_start
)
556 us_elapsed_child
= us_now
- cmd
->trace2_child_us_start
;
558 us_elapsed_child
= 0;
560 for_each_wanted_builtin (j
, tgt_j
)
561 if (tgt_j
->pfn_child_exit_fl
)
562 tgt_j
->pfn_child_exit_fl(file
, line
,
564 cmd
->trace2_child_id
, cmd
->pid
,
569 void trace2_child_ready_fl(const char *file
, int line
,
570 struct child_process
*cmd
,
573 struct tr2_tgt
*tgt_j
;
576 uint64_t us_elapsed_absolute
;
577 uint64_t us_elapsed_child
;
582 us_now
= getnanotime() / 1000;
583 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
585 if (cmd
->trace2_child_us_start
)
586 us_elapsed_child
= us_now
- cmd
->trace2_child_us_start
;
588 us_elapsed_child
= 0;
590 for_each_wanted_builtin (j
, tgt_j
)
591 if (tgt_j
->pfn_child_ready_fl
)
592 tgt_j
->pfn_child_ready_fl(file
, line
,
594 cmd
->trace2_child_id
,
600 int trace2_exec_fl(const char *file
, int line
, const char *exe
,
603 struct tr2_tgt
*tgt_j
;
607 uint64_t us_elapsed_absolute
;
608 const char **redacted
;
613 us_now
= getnanotime() / 1000;
614 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
616 exec_id
= tr2tls_locked_increment(&tr2_next_exec_id
);
618 redacted
= redact_argv(argv
);
620 for_each_wanted_builtin (j
, tgt_j
)
621 if (tgt_j
->pfn_exec_fl
)
622 tgt_j
->pfn_exec_fl(file
, line
, us_elapsed_absolute
,
623 exec_id
, exe
, redacted
);
625 free_redacted_argv(redacted
, argv
);
630 void trace2_exec_result_fl(const char *file
, int line
, int exec_id
, int code
)
632 struct tr2_tgt
*tgt_j
;
635 uint64_t us_elapsed_absolute
;
640 us_now
= getnanotime() / 1000;
641 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
643 for_each_wanted_builtin (j
, tgt_j
)
644 if (tgt_j
->pfn_exec_result_fl
)
645 tgt_j
->pfn_exec_result_fl(
646 file
, line
, us_elapsed_absolute
, exec_id
, code
);
649 void trace2_thread_start_fl(const char *file
, int line
, const char *thread_base_name
)
651 struct tr2_tgt
*tgt_j
;
654 uint64_t us_elapsed_absolute
;
659 if (tr2tls_is_main_thread()) {
661 * We should only be called from the new thread's thread-proc,
662 * so this is technically a bug. But in those cases where the
663 * main thread also runs the thread-proc function (or when we
664 * are built with threading disabled), we need to allow it.
666 * Convert this call to a region-enter so the nesting looks
669 trace2_region_enter_printf_fl(file
, line
, NULL
, NULL
, NULL
,
670 "thread-proc on main: %s",
675 us_now
= getnanotime() / 1000;
676 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
678 tr2tls_create_self(thread_base_name
, us_now
);
680 for_each_wanted_builtin (j
, tgt_j
)
681 if (tgt_j
->pfn_thread_start_fl
)
682 tgt_j
->pfn_thread_start_fl(file
, line
,
683 us_elapsed_absolute
);
686 void trace2_thread_exit_fl(const char *file
, int line
)
688 struct tr2_tgt
*tgt_j
;
691 uint64_t us_elapsed_absolute
;
692 uint64_t us_elapsed_thread
;
697 if (tr2tls_is_main_thread()) {
699 * We should only be called from the exiting thread's
700 * thread-proc, so this is technically a bug. But in
701 * those cases where the main thread also runs the
702 * thread-proc function (or when we are built with
703 * threading disabled), we need to allow it.
705 * Convert this call to a region-leave so the nesting
708 trace2_region_leave_printf_fl(file
, line
, NULL
, NULL
, NULL
,
709 "thread-proc on main");
713 us_now
= getnanotime() / 1000;
714 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
717 * Clear any unbalanced regions and then get the relative time
718 * for the outer-most region (which we pushed when the thread
719 * started). This gives us the run time of the thread.
721 tr2tls_pop_unwind_self();
722 us_elapsed_thread
= tr2tls_region_elasped_self(us_now
);
725 * Some timers want per-thread details. If this thread used
726 * one of those timers, emit the details now.
728 * Likewise for counters.
730 tr2_emit_per_thread_timers(tr2_tgt_emit_a_timer
);
731 tr2_emit_per_thread_counters(tr2_tgt_emit_a_counter
);
734 * Add stopwatch timer and counter data from the current
735 * (non-main) thread to the final totals. (We'll accumulate
736 * data for the main thread later during "atexit".)
739 tr2_update_final_timers();
740 tr2_update_final_counters();
743 for_each_wanted_builtin (j
, tgt_j
)
744 if (tgt_j
->pfn_thread_exit_fl
)
745 tgt_j
->pfn_thread_exit_fl(file
, line
,
752 void trace2_def_param_fl(const char *file
, int line
, const char *param
,
753 const char *value
, const struct key_value_info
*kvi
)
755 struct tr2_tgt
*tgt_j
;
757 const char *redacted
;
762 redacted
= redact_arg(value
);
764 for_each_wanted_builtin (j
, tgt_j
)
765 if (tgt_j
->pfn_param_fl
)
766 tgt_j
->pfn_param_fl(file
, line
, param
, redacted
, kvi
);
768 if (redacted
!= value
)
769 free((void *)redacted
);
772 void trace2_def_repo_fl(const char *file
, int line
, struct repository
*repo
)
774 struct tr2_tgt
*tgt_j
;
780 if (repo
->trace2_repo_id
)
783 repo
->trace2_repo_id
= tr2tls_locked_increment(&tr2_next_repo_id
);
785 for_each_wanted_builtin (j
, tgt_j
)
786 if (tgt_j
->pfn_repo_fl
)
787 tgt_j
->pfn_repo_fl(file
, line
, repo
);
790 void trace2_region_enter_printf_va_fl(const char *file
, int line
,
791 const char *category
, const char *label
,
792 const struct repository
*repo
,
793 const char *fmt
, va_list ap
)
795 struct tr2_tgt
*tgt_j
;
798 uint64_t us_elapsed_absolute
;
803 us_now
= getnanotime() / 1000;
804 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
807 * Print the region-enter message at the current nesting
808 * (indentation) level and then push a new level.
810 * We expect each target function to treat 'ap' as constant
813 for_each_wanted_builtin (j
, tgt_j
)
814 if (tgt_j
->pfn_region_enter_printf_va_fl
)
815 tgt_j
->pfn_region_enter_printf_va_fl(
816 file
, line
, us_elapsed_absolute
, category
,
817 label
, repo
, fmt
, ap
);
819 tr2tls_push_self(us_now
);
822 void trace2_region_enter_fl(const char *file
, int line
, const char *category
,
823 const char *label
, const struct repository
*repo
, ...)
827 trace2_region_enter_printf_va_fl(file
, line
, category
, label
, repo
,
833 void trace2_region_enter_printf_fl(const char *file
, int line
,
834 const char *category
, const char *label
,
835 const struct repository
*repo
,
836 const char *fmt
, ...)
841 trace2_region_enter_printf_va_fl(file
, line
, category
, label
, repo
, fmt
,
846 void trace2_region_leave_printf_va_fl(const char *file
, int line
,
847 const char *category
, const char *label
,
848 const struct repository
*repo
,
849 const char *fmt
, va_list ap
)
851 struct tr2_tgt
*tgt_j
;
854 uint64_t us_elapsed_absolute
;
855 uint64_t us_elapsed_region
;
860 us_now
= getnanotime() / 1000;
861 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
864 * Get the elapsed time in the current region before we
865 * pop it off the stack. Pop the stack. And then print
866 * the perf message at the new (shallower) level so that
867 * it lines up with the corresponding push/enter.
869 us_elapsed_region
= tr2tls_region_elasped_self(us_now
);
874 * We expect each target function to treat 'ap' as constant
877 for_each_wanted_builtin (j
, tgt_j
)
878 if (tgt_j
->pfn_region_leave_printf_va_fl
)
879 tgt_j
->pfn_region_leave_printf_va_fl(
880 file
, line
, us_elapsed_absolute
,
881 us_elapsed_region
, category
, label
, repo
, fmt
,
885 void trace2_region_leave_fl(const char *file
, int line
, const char *category
,
886 const char *label
, const struct repository
*repo
, ...)
890 trace2_region_leave_printf_va_fl(file
, line
, category
, label
, repo
,
895 void trace2_region_leave_printf_fl(const char *file
, int line
,
896 const char *category
, const char *label
,
897 const struct repository
*repo
,
898 const char *fmt
, ...)
903 trace2_region_leave_printf_va_fl(file
, line
, category
, label
, repo
, fmt
,
908 void trace2_data_string_fl(const char *file
, int line
, const char *category
,
909 const struct repository
*repo
, const char *key
,
912 struct tr2_tgt
*tgt_j
;
915 uint64_t us_elapsed_absolute
;
916 uint64_t us_elapsed_region
;
921 us_now
= getnanotime() / 1000;
922 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
923 us_elapsed_region
= tr2tls_region_elasped_self(us_now
);
925 for_each_wanted_builtin (j
, tgt_j
)
926 if (tgt_j
->pfn_data_fl
)
927 tgt_j
->pfn_data_fl(file
, line
, us_elapsed_absolute
,
928 us_elapsed_region
, category
, repo
,
932 void trace2_data_intmax_fl(const char *file
, int line
, const char *category
,
933 const struct repository
*repo
, const char *key
,
936 struct strbuf buf_string
= STRBUF_INIT
;
941 strbuf_addf(&buf_string
, "%" PRIdMAX
, value
);
942 trace2_data_string_fl(file
, line
, category
, repo
, key
, buf_string
.buf
);
943 strbuf_release(&buf_string
);
946 void trace2_data_json_fl(const char *file
, int line
, const char *category
,
947 const struct repository
*repo
, const char *key
,
948 const struct json_writer
*value
)
950 struct tr2_tgt
*tgt_j
;
953 uint64_t us_elapsed_absolute
;
954 uint64_t us_elapsed_region
;
959 us_now
= getnanotime() / 1000;
960 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
961 us_elapsed_region
= tr2tls_region_elasped_self(us_now
);
963 for_each_wanted_builtin (j
, tgt_j
)
964 if (tgt_j
->pfn_data_json_fl
)
965 tgt_j
->pfn_data_json_fl(file
, line
, us_elapsed_absolute
,
966 us_elapsed_region
, category
,
970 void trace2_printf_va_fl(const char *file
, int line
, const char *fmt
,
973 struct tr2_tgt
*tgt_j
;
976 uint64_t us_elapsed_absolute
;
981 us_now
= getnanotime() / 1000;
982 us_elapsed_absolute
= tr2tls_absolute_elapsed(us_now
);
985 * We expect each target function to treat 'ap' as constant
988 for_each_wanted_builtin (j
, tgt_j
)
989 if (tgt_j
->pfn_printf_va_fl
)
990 tgt_j
->pfn_printf_va_fl(file
, line
, us_elapsed_absolute
,
994 void trace2_printf_fl(const char *file
, int line
, const char *fmt
, ...)
999 trace2_printf_va_fl(file
, line
, fmt
, ap
);
1003 void trace2_timer_start(enum trace2_timer_id tid
)
1005 if (!trace2_enabled
)
1008 if (tid
< 0 || tid
>= TRACE2_NUMBER_OF_TIMERS
)
1009 BUG("trace2_timer_start: invalid timer id: %d", tid
);
1011 tr2_start_timer(tid
);
1014 void trace2_timer_stop(enum trace2_timer_id tid
)
1016 if (!trace2_enabled
)
1019 if (tid
< 0 || tid
>= TRACE2_NUMBER_OF_TIMERS
)
1020 BUG("trace2_timer_stop: invalid timer id: %d", tid
);
1022 tr2_stop_timer(tid
);
1025 void trace2_counter_add(enum trace2_counter_id cid
, uint64_t value
)
1027 if (!trace2_enabled
)
1030 if (cid
< 0 || cid
>= TRACE2_NUMBER_OF_COUNTERS
)
1031 BUG("trace2_counter_add: invalid counter id: %d", cid
);
1033 tr2_counter_increment(cid
, value
);
1036 const char *trace2_session_id(void)
1038 return tr2_sid_get();