File libperf-add-debug-output-support.patch of Package perf
xxxxxxxxxx
1
From: Jiri Olsa <jolsa@kernel.org>
2
Date: Sun, 21 Jul 2019 13:24:14 +0200
3
Subject: libperf: Add debug output support
4
Git-commit: a1556f8479ed58b8d5a33aef54578bad0165c7e7
5
Patch-mainline: v5.4-rc1
6
References: jsc#SLE-13661
7
8
Add the perf_set_print() function to allow setting an output function
9
for warn/info/debug messages.
10
11
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
12
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
13
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
14
Cc: Andi Kleen <ak@linux.intel.com>
15
Cc: Michael Petlan <mpetlan@redhat.com>
16
Cc: Namhyung Kim <namhyung@kernel.org>
17
Cc: Peter Zijlstra <peterz@infradead.org>
18
Link: http://lkml.kernel.org/r/20190721112506.12306-28-jolsa@kernel.org
19
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
20
Signed-off-by: Tony Jones <tonyj@suse.de>
21
---
22
tools/perf/lib/core.c | 34 ++++++++++++++++++++++++++++++++++
23
tools/perf/lib/include/perf/core.h | 13 +++++++++++++
24
tools/perf/lib/internal.h | 18 ++++++++++++++++++
25
tools/perf/lib/libperf.map | 2 ++
26
4 files changed, 67 insertions(+)
27
28
diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
29
index e69de29bb2d1..29d5e3348718 100644
30
--- a/tools/perf/lib/core.c
31
+++ b/tools/perf/lib/core.c
32
33
+// SPDX-License-Identifier: GPL-2.0-only
34
+
35
+#define __printf(a, b) __attribute__((format(printf, a, b)))
36
+
37
+#include <stdio.h>
38
+#include <stdarg.h>
39
+#include <perf/core.h>
40
+#include "internal.h"
41
+
42
+static int __base_pr(enum libperf_print_level level, const char *format,
43
+ va_list args)
44
+{
45
+ return vfprintf(stderr, format, args);
46
+}
47
+
48
+static libperf_print_fn_t __libperf_pr = __base_pr;
49
+
50
+void libperf_set_print(libperf_print_fn_t fn)
51
+{
52
+ __libperf_pr = fn;
53
+}
54
+
55
+__printf(2, 3)
56
+void libperf_print(enum libperf_print_level level, const char *format, ...)
57
+{
58
+ va_list args;
59
+
60
+ if (!__libperf_pr)
61
+ return;
62
+
63
+ va_start(args, format);
64
+ __libperf_pr(level, format, args);
65
+ va_end(args);
66
+}
67
diff --git a/tools/perf/lib/include/perf/core.h b/tools/perf/lib/include/perf/core.h
68
index e2e4b43c9131..c341a7b2c874 100644
69
--- a/tools/perf/lib/include/perf/core.h
70
+++ b/tools/perf/lib/include/perf/core.h
71
72
#ifndef __LIBPERF_CORE_H
73
#define __LIBPERF_CORE_H
74
75
+#include <stdarg.h>
76
+
77
#ifndef LIBPERF_API
78
#define LIBPERF_API __attribute__((visibility("default")))
79
#endif
80
81
+enum libperf_print_level {
82
+ LIBPERF_WARN,
83
+ LIBPERF_INFO,
84
+ LIBPERF_DEBUG,
85
+};
86
+
87
+typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
88
+ const char *, va_list ap);
89
+
90
+LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
91
+
92
#endif /* __LIBPERF_CORE_H */
93
diff --git a/tools/perf/lib/internal.h b/tools/perf/lib/internal.h
94
new file mode 100644
95
index 000000000000..dc92f241732e
96
--- /dev/null
97
+++ b/tools/perf/lib/internal.h
98
99
+/* SPDX-License-Identifier: GPL-2.0 */
100
+#ifndef __LIBPERF_INTERNAL_H
101
+#define __LIBPERF_INTERNAL_H
102
+
103
+void libperf_print(enum libperf_print_level level,
104
+ const char *format, ...)
105
+ __attribute__((format(printf, 2, 3)));
106
+
107
+#define __pr(level, fmt, ...) \
108
+do { \
109
+ libperf_print(level, "libperf: " fmt, ##__VA_ARGS__); \
110
+} while (0)
111
+
112
+#define pr_warning(fmt, ...) __pr(LIBPERF_WARN, fmt, ##__VA_ARGS__)
113
+#define pr_info(fmt, ...) __pr(LIBPERF_INFO, fmt, ##__VA_ARGS__)
114
+#define pr_debug(fmt, ...) __pr(LIBPERF_DEBUG, fmt, ##__VA_ARGS__)
115
+
116
+#endif /* __LIBPERF_INTERNAL_H */
117
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
118
index a8e913988edf..3536242c545c 100644
119
--- a/tools/perf/lib/libperf.map
120
+++ b/tools/perf/lib/libperf.map
121
122
LIBPERF_0.0.1 {
123
+ global:
124
+ libperf_set_print;
125
local:
126
*;
127
};
128
129