From: Christian Heusel <christian@heusel.eu>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: linux-perf-users@vger.kernel.org,
kernel-janitors@vger.kernel.org,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>, Ingo Molnar <mingo@redhat.com>,
Jiri Olsa <jolsa@kernel.org>,
Kan Liang <kan.liang@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>,
Namhyung Kim <namhyung@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] perf trace: Avoid duplicate code in fprintf_duration()
Date: Sat, 20 Jul 2024 13:29:56 +0200 [thread overview]
Message-ID: <b48460e2-c54d-4390-89e3-6835c379eb01@heusel.eu> (raw)
In-Reply-To: <b3943cc3-234f-4789-a894-314a3890ac8e@web.de>
[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]
On 24/07/19 06:32PM, Markus Elfring wrote:
> …
> >> +++ b/tools/perf/builtin-trace.c
> >> @@ -1258,12 +1258,16 @@ static size_t fprintf_duration(unsigned long t, bool calculated, FILE *fp)
> >>
> >> if (!calculated)
> >> printed += fprintf(fp, " ");
> >> - else if (duration >= 1.0)
> >> - printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration);
> >> - else if (duration >= 0.01)
> >> - printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration);
> >> else
> >> - printed += color_fprintf(fp, PERF_COLOR_NORMAL, "%6.3f ms", duration);
> >> + printed += color_fprintf(fp,
> >> + (duration >= 1.0
> >> + ? PERF_COLOR_RED
> >> + : (duration >= 0.01
> >> + ? PERF_COLOR_YELLOW
> >> + : PERF_COLOR_NORMAL)),
> >> + "%6.3f ms",
> >> + duration);
> >
> > Why is this a desirable change?
>
> I find it helpful to specify the affected function call only once
> in such an if branch.
>
>
> > Folding the if-statements into the
> > ternary operator makes the code quite unreadable compared to what it was
> > like before and doesn't give any obvious improvement.
>
> Do you prefer to store the result of the colour determination into another
> local variable so that it can be passed as a separate parameter?
No I think I prefer the current version of the code. But my judgement
does not matter much here, lets wait what the maintainers have to say
about this.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2024-07-20 11:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 14:17 [PATCH] perf trace: Avoid duplicate code in fprintf_duration() Markus Elfring
2024-07-19 15:41 ` Christian Heusel
2024-07-19 16:32 ` Markus Elfring
2024-07-20 11:29 ` Christian Heusel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b48460e2-c54d-4390-89e3-6835c379eb01@heusel.eu \
--to=christian@heusel.eu \
--cc=Markus.Elfring@web.de \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).