trace2: add dots directly to strbuf in perf_fmt_prepare()
The initialization function of the Trace2 performance format target sets aside a stash of dots for indenting output. Get rid of it and use strbuf_addchars() to provide dots on demand instead. This shortens the code, gets rid of a small heap allocation and is a bit more efficient. Signed-off-by: René Scharfe <l.s.r@web.de> Acked-by: Jeff King <peff@peff.net> Acked-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Nov 4, 2019 at 20:27 UTC
5c34d2f03e4a7505a6acb71b6a1be8d85d1cde05
1 file changed
+2
-15
trace2/tr2_tgt_perf.c
+2
-15
@@ -26,12 +26,9 @@ static int tr2env_perf_be_brief;
26
#define TR2FMT_PERF_REPO_WIDTH (3)
27
#define TR2FMT_PERF_CATEGORY_WIDTH (12)
28
29
-#define TR2_DOTS_BUFFER_SIZE (100)
29
#define TR2_INDENT (2)
30
#define TR2_INDENT_LENGTH(ctx) (((ctx)->nr_open_regions - 1) * TR2_INDENT)
31
33
-static struct strbuf dots = STRBUF_INIT;
34
-
32
static int fn_init(void)
33
{
34
int want = tr2_dst_trace_want(&tr2dst_perf);
@@ -41,8 +38,6 @@ static int fn_init(void)
38
if (!want)
39
return want;
40
44
- strbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);
45
-
41
brief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);
42
if (brief && *brief &&
43
((want_brief = git_parse_maybe_bool(brief)) != -1))
@@ -54,8 +49,6 @@ static int fn_init(void)
49
static void fn_term(void)
50
{
51
tr2_dst_trace_disable(&tr2dst_perf);
57
-
58
- strbuf_release(&dots);
52
}
53
54
/*
@@ -138,14 +131,8 @@ static void perf_fmt_prepare(const char *event_name,
131
strbuf_addf(buf, "%-*.*s | ", TR2FMT_PERF_CATEGORY_WIDTH,
132
TR2FMT_PERF_CATEGORY_WIDTH, (category ? category : ""));
133
141
- if (ctx->nr_open_regions > 0) {
142
- int len_indent = TR2_INDENT_LENGTH(ctx);
143
- while (len_indent > dots.len) {
144
- strbuf_addbuf(buf, &dots);
145
- len_indent -= dots.len;
146
- }
147
- strbuf_addf(buf, "%.*s", len_indent, dots.buf);
148
- }
134
+ if (ctx->nr_open_regions > 0)
135
+ strbuf_addchars(buf, '.', TR2_INDENT_LENGTH(ctx));
136
}
137
138
static void perf_io_write_fl(const char *file, int line, const char *event_name,