linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf trace: Avoid duplicate code in fprintf_duration()
@ 2024-07-19 14:17 Markus Elfring
  2024-07-19 15:41 ` Christian Heusel
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-07-19 14:17 UTC (permalink / raw)
  To: linux-perf-users, kernel-janitors, Adrian Hunter,
	Alexander Shishkin, Arnaldo Carvalho de Melo, Ian Rogers,
	Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland, Namhyung Kim,
	Peter Zijlstra
  Cc: LKML

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-20 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).