Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf script: Make printing flags reliable

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>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20250304111240.3378214-2-leo.yan@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Leo Yan and committed by
Namhyung Kim
2b747a86 be9f3e95

+9 -2
+7 -2
tools/perf/builtin-script.c
··· 1709 1709 static int perf_sample__fprintf_flags(u32 flags, FILE *fp) 1710 1710 { 1711 1711 char str[SAMPLE_FLAGS_BUF_SIZE]; 1712 + int ret; 1712 1713 1713 - perf_sample__sprintf_flags(flags, str, sizeof(str)); 1714 - return fprintf(fp, " %-21s ", str); 1714 + ret = perf_sample__sprintf_flags(flags, str, sizeof(str)); 1715 + if (ret < 0) 1716 + return fprintf(fp, " raw flags:0x%-*x ", 1717 + SAMPLE_FLAGS_STR_ALIGNED_SIZE - 12, flags); 1718 + 1719 + return fprintf(fp, " %-*s ", SAMPLE_FLAGS_STR_ALIGNED_SIZE, str); 1715 1720 } 1716 1721 1717 1722 struct printer_data {
+2
tools/perf/util/trace-event.h
··· 145 145 int common_lock_depth(struct scripting_context *context); 146 146 147 147 #define SAMPLE_FLAGS_BUF_SIZE 64 148 + #define SAMPLE_FLAGS_STR_ALIGNED_SIZE 21 149 + 148 150 int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz); 149 151 150 152 #if defined(LIBTRACEEVENT_VERSION) && LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)