perf tools: Add WARN_ONCE equivalent for UI warnings
authorJames Clark <james.clark@arm.com>
Thu, 29 Jul 2021 15:58:00 +0000 (16:58 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 3 Aug 2021 20:03:18 +0000 (17:03 -0300)
Currently WARN_ONCE prints to stderr and corrupts the TUI. Add
equivalent methods for UI warnings.

Signed-off-by: James Clark <james.clark@arm.com>
Reviewed-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lore.kernel.org/lkml/20210729155805.2830-2-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/debug.h

index 48f6319..f99468a 100644 (file)
@@ -22,6 +22,13 @@ extern int debug_data_convert;
        eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_warning(fmt, ...) \
        eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning_once(fmt, ...) ({           \
+       static int __warned;                    \
+       if (unlikely(!__warned)) {              \
+               pr_warning(fmt, ##__VA_ARGS__); \
+               __warned = 1;                   \
+       }                                       \
+})
 #define pr_info(fmt, ...) \
        eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_debug(fmt, ...) \
@@ -55,6 +62,13 @@ void trace_event(union perf_event *event);
 
 int ui__error(const char *format, ...) __printf(1, 2);
 int ui__warning(const char *format, ...) __printf(1, 2);
+#define ui__warning_once(format, ...) ({               \
+       static int __warned;                            \
+       if (unlikely(!__warned)) {                      \
+               ui__warning(format, ##__VA_ARGS__);     \
+               __warned = 1;                           \
+       }                                               \
+})
 
 void pr_stat(const char *fmt, ...);