mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	James Clark <james.clark@linaro.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	"Liang, Kan" <kan.liang@linux.intel.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Will Deacon <will@kernel.org>, Mike Leach <mike.leach@linaro.org>,
	Graham Woodward <graham.woodward@arm.com>,
	Paschalis.Mpeis@arm.com, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Leo Yan <leo.yan@arm.com>
Subject: [PATCH v4 01/12] perf script: Make printing flags reliable
Date: Tue,  4 Mar 2025 11:12:29 +0000	[thread overview]
Message-ID: <20250304111240.3378214-2-leo.yan@arm.com> (raw)
In-Reply-To: <20250304111240.3378214-1-leo.yan@arm.com>

Add a check for the generated string of flags.  Print out the raw number
if the string generation fails.

Use the SAMPLE_FLAGS_STR_ALIGNED_SIZE macro to replace the value '21'.

Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/builtin-script.c   | 9 +++++++--
 tools/perf/util/trace-event.h | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d797cec4f054..8ca04293d335 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1709,9 +1709,14 @@ static int perf_sample__fprintf_bts(struct perf_sample *sample,
 static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
 {
 	char str[SAMPLE_FLAGS_BUF_SIZE];
+	int ret;
+
+	ret = perf_sample__sprintf_flags(flags, str, sizeof(str));
+	if (ret < 0)
+		return fprintf(fp, "  raw flags:0x%-*x ",
+			       SAMPLE_FLAGS_STR_ALIGNED_SIZE - 12, flags);
 
-	perf_sample__sprintf_flags(flags, str, sizeof(str));
-	return fprintf(fp, "  %-21s ", str);
+	return fprintf(fp, "  %-*s ", SAMPLE_FLAGS_STR_ALIGNED_SIZE, str);
 }
 
 struct printer_data {
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index ac9fde2f980c..71e680bc3d4b 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -145,6 +145,8 @@ int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
 
 #define SAMPLE_FLAGS_BUF_SIZE 64
+#define SAMPLE_FLAGS_STR_ALIGNED_SIZE	21
+
 int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz);
 
 #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
-- 
2.34.1


  reply	other threads:[~2025-03-04 11:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 11:12 [PATCH v4 00/12] perf script: Refactor branch flags for Arm SPE Leo Yan
2025-03-04 11:12 ` Leo Yan [this message]
2025-03-04 15:21   ` [PATCH v4 01/12] perf script: Make printing flags reliable Adrian Hunter
2025-03-04 11:12 ` [PATCH v4 02/12] perf script: Refactor sample_flags_to_name() function Leo Yan
2025-03-04 11:12 ` [PATCH v4 03/12] perf script: Separate events from branch types Leo Yan
2025-03-04 11:12 ` [PATCH v4 04/12] perf script: Add not taken event for branches Leo Yan
2025-03-04 11:12 ` [PATCH v4 05/12] perf script: Add not taken event for branch stack Leo Yan
2025-03-04 11:12 ` [PATCH v4 06/12] perf arm-spe: Fix load-store operation checking Leo Yan
2025-03-04 11:12 ` [PATCH v4 07/12] perf arm-spe: Extend branch operations Leo Yan
2025-03-04 11:12 ` [PATCH v4 08/12] perf arm-spe: Decode transactional event Leo Yan
2025-03-04 11:12 ` [PATCH v4 09/12] perf arm-spe: Fill branch operations and events to record Leo Yan
2025-03-04 11:12 ` [PATCH v4 10/12] perf arm-spe: Set sample flags with supplement info Leo Yan
2025-03-04 11:12 ` [PATCH v4 11/12] perf arm-spe: Add branch stack Leo Yan
2025-03-04 11:12 ` [PATCH v4 12/12] perf arm-spe: Support previous branch target (PBT) address Leo Yan
2025-03-05 17:14 ` [PATCH v4 00/12] perf script: Refactor branch flags for Arm SPE Namhyung Kim

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=20250304111240.3378214-2-leo.yan@arm.com \
    --to=leo.yan@arm.com \
    --cc=Paschalis.Mpeis@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=graham.woodward@arm.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mike.leach@linaro.org \
    --cc=namhyung@kernel.org \
    --cc=will@kernel.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

all inboxes | Powered by JetHome®