blob: f99468a7f68170017f0fa9adc1862704bdbf3a71 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02002/* For debugging general purposes */
John Kacur8b40f522009-09-24 18:02:18 +02003#ifndef __PERF_DEBUG_H
4#define __PERF_DEBUG_H
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02005
Arnaldo Carvalho de Melob22bb132019-09-03 09:57:50 -03006#include <stdarg.h>
Ian Munsiec0555642010-04-13 18:37:33 +10007#include <stdbool.h>
Jiri Olsa8abceac2020-12-12 11:43:51 +01008#include <stdio.h>
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -03009#include <linux/compiler.h>
Arnaldo Carvalho de Melo8f411462009-11-16 16:32:42 -020010
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020011extern int verbose;
Ravi Bangoriaccd26742019-11-08 15:11:28 +053012extern int debug_peo_args;
Arnaldo Carvalho de Melob44308f2010-10-26 15:20:09 -020013extern bool quiet, dump_trace;
Jiri Olsacee3ab92014-07-11 14:49:54 +020014extern int debug_ordered_events;
Jiri Olsaedbe9812015-02-20 23:17:00 +010015extern int debug_data_convert;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020016
Jiri Olsa84f5d362014-07-14 23:46:48 +020017#ifndef pr_fmt
18#define pr_fmt(fmt) fmt
19#endif
20
21#define pr_err(fmt, ...) \
Jiri Olsac95688a2014-07-14 23:46:49 +020022 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
Jiri Olsa84f5d362014-07-14 23:46:48 +020023#define pr_warning(fmt, ...) \
Jiri Olsac95688a2014-07-14 23:46:49 +020024 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
James Clark1094795e2021-07-29 16:58:00 +010025#define pr_warning_once(fmt, ...) ({ \
26 static int __warned; \
27 if (unlikely(!__warned)) { \
28 pr_warning(fmt, ##__VA_ARGS__); \
29 __warned = 1; \
30 } \
31})
Jiri Olsa84f5d362014-07-14 23:46:48 +020032#define pr_info(fmt, ...) \
Jiri Olsac95688a2014-07-14 23:46:49 +020033 eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
Jiri Olsa84f5d362014-07-14 23:46:48 +020034#define pr_debug(fmt, ...) \
Jiri Olsac95688a2014-07-14 23:46:49 +020035 eprintf(1, verbose, pr_fmt(fmt), ##__VA_ARGS__)
Jiri Olsa84f5d362014-07-14 23:46:48 +020036#define pr_debugN(n, fmt, ...) \
Jiri Olsac95688a2014-07-14 23:46:49 +020037 eprintf(n, verbose, pr_fmt(fmt), ##__VA_ARGS__)
Jiri Olsa84f5d362014-07-14 23:46:48 +020038#define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
39#define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)
40#define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)
41
Ravi Bangoriaccd26742019-11-08 15:11:28 +053042/* Special macro to print perf_event_open arguments/return value. */
43#define pr_debug2_peo(fmt, ...) { \
44 if (debug_peo_args) \
45 pr_debugN(0, pr_fmt(fmt), ##__VA_ARGS__); \
46 else \
47 pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__); \
48}
49
Jiri Olsacee3ab92014-07-11 14:49:54 +020050#define pr_time_N(n, var, t, fmt, ...) \
51 eprintf_time(n, var, t, fmt, ##__VA_ARGS__)
52
53#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
54#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
55
Arnaldo Carvalho de Meloc8b5f2c2016-07-06 11:56:20 -030056#define STRERR_BUFSIZE 128 /* For the buffer size of str_error_r */
Masami Hiramatsub2348e12014-08-14 02:22:32 +000057
Arnaldo Carvalho de Melo8520a982019-08-29 16:18:59 -030058union perf_event;
59
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -030060int dump_printf(const char *fmt, ...) __printf(1, 2);
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020061void trace_event(union perf_event *event);
Arnaldo Carvalho de Melo567e5472010-03-12 21:05:10 -030062
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -030063int ui__error(const char *format, ...) __printf(1, 2);
64int ui__warning(const char *format, ...) __printf(1, 2);
James Clark1094795e2021-07-29 16:58:00 +010065#define ui__warning_once(format, ...) ({ \
66 static int __warned; \
67 if (unlikely(!__warned)) { \
68 ui__warning(format, ##__VA_ARGS__); \
69 __warned = 1; \
70 } \
71})
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020072
Jiri Olsaf772abc2013-12-03 14:09:25 +010073void pr_stat(const char *fmt, ...);
74
Arnaldo Carvalho de Meloafaed6d2017-06-16 11:57:54 -030075int eprintf(int level, int var, const char *fmt, ...) __printf(3, 4);
76int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __printf(4, 5);
Wang Nan0af08852015-07-31 10:35:33 -030077int veprintf(int level, int var, const char *fmt, va_list args);
Jiri Olsa84f5d362014-07-14 23:46:48 +020078
Jiri Olsabbb2cea2014-07-17 12:55:00 +020079int perf_debug_option(const char *str);
Jiri Olsa8abceac2020-12-12 11:43:51 +010080void debug_set_file(FILE *file);
Jiri Olsabcbd79d2021-01-02 23:04:22 +010081void debug_set_display_time(bool set);
Jiri Olsadd629cc2016-02-14 17:03:45 +010082void perf_debug_setup(void);
Namhyung Kim80df1982017-02-17 17:17:37 +090083int perf_quiet_option(void);
Jiri Olsabbb2cea2014-07-17 12:55:00 +020084
Arnaldo Carvalho de Melo8c2b7ca2017-04-19 16:21:59 -030085void dump_stack(void);
86void sighandler_dump_stack(int sig);
87
John Kacur8b40f522009-09-24 18:02:18 +020088#endif /* __PERF_DEBUG_H */