diff options
author | Vincent Ambo <mail@tazj.in> | 2020-11-21T18·20+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2020-11-21T18·45+0100 |
commit | f4609b896fac842433bd495c166d5987852a6a73 (patch) | |
tree | 95511c465c54c4f5d27e5d39ce187e2a1dd82bd3 /third_party/git/trace2/tr2_tgt_perf.c | |
parent | 082c006c04343a78d87b6c6ab3608c25d6213c3f (diff) |
merge(3p/git): Merge git subtree at v2.29.2 r/1890
This also bumps the stable nixpkgs to 20.09 as of 2020-11-21, because there is some breakage in the git build related to the netrc credentials helper which someone has taken care of in nixpkgs. The stable channel is not used for anything other than git, so this should be fine. Change-Id: I3575a19dab09e1e9556cf8231d717de9890484fb
Diffstat (limited to 'third_party/git/trace2/tr2_tgt_perf.c')
-rw-r--r-- | third_party/git/trace2/tr2_tgt_perf.c | 108 |
1 files changed, 62 insertions, 46 deletions
diff --git a/third_party/git/trace2/tr2_tgt_perf.c b/third_party/git/trace2/tr2_tgt_perf.c index ea0cbbe13ee0..a8018f18cc87 100644 --- a/third_party/git/trace2/tr2_tgt_perf.c +++ b/third_party/git/trace2/tr2_tgt_perf.c @@ -11,7 +11,7 @@ #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 }; +static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0, 0 }; /* * Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>" @@ -21,17 +21,14 @@ static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0 }; */ static int tr2env_perf_be_brief; -#define TR2FMT_PERF_FL_WIDTH (50) +#define TR2FMT_PERF_FL_WIDTH (28) #define TR2FMT_PERF_MAX_EVENT_NAME (12) -#define TR2FMT_PERF_REPO_WIDTH (4) -#define TR2FMT_PERF_CATEGORY_WIDTH (10) +#define TR2FMT_PERF_REPO_WIDTH (3) +#define TR2FMT_PERF_CATEGORY_WIDTH (12) -#define TR2_DOTS_BUFFER_SIZE (100) #define TR2_INDENT (2) #define TR2_INDENT_LENGTH(ctx) (((ctx)->nr_open_regions - 1) * TR2_INDENT) -static struct strbuf dots = STRBUF_INIT; - static int fn_init(void) { int want = tr2_dst_trace_want(&tr2dst_perf); @@ -41,8 +38,6 @@ static int fn_init(void) if (!want) return want; - strbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE); - brief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF); if (brief && *brief && ((want_brief = git_parse_maybe_bool(brief)) != -1)) @@ -54,8 +49,6 @@ static int fn_init(void) static void fn_term(void) { tr2_dst_trace_disable(&tr2dst_perf); - - strbuf_release(&dots); } /* @@ -79,17 +72,36 @@ static void perf_fmt_prepare(const char *event_name, if (!tr2env_perf_be_brief) { struct tr2_tbuf tb_now; + size_t fl_end_col; tr2_tbuf_local_time(&tb_now); strbuf_addstr(buf, tb_now.buf); strbuf_addch(buf, ' '); - if (file && *file) - strbuf_addf(buf, "%s:%d ", file, line); - while (buf->len < TR2FMT_PERF_FL_WIDTH) + fl_end_col = buf->len + TR2FMT_PERF_FL_WIDTH; + + if (file && *file) { + struct strbuf buf_fl = STRBUF_INIT; + + strbuf_addf(&buf_fl, "%s:%d", file, line); + + if (buf_fl.len <= TR2FMT_PERF_FL_WIDTH) + strbuf_addbuf(buf, &buf_fl); + else { + size_t avail = TR2FMT_PERF_FL_WIDTH - 3; + strbuf_addstr(buf, "..."); + strbuf_add(buf, + &buf_fl.buf[buf_fl.len - avail], + avail); + } + + strbuf_release(&buf_fl); + } + + while (buf->len < fl_end_col) strbuf_addch(buf, ' '); - strbuf_addstr(buf, "| "); + strbuf_addstr(buf, " | "); } strbuf_addf(buf, "d%d | ", tr2_sid_depth()); @@ -102,7 +114,7 @@ static void perf_fmt_prepare(const char *event_name, strbuf_addf(buf, "r%d ", repo->trace2_repo_id); while (buf->len < len) strbuf_addch(buf, ' '); - strbuf_addstr(buf, "| "); + strbuf_addstr(buf, " | "); if (p_us_elapsed_absolute) strbuf_addf(buf, "%9.6f | ", @@ -116,17 +128,11 @@ static void perf_fmt_prepare(const char *event_name, else strbuf_addf(buf, "%9s | ", " "); - strbuf_addf(buf, "%-*s | ", TR2FMT_PERF_CATEGORY_WIDTH, - (category ? category : "")); + strbuf_addf(buf, "%-*.*s | ", TR2FMT_PERF_CATEGORY_WIDTH, + TR2FMT_PERF_CATEGORY_WIDTH, (category ? category : "")); - if (ctx->nr_open_regions > 0) { - int len_indent = TR2_INDENT_LENGTH(ctx); - while (len_indent > dots.len) { - strbuf_addbuf(buf, &dots); - len_indent -= dots.len; - } - strbuf_addf(buf, "%.*s", len_indent, dots.buf); - } + if (ctx->nr_open_regions > 0) + strbuf_addchars(buf, '.', TR2_INDENT_LENGTH(ctx)); } static void perf_io_write_fl(const char *file, int line, const char *event_name, @@ -165,7 +171,7 @@ static void fn_start_fl(const char *file, int line, const char *event_name = "start"; struct strbuf buf_payload = STRBUF_INIT; - sq_quote_argv_pretty(&buf_payload, argv); + sq_append_quote_argv_pretty(&buf_payload, argv); perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute, NULL, NULL, &buf_payload); @@ -220,11 +226,6 @@ static void maybe_append_string_va(struct strbuf *buf, const char *fmt, va_end(copy_ap); return; } - - if (fmt && *fmt) { - strbuf_addstr(buf, fmt); - return; - } } static void fn_error_va_fl(const char *file, int line, const char *fmt, @@ -285,8 +286,9 @@ static void fn_alias_fl(const char *file, int line, const char *alias, const char *event_name = "alias"; struct strbuf buf_payload = STRBUF_INIT; - strbuf_addf(&buf_payload, "alias:%s argv:", alias); - sq_quote_argv_pretty(&buf_payload, argv); + strbuf_addf(&buf_payload, "alias:%s argv:[", alias); + sq_append_quote_argv_pretty(&buf_payload, argv); + strbuf_addch(&buf_payload, ']'); perf_io_write_fl(file, line, event_name, NULL, NULL, NULL, NULL, &buf_payload); @@ -315,10 +317,14 @@ static void fn_child_start_fl(const char *file, int line, sq_quote_buf_pretty(&buf_payload, cmd->dir); } - strbuf_addstr(&buf_payload, " argv:"); - if (cmd->git_cmd) - strbuf_addstr(&buf_payload, " git"); - sq_quote_argv_pretty(&buf_payload, cmd->argv); + strbuf_addstr(&buf_payload, " argv:["); + if (cmd->git_cmd) { + strbuf_addstr(&buf_payload, "git"); + if (cmd->argv[0]) + strbuf_addch(&buf_payload, ' '); + } + sq_append_quote_argv_pretty(&buf_payload, cmd->argv); + strbuf_addch(&buf_payload, ']'); perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute, NULL, NULL, &buf_payload); @@ -369,10 +375,14 @@ static void fn_exec_fl(const char *file, int line, uint64_t us_elapsed_absolute, struct strbuf buf_payload = STRBUF_INIT; strbuf_addf(&buf_payload, "id:%d ", exec_id); - strbuf_addstr(&buf_payload, "argv:"); - if (exe) - strbuf_addf(&buf_payload, " %s", exe); - sq_quote_argv_pretty(&buf_payload, argv); + strbuf_addstr(&buf_payload, "argv:["); + if (exe) { + strbuf_addstr(&buf_payload, exe); + if (argv[0]) + strbuf_addch(&buf_payload, ' '); + } + sq_append_quote_argv_pretty(&buf_payload, argv); + strbuf_addch(&buf_payload, ']'); perf_io_write_fl(file, line, event_name, NULL, &us_elapsed_absolute, NULL, NULL, &buf_payload); @@ -433,8 +443,11 @@ static void fn_region_enter_printf_va_fl(const char *file, int line, struct strbuf buf_payload = STRBUF_INIT; if (label) - strbuf_addf(&buf_payload, "label:%s ", label); - maybe_append_string_va(&buf_payload, fmt, ap); + strbuf_addf(&buf_payload, "label:%s", label); + if (fmt && *fmt) { + strbuf_addch(&buf_payload, ' '); + maybe_append_string_va(&buf_payload, fmt, ap); + } perf_io_write_fl(file, line, event_name, repo, &us_elapsed_absolute, NULL, category, &buf_payload); @@ -450,8 +463,11 @@ static void fn_region_leave_printf_va_fl( struct strbuf buf_payload = STRBUF_INIT; if (label) - strbuf_addf(&buf_payload, "label:%s ", label); - maybe_append_string_va(&buf_payload, fmt, ap); + strbuf_addf(&buf_payload, "label:%s", label); + if (fmt && *fmt) { + strbuf_addch(&buf_payload, ' ' ); + maybe_append_string_va(&buf_payload, fmt, ap); + } perf_io_write_fl(file, line, event_name, repo, &us_elapsed_absolute, &us_elapsed_region, category, &buf_payload); |