2023-02-24 03:09:23 +03:00
|
|
|
#include "git-compat-util.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
#include "config.h"
|
2023-04-22 23:17:20 +03:00
|
|
|
#include "repository.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
#include "run-command.h"
|
|
|
|
#include "sigchain.h"
|
|
|
|
#include "thread-utils.h"
|
2023-02-24 03:09:23 +03:00
|
|
|
#include "trace.h"
|
2023-04-11 06:00:38 +03:00
|
|
|
#include "trace2.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
#include "trace2/tr2_cfg.h"
|
|
|
|
#include "trace2/tr2_cmd_name.h"
|
2022-10-24 16:41:07 +03:00
|
|
|
#include "trace2/tr2_ctr.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
#include "trace2/tr2_dst.h"
|
|
|
|
#include "trace2/tr2_sid.h"
|
2019-04-15 23:39:47 +03:00
|
|
|
#include "trace2/tr2_sysenv.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
#include "trace2/tr2_tgt.h"
|
|
|
|
#include "trace2/tr2_tls.h"
|
2022-10-24 16:41:06 +03:00
|
|
|
#include "trace2/tr2_tmr.h"
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
static int trace2_enabled;
|
2023-11-22 22:18:35 +03:00
|
|
|
static int trace2_redact = 1;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
static int tr2_next_child_id; /* modify under lock */
|
|
|
|
static int tr2_next_exec_id; /* modify under lock */
|
|
|
|
static int tr2_next_repo_id = 1; /* modify under lock. zero is reserved */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A table of the builtin TRACE2 targets. Each of these may be independently
|
|
|
|
* enabled or disabled. Each TRACE2 API method will try to write an event to
|
|
|
|
* *each* of the enabled targets.
|
|
|
|
*/
|
|
|
|
/* clang-format off */
|
|
|
|
static struct tr2_tgt *tr2_tgt_builtins[] =
|
|
|
|
{
|
|
|
|
&tr2_tgt_normal,
|
|
|
|
&tr2_tgt_perf,
|
|
|
|
&tr2_tgt_event,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
#define for_each_builtin(j, tgt_j) \
|
|
|
|
for (j = 0, tgt_j = tr2_tgt_builtins[j]; \
|
|
|
|
tgt_j; \
|
|
|
|
j++, tgt_j = tr2_tgt_builtins[j])
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
#define for_each_wanted_builtin(j, tgt_j) \
|
|
|
|
for_each_builtin(j, tgt_j) \
|
|
|
|
if (tr2_dst_trace_want(tgt_j->pdst))
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force (rather than lazily) initialize any of the requested
|
|
|
|
* builtin TRACE2 targets at startup (and before we've seen an
|
|
|
|
* actual TRACE2 event call) so we can see if we need to setup
|
2022-10-24 16:41:01 +03:00
|
|
|
* private data structures and thread-local storage.
|
2019-02-23 01:25:01 +03:00
|
|
|
*
|
|
|
|
* Return the number of builtin targets enabled.
|
|
|
|
*/
|
|
|
|
static int tr2_tgt_want_builtins(void)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
int sum = 0;
|
|
|
|
|
|
|
|
for_each_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_init())
|
|
|
|
sum++;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Properly terminate each builtin target. Give each target
|
|
|
|
* a chance to write a summary event and/or flush if necessary
|
|
|
|
* and then close the fd.
|
|
|
|
*/
|
|
|
|
static void tr2_tgt_disable_builtins(void)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for_each_builtin (j, tgt_j)
|
|
|
|
tgt_j->pfn_term();
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:41:06 +03:00
|
|
|
/*
|
|
|
|
* The signature of this function must match the pfn_timer
|
|
|
|
* method in the targets. (Think of this is an apply operation
|
|
|
|
* across the set of active targets.)
|
|
|
|
*/
|
|
|
|
static void tr2_tgt_emit_a_timer(const struct tr2_timer_metadata *meta,
|
|
|
|
const struct tr2_timer *timer,
|
|
|
|
int is_final_data)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_timer)
|
|
|
|
tgt_j->pfn_timer(meta, timer, is_final_data);
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:41:07 +03:00
|
|
|
/*
|
|
|
|
* The signature of this function must match the pfn_counter
|
|
|
|
* method in the targets.
|
|
|
|
*/
|
|
|
|
static void tr2_tgt_emit_a_counter(const struct tr2_counter_metadata *meta,
|
|
|
|
const struct tr2_counter *counter,
|
|
|
|
int is_final_data)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_counter)
|
|
|
|
tgt_j->pfn_counter(meta, counter, is_final_data);
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
static int tr2main_exit_code;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our atexit routine should run after everything has finished.
|
|
|
|
*
|
|
|
|
* Note that events generated here might not actually appear if
|
|
|
|
* we are writing to fd 1 or 2 and our atexit routine runs after
|
|
|
|
* the pager's atexit routine (since it closes them to shutdown
|
|
|
|
* the pipes).
|
|
|
|
*/
|
|
|
|
static void tr2main_atexit_handler(void)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any unbalanced regions so that our atexit message
|
|
|
|
* does not appear nested. This improves the appearance of
|
|
|
|
* the trace output if someone calls die(), for example.
|
|
|
|
*/
|
|
|
|
tr2tls_pop_unwind_self();
|
|
|
|
|
2022-10-24 16:41:06 +03:00
|
|
|
/*
|
|
|
|
* Some timers want per-thread details. If the main thread
|
|
|
|
* used one of those timers, emit the details now (before
|
|
|
|
* we emit the aggregate timer values).
|
2022-10-24 16:41:07 +03:00
|
|
|
*
|
|
|
|
* Likewise for counters.
|
2022-10-24 16:41:06 +03:00
|
|
|
*/
|
|
|
|
tr2_emit_per_thread_timers(tr2_tgt_emit_a_timer);
|
2022-10-24 16:41:07 +03:00
|
|
|
tr2_emit_per_thread_counters(tr2_tgt_emit_a_counter);
|
2022-10-24 16:41:06 +03:00
|
|
|
|
|
|
|
/*
|
2022-10-24 16:41:07 +03:00
|
|
|
* Add stopwatch timer and counter data for the main thread to
|
|
|
|
* the final totals. And then emit the final values.
|
2022-10-24 16:41:06 +03:00
|
|
|
*
|
|
|
|
* Technically, we shouldn't need to hold the lock to update
|
2022-10-24 16:41:07 +03:00
|
|
|
* and output the final_timer_block and final_counter_block
|
|
|
|
* (since all other threads should be dead by now), but it
|
|
|
|
* doesn't hurt anything.
|
2022-10-24 16:41:06 +03:00
|
|
|
*/
|
|
|
|
tr2tls_lock();
|
|
|
|
tr2_update_final_timers();
|
2022-10-24 16:41:07 +03:00
|
|
|
tr2_update_final_counters();
|
2022-10-24 16:41:06 +03:00
|
|
|
tr2_emit_final_timers(tr2_tgt_emit_a_timer);
|
2022-10-24 16:41:07 +03:00
|
|
|
tr2_emit_final_counters(tr2_tgt_emit_a_counter);
|
2022-10-24 16:41:06 +03:00
|
|
|
tr2tls_unlock();
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_atexit)
|
|
|
|
tgt_j->pfn_atexit(us_elapsed_absolute,
|
|
|
|
tr2main_exit_code);
|
|
|
|
|
|
|
|
tr2_tgt_disable_builtins();
|
|
|
|
|
|
|
|
tr2tls_release();
|
|
|
|
tr2_sid_release();
|
|
|
|
tr2_cmd_name_release();
|
|
|
|
tr2_cfg_free_patterns();
|
2020-03-21 00:06:15 +03:00
|
|
|
tr2_cfg_free_env_vars();
|
2019-04-15 23:39:47 +03:00
|
|
|
tr2_sysenv_release();
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
trace2_enabled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tr2main_signal_handler(int signo)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_signal)
|
|
|
|
tgt_j->pfn_signal(us_elapsed_absolute, signo);
|
|
|
|
|
|
|
|
sigchain_pop(signo);
|
|
|
|
raise(signo);
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:39:43 +03:00
|
|
|
void trace2_initialize_clock(void)
|
|
|
|
{
|
|
|
|
tr2tls_start_process_clock();
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
void trace2_initialize_fl(const char *file, int line)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
2019-04-15 23:39:47 +03:00
|
|
|
tr2_sysenv_load();
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
if (!tr2_tgt_want_builtins())
|
|
|
|
return;
|
|
|
|
trace2_enabled = 1;
|
2023-11-22 22:18:35 +03:00
|
|
|
if (!git_env_bool("GIT_TRACE2_REDACT", 1))
|
|
|
|
trace2_redact = 0;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
tr2_sid_get();
|
|
|
|
|
|
|
|
atexit(tr2main_atexit_handler);
|
|
|
|
sigchain_push(SIGPIPE, tr2main_signal_handler);
|
|
|
|
tr2tls_init();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit 'version' message on each active builtin target.
|
|
|
|
*/
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_version_fl)
|
|
|
|
tgt_j->pfn_version_fl(file, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
int trace2_is_enabled(void)
|
|
|
|
{
|
|
|
|
return trace2_enabled;
|
|
|
|
}
|
|
|
|
|
2023-11-22 22:18:35 +03:00
|
|
|
/*
|
|
|
|
* Redacts an argument, i.e. ensures that no password in
|
|
|
|
* https://user:password@host/-style URLs is logged.
|
|
|
|
*
|
|
|
|
* Returns the original if nothing needed to be redacted.
|
|
|
|
* Returns a pointer that needs to be `free()`d otherwise.
|
|
|
|
*/
|
|
|
|
static const char *redact_arg(const char *arg)
|
|
|
|
{
|
|
|
|
const char *p, *colon;
|
|
|
|
size_t at;
|
|
|
|
|
|
|
|
if (!trace2_redact ||
|
|
|
|
(!skip_prefix(arg, "https://", &p) &&
|
|
|
|
!skip_prefix(arg, "http://", &p)))
|
|
|
|
return arg;
|
|
|
|
|
|
|
|
at = strcspn(p, "@/");
|
|
|
|
if (p[at] != '@')
|
|
|
|
return arg;
|
|
|
|
|
|
|
|
colon = memchr(p, ':', at);
|
|
|
|
if (!colon)
|
|
|
|
return arg;
|
|
|
|
|
|
|
|
return xstrfmt("%.*s:<REDACTED>%s", (int)(colon - arg), arg, p + at);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redacts arguments in an argument list.
|
|
|
|
*
|
|
|
|
* Returns the original if nothing needed to be redacted.
|
|
|
|
* Otherwise, returns a new array that needs to be released
|
|
|
|
* via `free_redacted_argv()`.
|
|
|
|
*/
|
|
|
|
static const char **redact_argv(const char **argv)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
const char *redacted = NULL;
|
|
|
|
const char **ret;
|
|
|
|
|
|
|
|
if (!trace2_redact)
|
|
|
|
return argv;
|
|
|
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
if ((redacted = redact_arg(argv[i])) != argv[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!argv[i])
|
|
|
|
return argv;
|
|
|
|
|
|
|
|
for (j = 0; argv[j]; j++)
|
|
|
|
; /* keep counting */
|
|
|
|
|
|
|
|
ALLOC_ARRAY(ret, j + 1);
|
|
|
|
ret[j] = NULL;
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
ret[j] = argv[j];
|
|
|
|
ret[i] = redacted;
|
|
|
|
for (++i; argv[i]; i++) {
|
|
|
|
redacted = redact_arg(argv[i]);
|
|
|
|
ret[i] = redacted ? redacted : argv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_redacted_argv(const char **redacted, const char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (redacted != argv) {
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
if (redacted[i] != argv[i])
|
|
|
|
free((void *)redacted[i]);
|
|
|
|
free((void *)redacted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
void trace2_cmd_start_fl(const char *file, int line, const char **argv)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
2019-04-15 23:39:44 +03:00
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
2023-11-22 22:18:35 +03:00
|
|
|
const char **redacted;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
2019-04-15 23:39:44 +03:00
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
2023-11-22 22:18:35 +03:00
|
|
|
redacted = redact_argv(argv);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_start_fl)
|
2019-04-15 23:39:44 +03:00
|
|
|
tgt_j->pfn_start_fl(file, line, us_elapsed_absolute,
|
2023-11-22 22:18:35 +03:00
|
|
|
redacted);
|
|
|
|
|
|
|
|
free_redacted_argv(redacted, argv);
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
2022-06-02 15:25:32 +03:00
|
|
|
void trace2_cmd_exit_fl(const char *file, int line, int code)
|
2019-02-23 01:25:01 +03:00
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
2022-06-02 15:25:32 +03:00
|
|
|
return;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
2019-04-15 23:39:48 +03:00
|
|
|
trace2_collect_process_info(TRACE2_PROCESS_INFO_EXIT);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
tr2main_exit_code = code;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_exit_fl)
|
|
|
|
tgt_j->pfn_exit_fl(file, line, us_elapsed_absolute,
|
|
|
|
code);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_cmd_error_va_fl(const char *file, int line, const char *fmt,
|
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We expect each target function to treat 'ap' as constant
|
|
|
|
* and use va_copy (because an 'ap' can only be walked once).
|
|
|
|
*/
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_error_va_fl)
|
|
|
|
tgt_j->pfn_error_va_fl(file, line, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_cmd_path_fl(const char *file, int line, const char *pathname)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_command_path_fl)
|
|
|
|
tgt_j->pfn_command_path_fl(file, line, pathname);
|
|
|
|
}
|
|
|
|
|
tr2: log parent process name
It can be useful to tell who invoked Git - was it invoked manually by a
user via CLI or script? By an IDE? In some cases - like 'repo' tool -
we can influence the source code and set the GIT_TRACE2_PARENT_SID
environment variable from the caller process. In 'repo''s case, that
parent SID is manipulated to include the string "repo", which means we
can positively identify when Git was invoked by 'repo' tool. However,
identifying parents that way requires both that we know which tools
invoke Git and that we have the ability to modify the source code of
those tools. It cannot scale to keep up with the various IDEs and
wrappers which use Git, most of which we don't know about. Learning
which tools and wrappers invoke Git, and how, would give us insight to
decide where to improve Git's usability and performance.
Unfortunately, there's no cross-platform reliable way to gather the name
of the parent process. If procfs is present, we can use that; otherwise
we will need to discover the name another way. However, the process ID
should be sufficient to look up the process name on most platforms, so
that code may be shareable.
Git for Windows gathers similar information and logs it as a "data_json"
event. However, since "data_json" has a variable format, it is difficult
to parse effectively in some languages; instead, let's pursue a
dedicated "cmd_ancestry" event to record information about the ancestry
of the current process and a consistent, parseable way.
Git for Windows also gathers information about more than one generation
of parent. In Linux further ancestry info can be gathered with procfs,
but it's unwieldy to do so. In the interest of later moving Git for
Windows ancestry logging to the 'cmd_ancestry' event, and in the
interest of later adding more ancestry to the Linux implementation - or
of adding this functionality to other platforms which have an easier
time walking the process tree - let's make 'cmd_ancestry' accept an
array of parentage.
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-22 04:27:07 +03:00
|
|
|
void trace2_cmd_ancestry_fl(const char *file, int line, const char **parent_names)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_command_ancestry_fl)
|
|
|
|
tgt_j->pfn_command_ancestry_fl(file, line, parent_names);
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
void trace2_cmd_name_fl(const char *file, int line, const char *name)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
const char *hierarchy;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tr2_cmd_name_append_hierarchy(name);
|
|
|
|
hierarchy = tr2_cmd_name_get_hierarchy();
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_command_name_fl)
|
|
|
|
tgt_j->pfn_command_name_fl(file, line, name, hierarchy);
|
2024-03-07 18:22:29 +03:00
|
|
|
|
|
|
|
trace2_cmd_list_config();
|
|
|
|
trace2_cmd_list_env_vars();
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_cmd_mode_fl(const char *file, int line, const char *mode)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_command_mode_fl)
|
|
|
|
tgt_j->pfn_command_mode_fl(file, line, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_cmd_alias_fl(const char *file, int line, const char *alias,
|
|
|
|
const char **argv)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_alias_fl)
|
|
|
|
tgt_j->pfn_alias_fl(file, line, alias, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_cmd_list_config_fl(const char *file, int line)
|
|
|
|
{
|
2024-03-07 18:22:28 +03:00
|
|
|
static int emitted = 0;
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
2024-03-07 18:22:28 +03:00
|
|
|
if (emitted)
|
|
|
|
return;
|
|
|
|
emitted = 1;
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
tr2_cfg_list_config_fl(file, line);
|
|
|
|
}
|
|
|
|
|
2020-03-21 00:06:15 +03:00
|
|
|
void trace2_cmd_list_env_vars_fl(const char *file, int line)
|
|
|
|
{
|
2024-03-07 18:22:28 +03:00
|
|
|
static int emitted = 0;
|
|
|
|
|
2020-03-21 00:06:15 +03:00
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
2024-03-07 18:22:28 +03:00
|
|
|
if (emitted)
|
|
|
|
return;
|
|
|
|
emitted = 1;
|
|
|
|
|
2020-03-21 00:06:15 +03:00
|
|
|
tr2_list_env_vars_fl(file, line);
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
void trace2_cmd_set_config_fl(const char *file, int line, const char *key,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tr2_cfg_set_fl(file, line, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_child_start_fl(const char *file, int line,
|
|
|
|
struct child_process *cmd)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
2023-11-22 22:18:35 +03:00
|
|
|
const char **orig_argv = cmd->args.v;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
cmd->trace2_child_id = tr2tls_locked_increment(&tr2_next_child_id);
|
|
|
|
cmd->trace2_child_us_start = us_now;
|
|
|
|
|
2023-11-22 22:18:35 +03:00
|
|
|
/*
|
|
|
|
* The `pfn_child_start_fl` API takes a `struct child_process`
|
|
|
|
* rather than a simple `argv` for the child because some
|
|
|
|
* targets make use of the additional context bits/values. So
|
|
|
|
* temporarily replace the original argv (inside the `strvec`)
|
|
|
|
* with a possibly redacted version.
|
|
|
|
*/
|
|
|
|
cmd->args.v = redact_argv(orig_argv);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_child_start_fl)
|
|
|
|
tgt_j->pfn_child_start_fl(file, line,
|
|
|
|
us_elapsed_absolute, cmd);
|
2023-11-22 22:18:35 +03:00
|
|
|
|
|
|
|
if (cmd->args.v != orig_argv) {
|
|
|
|
free_redacted_argv(cmd->args.v, orig_argv);
|
|
|
|
cmd->args.v = orig_argv;
|
|
|
|
}
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_child_exit_fl(const char *file, int line, struct child_process *cmd,
|
|
|
|
int child_exit_code)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_child;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
if (cmd->trace2_child_us_start)
|
|
|
|
us_elapsed_child = us_now - cmd->trace2_child_us_start;
|
|
|
|
else
|
|
|
|
us_elapsed_child = 0;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_child_exit_fl)
|
|
|
|
tgt_j->pfn_child_exit_fl(file, line,
|
|
|
|
us_elapsed_absolute,
|
|
|
|
cmd->trace2_child_id, cmd->pid,
|
|
|
|
child_exit_code,
|
|
|
|
us_elapsed_child);
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:36:12 +03:00
|
|
|
void trace2_child_ready_fl(const char *file, int line,
|
|
|
|
struct child_process *cmd,
|
|
|
|
const char *ready)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_child;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
if (cmd->trace2_child_us_start)
|
|
|
|
us_elapsed_child = us_now - cmd->trace2_child_us_start;
|
|
|
|
else
|
|
|
|
us_elapsed_child = 0;
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_child_ready_fl)
|
|
|
|
tgt_j->pfn_child_ready_fl(file, line,
|
|
|
|
us_elapsed_absolute,
|
|
|
|
cmd->trace2_child_id,
|
|
|
|
cmd->pid,
|
|
|
|
ready,
|
|
|
|
us_elapsed_child);
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
int trace2_exec_fl(const char *file, int line, const char *exe,
|
|
|
|
const char **argv)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
int exec_id;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
2023-11-22 22:18:35 +03:00
|
|
|
const char **redacted;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
exec_id = tr2tls_locked_increment(&tr2_next_exec_id);
|
|
|
|
|
2023-11-22 22:18:35 +03:00
|
|
|
redacted = redact_argv(argv);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_exec_fl)
|
|
|
|
tgt_j->pfn_exec_fl(file, line, us_elapsed_absolute,
|
2023-11-22 22:18:35 +03:00
|
|
|
exec_id, exe, redacted);
|
|
|
|
|
|
|
|
free_redacted_argv(redacted, argv);
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
return exec_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_exec_result_fl(const char *file, int line, int exec_id, int code)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_exec_result_fl)
|
|
|
|
tgt_j->pfn_exec_result_fl(
|
|
|
|
file, line, us_elapsed_absolute, exec_id, code);
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:41:03 +03:00
|
|
|
void trace2_thread_start_fl(const char *file, int line, const char *thread_base_name)
|
2019-02-23 01:25:01 +03:00
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tr2tls_is_main_thread()) {
|
|
|
|
/*
|
|
|
|
* We should only be called from the new thread's thread-proc,
|
|
|
|
* so this is technically a bug. But in those cases where the
|
|
|
|
* main thread also runs the thread-proc function (or when we
|
|
|
|
* are built with threading disabled), we need to allow it.
|
|
|
|
*
|
|
|
|
* Convert this call to a region-enter so the nesting looks
|
|
|
|
* correct.
|
|
|
|
*/
|
|
|
|
trace2_region_enter_printf_fl(file, line, NULL, NULL, NULL,
|
|
|
|
"thread-proc on main: %s",
|
2022-10-24 16:41:03 +03:00
|
|
|
thread_base_name);
|
2019-02-23 01:25:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
2022-10-24 16:41:03 +03:00
|
|
|
tr2tls_create_self(thread_base_name, us_now);
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_thread_start_fl)
|
|
|
|
tgt_j->pfn_thread_start_fl(file, line,
|
|
|
|
us_elapsed_absolute);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_thread_exit_fl(const char *file, int line)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_thread;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tr2tls_is_main_thread()) {
|
|
|
|
/*
|
|
|
|
* We should only be called from the exiting thread's
|
|
|
|
* thread-proc, so this is technically a bug. But in
|
|
|
|
* those cases where the main thread also runs the
|
|
|
|
* thread-proc function (or when we are built with
|
|
|
|
* threading disabled), we need to allow it.
|
|
|
|
*
|
|
|
|
* Convert this call to a region-leave so the nesting
|
|
|
|
* looks correct.
|
|
|
|
*/
|
|
|
|
trace2_region_leave_printf_fl(file, line, NULL, NULL, NULL,
|
|
|
|
"thread-proc on main");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any unbalanced regions and then get the relative time
|
|
|
|
* for the outer-most region (which we pushed when the thread
|
|
|
|
* started). This gives us the run time of the thread.
|
|
|
|
*/
|
|
|
|
tr2tls_pop_unwind_self();
|
|
|
|
us_elapsed_thread = tr2tls_region_elasped_self(us_now);
|
|
|
|
|
2022-10-24 16:41:06 +03:00
|
|
|
/*
|
|
|
|
* Some timers want per-thread details. If this thread used
|
|
|
|
* one of those timers, emit the details now.
|
2022-10-24 16:41:07 +03:00
|
|
|
*
|
|
|
|
* Likewise for counters.
|
2022-10-24 16:41:06 +03:00
|
|
|
*/
|
|
|
|
tr2_emit_per_thread_timers(tr2_tgt_emit_a_timer);
|
2022-10-24 16:41:07 +03:00
|
|
|
tr2_emit_per_thread_counters(tr2_tgt_emit_a_counter);
|
2022-10-24 16:41:06 +03:00
|
|
|
|
|
|
|
/*
|
2022-10-24 16:41:07 +03:00
|
|
|
* Add stopwatch timer and counter data from the current
|
|
|
|
* (non-main) thread to the final totals. (We'll accumulate
|
|
|
|
* data for the main thread later during "atexit".)
|
2022-10-24 16:41:06 +03:00
|
|
|
*/
|
|
|
|
tr2tls_lock();
|
|
|
|
tr2_update_final_timers();
|
2022-10-24 16:41:07 +03:00
|
|
|
tr2_update_final_counters();
|
2022-10-24 16:41:06 +03:00
|
|
|
tr2tls_unlock();
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_thread_exit_fl)
|
|
|
|
tgt_j->pfn_thread_exit_fl(file, line,
|
|
|
|
us_elapsed_absolute,
|
|
|
|
us_elapsed_thread);
|
|
|
|
|
|
|
|
tr2tls_unset_self();
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_def_param_fl(const char *file, int line, const char *param,
|
2023-06-28 22:26:26 +03:00
|
|
|
const char *value, const struct key_value_info *kvi)
|
2019-02-23 01:25:01 +03:00
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
2023-11-22 22:18:35 +03:00
|
|
|
const char *redacted;
|
2019-02-23 01:25:01 +03:00
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
2023-11-22 22:18:35 +03:00
|
|
|
redacted = redact_arg(value);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_param_fl)
|
2023-11-22 22:18:35 +03:00
|
|
|
tgt_j->pfn_param_fl(file, line, param, redacted, kvi);
|
|
|
|
|
|
|
|
if (redacted != value)
|
|
|
|
free((void *)redacted);
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_def_repo_fl(const char *file, int line, struct repository *repo)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (repo->trace2_repo_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
repo->trace2_repo_id = tr2tls_locked_increment(&tr2_next_repo_id);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_repo_fl)
|
|
|
|
tgt_j->pfn_repo_fl(file, line, repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_enter_printf_va_fl(const char *file, int line,
|
|
|
|
const char *category, const char *label,
|
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the region-enter message at the current nesting
|
|
|
|
* (indentation) level and then push a new level.
|
|
|
|
*
|
|
|
|
* We expect each target function to treat 'ap' as constant
|
|
|
|
* and use va_copy.
|
|
|
|
*/
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_region_enter_printf_va_fl)
|
|
|
|
tgt_j->pfn_region_enter_printf_va_fl(
|
|
|
|
file, line, us_elapsed_absolute, category,
|
|
|
|
label, repo, fmt, ap);
|
|
|
|
|
|
|
|
tr2tls_push_self(us_now);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_enter_fl(const char *file, int line, const char *category,
|
2019-03-19 20:13:46 +03:00
|
|
|
const char *label, const struct repository *repo, ...)
|
2019-02-23 01:25:01 +03:00
|
|
|
{
|
2019-03-19 20:13:46 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, repo);
|
2019-02-23 01:25:01 +03:00
|
|
|
trace2_region_enter_printf_va_fl(file, line, category, label, repo,
|
2019-03-19 20:13:46 +03:00
|
|
|
NULL, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_enter_printf_fl(const char *file, int line,
|
|
|
|
const char *category, const char *label,
|
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
trace2_region_enter_printf_va_fl(file, line, category, label, repo, fmt,
|
|
|
|
ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_leave_printf_va_fl(const char *file, int line,
|
|
|
|
const char *category, const char *label,
|
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_region;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the elapsed time in the current region before we
|
|
|
|
* pop it off the stack. Pop the stack. And then print
|
|
|
|
* the perf message at the new (shallower) level so that
|
|
|
|
* it lines up with the corresponding push/enter.
|
|
|
|
*/
|
|
|
|
us_elapsed_region = tr2tls_region_elasped_self(us_now);
|
|
|
|
|
|
|
|
tr2tls_pop_self();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We expect each target function to treat 'ap' as constant
|
|
|
|
* and use va_copy.
|
|
|
|
*/
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_region_leave_printf_va_fl)
|
|
|
|
tgt_j->pfn_region_leave_printf_va_fl(
|
|
|
|
file, line, us_elapsed_absolute,
|
|
|
|
us_elapsed_region, category, label, repo, fmt,
|
|
|
|
ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_leave_fl(const char *file, int line, const char *category,
|
2019-03-19 20:13:46 +03:00
|
|
|
const char *label, const struct repository *repo, ...)
|
2019-02-23 01:25:01 +03:00
|
|
|
{
|
2019-03-19 20:13:46 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, repo);
|
2019-02-23 01:25:01 +03:00
|
|
|
trace2_region_leave_printf_va_fl(file, line, category, label, repo,
|
2019-03-19 20:13:46 +03:00
|
|
|
NULL, ap);
|
|
|
|
va_end(ap);
|
2019-02-23 01:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_region_leave_printf_fl(const char *file, int line,
|
|
|
|
const char *category, const char *label,
|
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
trace2_region_leave_printf_va_fl(file, line, category, label, repo, fmt,
|
|
|
|
ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_data_string_fl(const char *file, int line, const char *category,
|
|
|
|
const struct repository *repo, const char *key,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_region;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
us_elapsed_region = tr2tls_region_elasped_self(us_now);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_data_fl)
|
|
|
|
tgt_j->pfn_data_fl(file, line, us_elapsed_absolute,
|
|
|
|
us_elapsed_region, category, repo,
|
|
|
|
key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_data_intmax_fl(const char *file, int line, const char *category,
|
|
|
|
const struct repository *repo, const char *key,
|
|
|
|
intmax_t value)
|
|
|
|
{
|
|
|
|
struct strbuf buf_string = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strbuf_addf(&buf_string, "%" PRIdMAX, value);
|
|
|
|
trace2_data_string_fl(file, line, category, repo, key, buf_string.buf);
|
|
|
|
strbuf_release(&buf_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_data_json_fl(const char *file, int line, const char *category,
|
|
|
|
const struct repository *repo, const char *key,
|
|
|
|
const struct json_writer *value)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
uint64_t us_elapsed_region;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
us_elapsed_region = tr2tls_region_elasped_self(us_now);
|
|
|
|
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
2019-04-25 20:08:53 +03:00
|
|
|
if (tgt_j->pfn_data_json_fl)
|
2019-02-23 01:25:01 +03:00
|
|
|
tgt_j->pfn_data_json_fl(file, line, us_elapsed_absolute,
|
|
|
|
us_elapsed_region, category,
|
|
|
|
repo, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_printf_va_fl(const char *file, int line, const char *fmt,
|
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
struct tr2_tgt *tgt_j;
|
|
|
|
int j;
|
|
|
|
uint64_t us_now;
|
|
|
|
uint64_t us_elapsed_absolute;
|
|
|
|
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
us_now = getnanotime() / 1000;
|
|
|
|
us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We expect each target function to treat 'ap' as constant
|
|
|
|
* and use va_copy.
|
|
|
|
*/
|
|
|
|
for_each_wanted_builtin (j, tgt_j)
|
|
|
|
if (tgt_j->pfn_printf_va_fl)
|
|
|
|
tgt_j->pfn_printf_va_fl(file, line, us_elapsed_absolute,
|
|
|
|
fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_printf_fl(const char *file, int line, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
trace2_printf_va_fl(file, line, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:41:06 +03:00
|
|
|
void trace2_timer_start(enum trace2_timer_id tid)
|
|
|
|
{
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tid < 0 || tid >= TRACE2_NUMBER_OF_TIMERS)
|
|
|
|
BUG("trace2_timer_start: invalid timer id: %d", tid);
|
|
|
|
|
|
|
|
tr2_start_timer(tid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void trace2_timer_stop(enum trace2_timer_id tid)
|
|
|
|
{
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tid < 0 || tid >= TRACE2_NUMBER_OF_TIMERS)
|
|
|
|
BUG("trace2_timer_stop: invalid timer id: %d", tid);
|
|
|
|
|
|
|
|
tr2_stop_timer(tid);
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:41:07 +03:00
|
|
|
void trace2_counter_add(enum trace2_counter_id cid, uint64_t value)
|
|
|
|
{
|
|
|
|
if (!trace2_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cid < 0 || cid >= TRACE2_NUMBER_OF_COUNTERS)
|
|
|
|
BUG("trace2_counter_add: invalid counter id: %d", cid);
|
|
|
|
|
|
|
|
tr2_counter_increment(cid, value);
|
|
|
|
}
|
|
|
|
|
2020-11-12 02:29:26 +03:00
|
|
|
const char *trace2_session_id(void)
|
|
|
|
{
|
|
|
|
return tr2_sid_get();
|
|
|
|
}
|