Merge branch 'es/trace2-log-parent-process-name'

trace2 logs learned to show parent process name to see in what
context Git was invoked.

* es/trace2-log-parent-process-name:
  tr2: log parent process name
  tr2: make process info collection platform-generic
This commit is contained in:
Junio C Hamano
2021-08-24 15:32:40 -07:00
14 changed files with 184 additions and 7 deletions

View File

@ -27,6 +27,8 @@ typedef void(tr2_tgt_evt_error_va_fl_t)(const char *file, int line,
typedef void(tr2_tgt_evt_command_path_fl_t)(const char *file, int line,
const char *command_path);
typedef void(tr2_tgt_evt_command_ancestry_fl_t)(const char *file, int line,
const char **parent_names);
typedef void(tr2_tgt_evt_command_name_fl_t)(const char *file, int line,
const char *name,
const char *hierarchy);
@ -108,6 +110,7 @@ struct tr2_tgt {
tr2_tgt_evt_atexit_t *pfn_atexit;
tr2_tgt_evt_error_va_fl_t *pfn_error_va_fl;
tr2_tgt_evt_command_path_fl_t *pfn_command_path_fl;
tr2_tgt_evt_command_ancestry_fl_t *pfn_command_ancestry_fl;
tr2_tgt_evt_command_name_fl_t *pfn_command_name_fl;
tr2_tgt_evt_command_mode_fl_t *pfn_command_mode_fl;
tr2_tgt_evt_alias_fl_t *pfn_alias_fl;

View File

@ -261,6 +261,26 @@ static void fn_command_path_fl(const char *file, int line, const char *pathname)
jw_release(&jw);
}
static void fn_command_ancestry_fl(const char *file, int line, const char **parent_names)
{
const char *event_name = "cmd_ancestry";
const char *parent_name = NULL;
struct json_writer jw = JSON_WRITER_INIT;
jw_object_begin(&jw, 0);
event_fmt_prepare(event_name, file, line, NULL, &jw);
jw_object_inline_begin_array(&jw, "ancestry");
while ((parent_name = *parent_names++))
jw_array_string(&jw, parent_name);
jw_end(&jw); /* 'ancestry' array */
jw_end(&jw); /* event object */
tr2_dst_write_line(&tr2dst_event, &jw.json);
jw_release(&jw);
}
static void fn_command_name_fl(const char *file, int line, const char *name,
const char *hierarchy)
{
@ -584,6 +604,7 @@ struct tr2_tgt tr2_tgt_event = {
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,

View File

@ -160,6 +160,24 @@ static void fn_command_path_fl(const char *file, int line, const char *pathname)
strbuf_release(&buf_payload);
}
static void fn_command_ancestry_fl(const char *file, int line, const char **parent_names)
{
const char *parent_name = NULL;
struct strbuf buf_payload = STRBUF_INIT;
/* cmd_ancestry parent <- grandparent <- great-grandparent */
strbuf_addstr(&buf_payload, "cmd_ancestry ");
while ((parent_name = *parent_names++)) {
strbuf_addstr(&buf_payload, parent_name);
/* if we'll write another one after this, add a delimiter */
if (parent_names && *parent_names)
strbuf_addstr(&buf_payload, " <- ");
}
normal_io_write_fl(file, line, &buf_payload);
strbuf_release(&buf_payload);
}
static void fn_command_name_fl(const char *file, int line, const char *name,
const char *hierarchy)
{
@ -306,6 +324,7 @@ struct tr2_tgt tr2_tgt_normal = {
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,

View File

@ -253,6 +253,21 @@ static void fn_command_path_fl(const char *file, int line, const char *pathname)
strbuf_release(&buf_payload);
}
static void fn_command_ancestry_fl(const char *file, int line, const char **parent_names)
{
const char *event_name = "cmd_ancestry";
struct strbuf buf_payload = STRBUF_INIT;
strbuf_addstr(&buf_payload, "ancestry:[");
/* It's not an argv but the rules are basically the same. */
sq_append_quote_argv_pretty(&buf_payload, parent_names);
strbuf_addch(&buf_payload, ']');
perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL,
&buf_payload);
strbuf_release(&buf_payload);
}
static void fn_command_name_fl(const char *file, int line, const char *name,
const char *hierarchy)
{
@ -532,6 +547,7 @@ struct tr2_tgt tr2_tgt_perf = {
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,