* [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()
@ 2019-11-04 19:27 René Scharfe
2019-11-04 19:55 ` Jeff King
2019-11-05 15:00 ` Jeff Hostetler
0 siblings, 2 replies; 3+ messages in thread
From: René Scharfe @ 2019-11-04 19:27 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano, Jeff Hostetler
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>
---
trace2/tr2_tgt_perf.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c
index ffac8029ad..a8018f18cc 100644
--- a/trace2/tr2_tgt_perf.c
+++ b/trace2/tr2_tgt_perf.c
@@ -26,12 +26,9 @@ static int tr2env_perf_be_brief;
#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);
}
/*
@@ -138,14 +131,8 @@ static void perf_fmt_prepare(const char *event_name,
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,
--
2.24.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()
2019-11-04 19:27 [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare() René Scharfe
@ 2019-11-04 19:55 ` Jeff King
2019-11-05 15:00 ` Jeff Hostetler
1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2019-11-04 19:55 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano, Jeff Hostetler
On Mon, Nov 04, 2019 at 08:27:54PM +0100, René Scharfe wrote:
> 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.
Yeah, the end result is much easier on the eyes. I am scratching my head
at whether there is any advantage to copying the separate buffer, but I
don't see one. The likelihood of having to allocate in the final "buf"
strbuf is the same either way.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()
2019-11-04 19:27 [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare() René Scharfe
2019-11-04 19:55 ` Jeff King
@ 2019-11-05 15:00 ` Jeff Hostetler
1 sibling, 0 replies; 3+ messages in thread
From: Jeff Hostetler @ 2019-11-05 15:00 UTC (permalink / raw)
To: René Scharfe, Git Mailing List; +Cc: Junio C Hamano, Jeff Hostetler
On 11/4/2019 2:27 PM, René Scharfe wrote:
> 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>
Looks good!
Thanks for simplifying my otherwise convoluted code.
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-05 15:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 19:27 [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare() René Scharfe
2019-11-04 19:55 ` Jeff King
2019-11-05 15:00 ` Jeff Hostetler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).