From: Markus Elfring <Markus.Elfring@web.de>
To: Christian Heusel <christian@heusel.eu>,
linux-perf-users@vger.kernel.org,
kernel-janitors@vger.kernel.org
Cc: 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: Fri, 19 Jul 2024 18:32:24 +0200 [thread overview]
Message-ID: <b3943cc3-234f-4789-a894-314a3890ac8e@web.de> (raw)
In-Reply-To: <c105871a-6462-4678-9f0c-b2ed5a254bb1@heusel.eu>
…
>> +++ 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?
Regards,
Markus
next prev parent reply other threads:[~2024-07-19 16:33 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 [this message]
2024-07-20 11:29 ` Christian Heusel
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=b3943cc3-234f-4789-a894-314a3890ac8e@web.de \
--to=markus.elfring@web.de \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=christian@heusel.eu \
--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).