* [PATCH] perf: Optimise format string selections in three functions
@ 2024-07-19 13:38 Markus Elfring
0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2024-07-19 13:38 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, Julia Lawall
From: Markus Elfring <elfring@users.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@users.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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-07-19 13:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-19 13:38 [PATCH] perf: Optimise format string selections in three functions Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®