Subject: Re: [PATCH 02/14] trace2: create new combined trace facility

From: SZEDER Gábor <[email-masked]>
Date: Fri, 25 Jan 2019 12:22:03 +0100

On Tue, Jan 22, 2019 at 01:22:14PM -0800, Jeff Hostetler via GitGitGadget wrote:
> diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
> new file mode 100644
> index 0000000000..035855d883
> --- /dev/null
> +++ b/trace2/tr2_tgt_perf.c
> @@ -0,0 +1,573 @@

> +static struct strbuf dots = STRBUF_INIT;

> +static void perf_fmt_prepare(
> +	const char *event_name, struct tr2tls_thread_ctx *ctx,
> +	const char *file, int line, const struct repository *repo,
> +	uint64_t *p_us_elapsed_absolute, uint64_t *p_us_elapsed_relative,
> +	const char *category, struct strbuf *buf)
> +{
> +	int len;
> +
> +	strbuf_setlen(buf,0);
> +
> +	if (!tr2env_perf_brief) {
> +
> +		struct tr2_tbuf tb_now;
> +
> +		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)
> +			strbuf_addch(buf, ' ');
> +
> +		strbuf_addstr(buf, "| ");
> +	}
> +
> +	strbuf_addf(buf, "d%d | ", tr2_sid_depth());
> +	strbuf_addf(buf, "%-*s | %-*s | ",
> +		    TR2_MAX_THREAD_NAME, ctx->thread_name.buf,
> +		    TR2FMT_PERF_MAX_EVENT_NAME, event_name);
> +
> +	len = buf->len + TR2FMT_PERF_REPO_WIDTH;
> +	if (repo)
> +		strbuf_addf(buf, "r%d ", repo->trace2_repo_id);
> +	while (buf->len < len)
> +		strbuf_addch(buf, ' ' );
> +	strbuf_addstr(buf, "| ");
> +
> +	if (p_us_elapsed_absolute)
> +		strbuf_addf(buf, "%9.6f | ",
> +			    ((double)(*p_us_elapsed_absolute)) / 1000000.0);
> +	else
> +		strbuf_addf(buf, "%9s | ", " ");
> +
> +	if (p_us_elapsed_relative)
> +		strbuf_addf(buf, "%9.6f | ",
> +			    ((double)(*p_us_elapsed_relative)) / 1000000.0);
> +	else
> +		strbuf_addf(buf, "%9s | ", " ");
> +		
> +	strbuf_addf(buf, "%-*s | ", 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_addf(buf, "%s", dots.buf);

Please use the much simpler are more idiomatic strbuf_addbuf()
function instead.

> +			len_indent -= dots.len;
> +		}
> +		strbuf_addf(buf, "%.*s", len_indent, dots.buf);
> +	}
> +}

> +static void fn_version_fl(const char *file, int line)
> +{
> +	const char *event_name = "version";
> +	struct strbuf buf_payload = STRBUF_INIT;
> +
> +	strbuf_addf(&buf_payload, "%s", git_version_string);

strbuf_addstr()

> +
> +	perf_io_write_fl(file, line, event_name, NULL,
> +			 NULL, NULL, NULL,
> +			 &buf_payload);
> +	strbuf_release(&buf_payload);
> +}