From: Markus Elfring <Markus.Elfring@web.de>
To: 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>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] perf trace: Avoid duplicate code in fprintf_duration()
Date: Fri, 19 Jul 2024 16:17:18 +0200 [thread overview]
Message-ID: <c564da16-062f-4da6-9021-c68f9c6eab63@web.de> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 19 Jul 2024 16:12:51 +0200
Adjust the colour selection so that a bit of duplicate code can be avoided
in this function implementation.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
tools/perf/builtin-trace.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 8449f2beb54d..e29ae5cb95b0 100644
--- a/tools/perf/builtin-trace.c
+++ 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);
+
return printed + fprintf(fp, "): ");
}
--
2.45.2
next reply other threads:[~2024-07-19 14:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 14:17 Markus Elfring [this message]
2024-07-19 15:41 ` [PATCH] perf trace: Avoid duplicate code in fprintf_duration() Christian Heusel
2024-07-19 16:32 ` Markus Elfring
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=c564da16-062f-4da6-9021-c68f9c6eab63@web.de \
--to=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).