{"thread":{"id":"52186","subject":"[PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()","startedAt":"2019-11-04T19:28:11Z","lastAt":"2019-11-05T15:10:11Z","messageCount":3,"participants":["René Scharfe","Jeff King","Jeff Hostetler"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"385415","messageId":"c4237b45-6faf-c1fc-eb13-b6c71b7fb6ef@web.de","threadId":"52186","inReplyTo":null,"subject":"[PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-11-04T19:27:54Z","receivedAt":"2019-11-04T19:28:11Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"The initialization function of the Trace2 performance format target sets\naside a stash of dots for indenting output.  Get rid of it and use\nstrbuf_addchars() to provide dots on demand instead.  This shortens the\ncode, gets rid of a small heap allocation and is a bit more efficient.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n trace2/tr2_tgt_perf.c | 17 ++---------------\n 1 file changed, 2 insertions(+), 15 deletions(-)\n\ndiff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c\nindex ffac8029ad..a8018f18cc 100644\n--- a/trace2/tr2_tgt_perf.c\n+++ b/trace2/tr2_tgt_perf.c\n@@ -26,12 +26,9 @@ static int tr2env_perf_be_brief;\n #define TR2FMT_PERF_REPO_WIDTH (3)\n #define TR2FMT_PERF_CATEGORY_WIDTH (12)\n\n-#define TR2_DOTS_BUFFER_SIZE (100)\n #define TR2_INDENT (2)\n #define TR2_INDENT_LENGTH(ctx) (((ctx)->nr_open_regions - 1) * TR2_INDENT)\n\n-static struct strbuf dots = STRBUF_INIT;\n-\n static int fn_init(void)\n {\n \tint want = tr2_dst_trace_want(&tr2dst_perf);\n@@ -41,8 +38,6 @@ static int fn_init(void)\n \tif (!want)\n \t\treturn want;\n\n-\tstrbuf_addchars(&dots, '.', TR2_DOTS_BUFFER_SIZE);\n-\n \tbrief = tr2_sysenv_get(TR2_SYSENV_PERF_BRIEF);\n \tif (brief && *brief &&\n \t    ((want_brief = git_parse_maybe_bool(brief)) != -1))\n@@ -54,8 +49,6 @@ static int fn_init(void)\n static void fn_term(void)\n {\n \ttr2_dst_trace_disable(&tr2dst_perf);\n-\n-\tstrbuf_release(&dots);\n }\n\n /*\n@@ -138,14 +131,8 @@ static void perf_fmt_prepare(const char *event_name,\n \tstrbuf_addf(buf, \"%-*.*s | \", TR2FMT_PERF_CATEGORY_WIDTH,\n \t\t    TR2FMT_PERF_CATEGORY_WIDTH, (category ? category : \"\"));\n\n-\tif (ctx->nr_open_regions > 0) {\n-\t\tint len_indent = TR2_INDENT_LENGTH(ctx);\n-\t\twhile (len_indent > dots.len) {\n-\t\t\tstrbuf_addbuf(buf, &dots);\n-\t\t\tlen_indent -= dots.len;\n-\t\t}\n-\t\tstrbuf_addf(buf, \"%.*s\", len_indent, dots.buf);\n-\t}\n+\tif (ctx->nr_open_regions > 0)\n+\t\tstrbuf_addchars(buf, '.', TR2_INDENT_LENGTH(ctx));\n }\n\n static void perf_io_write_fl(const char *file, int line, const char *event_name,\n--\n2.24.0\n"},{"id":"385417","messageId":"20191104195508.GB20900@sigill.intra.peff.net","threadId":"52186","inReplyTo":"c4237b45-6faf-c1fc-eb13-b6c71b7fb6ef@web.de","subject":"Re: [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-11-04T19:55:08Z","receivedAt":"2019-11-04T19:55:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 04, 2019 at 08:27:54PM +0100, René Scharfe wrote:\n\n> The initialization function of the Trace2 performance format target sets\n> aside a stash of dots for indenting output.  Get rid of it and use\n> strbuf_addchars() to provide dots on demand instead.  This shortens the\n> code, gets rid of a small heap allocation and is a bit more efficient.\n\nYeah, the end result is much easier on the eyes. I am scratching my head\nat whether there is any advantage to copying the separate buffer, but I\ndon't see one. The likelihood of having to allocate in the final \"buf\"\nstrbuf is the same either way.\n\n-Peff\n"},{"id":"385451","messageId":"0fae18b6-dd98-f7df-d2a9-cfdc34916686@jeffhostetler.com","threadId":"52186","inReplyTo":"c4237b45-6faf-c1fc-eb13-b6c71b7fb6ef@web.de","subject":"Re: [PATCH] trace2: add dots directly to strbuf in perf_fmt_prepare()","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2019-11-05T15:00:09Z","receivedAt":"2019-11-05T15:10:11Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 11/4/2019 2:27 PM, René Scharfe wrote:\n> The initialization function of the Trace2 performance format target sets\n> aside a stash of dots for indenting output.  Get rid of it and use\n> strbuf_addchars() to provide dots on demand instead.  This shortens the\n> code, gets rid of a small heap allocation and is a bit more efficient.\n> \n> Signed-off-by: René Scharfe <l.s.r@web.de>\n\nLooks good!\nThanks for simplifying my otherwise convoluted code.\nJeff\n\n"}]}