[PATCH] perf trace: Avoid duplicate code in fprintf_duration()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
 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






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux