1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* For debugging general purposes */ 3 #ifndef __PERF_DEBUG_H 4 #define __PERF_DEBUG_H 5 6 #include <stdarg.h> 7 #include <stdbool.h> 8 #include <stdio.h> 9 #include <linux/compiler.h> 10 11 extern int verbose; 12 extern int debug_kmaps; 13 extern int debug_peo_args; 14 extern bool quiet, dump_trace; 15 extern int debug_ordered_events; 16 extern int debug_data_convert; 17 18 #ifndef pr_fmt 19 #define pr_fmt(fmt) fmt 20 #endif 21 22 #define pr_err(fmt, ...) \ 23 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) 24 #define pr_warning(fmt, ...) \ 25 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) 26 #define pr_warning_once(fmt, ...) ({ \ 27 static int __warned; \ 28 if (unlikely(!__warned)) { \ 29 pr_warning(fmt, ##__VA_ARGS__); \ 30 __warned = 1; \ 31 } \ 32 }) 33 #define pr_info(fmt, ...) \ 34 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) 35 #define pr_debug(fmt, ...) \ 36 eprintf(1, verbose, pr_fmt(fmt), ##__VA_ARGS__) 37 #define pr_debugN(n, fmt, ...) \ 38 eprintf(n, verbose, pr_fmt(fmt), ##__VA_ARGS__) 39 #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__) 40 #define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__) 41 #define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__) 42 43 /* Special macro to print perf_event_open arguments/return value. */ 44 #define pr_debug2_peo(fmt, ...) { \ 45 if (debug_peo_args) \ 46 pr_debugN(0, pr_fmt(fmt), ##__VA_ARGS__); \ 47 else \ 48 pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__); \ 49 } 50 51 #define pr_time_N(n, var, t, fmt, ...) \ 52 eprintf_time(n, var, t, fmt, ##__VA_ARGS__) 53 54 #define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 55 #define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__) 56 57 #define STRERR_BUFSIZE 128 /* For the buffer size of str_error_r */ 58 59 union perf_event; 60 61 int dump_printf(const char *fmt, ...) __printf(1, 2); 62 void trace_event(union perf_event *event); 63 64 int ui__error(const char *format, ...) __printf(1, 2); 65 int ui__warning(const char *format, ...) __printf(1, 2); 66 #define ui__warning_once(format, ...) ({ \ 67 static int __warned; \ 68 if (unlikely(!__warned)) { \ 69 ui__warning(format, ##__VA_ARGS__); \ 70 __warned = 1; \ 71 } \ 72 }) 73 74 void pr_stat(const char *fmt, ...); 75 76 int eprintf(int level, int var, const char *fmt, ...) __printf(3, 4); 77 int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __printf(4, 5); 78 int veprintf(int level, int var, const char *fmt, va_list args); 79 80 int perf_debug_option(const char *str); 81 FILE *debug_file(void); 82 void debug_set_file(FILE *file); 83 void debug_set_display_time(bool set); 84 void perf_debug_setup(void); 85 int perf_quiet_option(void); 86 87 void dump_stack(void); 88 void sighandler_dump_stack(int sig); 89 90 #endif /* __PERF_DEBUG_H */ 91