lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <fcc9ebe9-e4a0-4395-b3f0-8c6d5fba56f2@web.de>
Date: Fri, 19 Jul 2024 15:38:14 +0200
From: Markus Elfring <Markus.Elfring@....de>
To: linux-perf-users@...r.kernel.org, kernel-janitors@...r.kernel.org,
 Adrian Hunter <adrian.hunter@...el.com>,
 Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
 Arnaldo Carvalho de Melo <acme@...nel.org>, Ian Rogers <irogers@...gle.com>,
 Ingo Molnar <mingo@...hat.com>, Jiri Olsa <jolsa@...nel.org>,
 Kan Liang <kan.liang@...ux.intel.com>, Mark Rutland <mark.rutland@....com>,
 Namhyung Kim <namhyung@...nel.org>, Peter Zijlstra <peterz@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>, Julia Lawall <julia.lawall@...ia.fr>
Subject: [PATCH] perf: Optimise format string selections in three functions

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Fri, 19 Jul 2024 15:30:26 +0200

Adjust source code in three function implementations so that duplicate code
can be avoided for a few format string selections.

This issue was transformed by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 tools/perf/builtin-script.c | 29 +++++++++++++----------------
 tools/perf/ui/stdio/hist.c  | 11 +++--------
 2 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c16224b1fef3..ec6807f00c54 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -796,16 +796,16 @@ static int perf_sample__fprintf_start(struct perf_script *script,
 	if (PRINT_FIELD(VCPU) && sample->machine_pid)
 		printed += fprintf(fp, "VCPU:%03d ", sample->vcpu);

-	if (PRINT_FIELD(COMM)) {
-		const char *comm = thread ? thread__comm_str(thread) : ":-1";
-
-		if (latency_format)
-			printed += fprintf(fp, "%8.8s ", comm);
-		else if (PRINT_FIELD(IP) && evsel__has_callchain(evsel) && symbol_conf.use_callchain)
-			printed += fprintf(fp, "%s ", comm);
-		else
-			printed += fprintf(fp, "%16s ", comm);
-	}
+	if (PRINT_FIELD(COMM))
+		printed += fprintf(fp,
+				   (latency_format
+				   ? "%8.8s "
+				   : ((PRINT_FIELD(IP) &&
+				     evsel__has_callchain(evsel) &&
+				     symbol_conf.use_callchain)
+				     ? "%s "
+				     : "%16s ")),
+				   (thread ? thread__comm_str(thread) : ":-1"));

 	if (PRINT_FIELD(PID) && PRINT_FIELD(TID))
 		printed += fprintf(fp, "%7d/%-7d ", sample->pid, sample->tid);
@@ -814,12 +814,9 @@ static int perf_sample__fprintf_start(struct perf_script *script,
 	else if (PRINT_FIELD(TID))
 		printed += fprintf(fp, "%7d ", sample->tid);

-	if (PRINT_FIELD(CPU)) {
-		if (latency_format)
-			printed += fprintf(fp, "%3d ", sample->cpu);
-		else
-			printed += fprintf(fp, "[%03d] ", sample->cpu);
-	}
+	if (PRINT_FIELD(CPU))
+		printed += fprintf(fp, (latency_format ? "%3d " : "[%03d] "),
+				   sample->cpu);

 	if (PRINT_FIELD(MISC)) {
 		int ret = 0;
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 9372e8904d22..899019e8aab8 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -37,10 +37,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
 	size_t ret = callchain__fprintf_left_margin(fp, left_margin);

 	for (i = 0; i < depth; i++)
-		if (depth_mask & (1 << i))
-			ret += fprintf(fp, "|          ");
-		else
-			ret += fprintf(fp, "           ");
+		ret += fprintf(fp, ((depth_mask & (1 << i)) ? "|          " : "           "));

 	ret += fprintf(fp, "\n");

@@ -60,10 +57,8 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,

 	ret += callchain__fprintf_left_margin(fp, left_margin);
 	for (i = 0; i < depth; i++) {
-		if (depth_mask & (1 << i))
-			ret += fprintf(fp, "|");
-		else
-			ret += fprintf(fp, " ");
+		ret += fprintf(fp, ((depth_mask & (1 << i)) ? "|" : " "));
+
 		if (!period && i == depth - 1) {
 			ret += fprintf(fp, "--");
 			ret += callchain_node__fprintf_value(node, fp, total_samples);
--
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ