xref: /openbmc/linux/tools/perf/trace/beauty/beauty.h (revision 99a15348)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_TRACE_BEAUTY_H
3 #define _PERF_TRACE_BEAUTY_H
4 
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <sys/types.h>
8 #include <stdbool.h>
9 
10 struct strarray {
11 	u64	    offset;
12 	int	    nr_entries;
13 	const char *prefix;
14 	const char **entries;
15 };
16 
17 #define DEFINE_STRARRAY(array, _prefix) struct strarray strarray__##array = { \
18 	.nr_entries = ARRAY_SIZE(array), \
19 	.entries = array, \
20 	.prefix = _prefix, \
21 }
22 
23 #define DEFINE_STRARRAY_OFFSET(array, _prefix, off) struct strarray strarray__##array = { \
24 	.offset	    = off, \
25 	.nr_entries = ARRAY_SIZE(array), \
26 	.entries = array, \
27 	.prefix = _prefix, \
28 }
29 
30 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
31 size_t strarray__scnprintf_suffix(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_suffix, int val);
32 size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags);
33 
34 bool strarray__strtoul(struct strarray *sa, char *bf, size_t size, u64 *ret);
35 bool strarray__strtoul_flags(struct strarray *sa, char *bf, size_t size, u64 *ret);
36 
37 struct trace;
38 struct thread;
39 
40 struct file {
41 	char *pathname;
42 	int  dev_maj;
43 };
44 
45 struct file *thread__files_entry(struct thread *thread, int fd);
46 
47 struct strarrays {
48 	int		nr_entries;
49 	struct strarray **entries;
50 };
51 
52 #define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \
53 	.nr_entries = ARRAY_SIZE(array), \
54 	.entries = array, \
55 }
56 
57 size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
58 
59 bool strarrays__strtoul(struct strarrays *sas, char *bf, size_t size, u64 *ret);
60 
61 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
62 
63 extern struct strarray strarray__socket_families;
64 
65 extern struct strarray strarray__socket_level;
66 
67 /**
68  * augmented_arg: extra payload for syscall pointer arguments
69 
70  * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts,
71  * then its the arguments contents, so that we can show more than just a
72  * pointer. This will be done initially with eBPF, the start of that is at the
73  * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but
74  * will eventually be done automagically caching the running kernel tracefs
75  * events data into an eBPF C script, that then gets compiled and its .o file
76  * cached for subsequent use. For char pointers like the ones for 'open' like
77  * syscalls its easy, for the rest we should use DWARF or better, BTF, much
78  * more compact.
79  *
80  * @size: 8 if all we need is an integer, otherwise all of the augmented arg.
81  * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
82  * @value: u64 aligned, for structs, pathnames
83  */
84 struct augmented_arg {
85 	int  size;
86 	int  int_arg;
87 	u64  value[];
88 };
89 
90 struct syscall_arg_fmt;
91 
92 /**
93  * @val: value of syscall argument being formatted
94  * @len: for tracepoint dynamic arrays, if fmt->nr_entries == 0, then its not a fixed array, look at arg->len
95  * @args: All the args, use syscall_args__val(arg, nth) to access one
96  * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc
97  * @augmented_args_size: augmented_args total payload size
98  * @thread: tid state (maps, pid, tid, etc)
99  * @trace: 'perf trace' internals: all threads, etc
100  * @parm: private area, may be an strarray, for instance
101  * @idx: syscall arg idx (is this the first?)
102  * @mask: a syscall arg may mask another arg, see syscall_arg__scnprintf_futex_op
103  * @show_string_prefix: When there is a common prefix in a string table, show it or not
104  */
105 
106 struct syscall_arg {
107 	unsigned long val;
108 	unsigned char *args;
109 	struct syscall_arg_fmt *fmt;
110 	struct {
111 		struct augmented_arg *args;
112 		int		     size;
113 	} augmented;
114 	struct thread *thread;
115 	struct trace  *trace;
116 	void	      *parm;
117 	u16	      len;
118 	u8	      idx;
119 	u8	      mask;
120 	bool	      show_string_prefix;
121 };
122 
123 unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx);
124 
125 size_t syscall_arg__scnprintf_strarray_flags(char *bf, size_t size, struct syscall_arg *arg);
126 #define SCA_STRARRAY_FLAGS syscall_arg__scnprintf_strarray_flags
127 
128 bool syscall_arg__strtoul_strarray(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
129 #define STUL_STRARRAY syscall_arg__strtoul_strarray
130 
131 bool syscall_arg__strtoul_strarray_flags(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
132 #define STUL_STRARRAY_FLAGS syscall_arg__strtoul_strarray_flags
133 
134 bool syscall_arg__strtoul_strarrays(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
135 #define STUL_STRARRAYS syscall_arg__strtoul_strarrays
136 
137 size_t syscall_arg__scnprintf_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg);
138 #define SCA_X86_IRQ_VECTORS syscall_arg__scnprintf_x86_irq_vectors
139 
140 bool syscall_arg__strtoul_x86_irq_vectors(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
141 #define STUL_X86_IRQ_VECTORS syscall_arg__strtoul_x86_irq_vectors
142 
143 size_t syscall_arg__scnprintf_x86_MSR(char *bf, size_t size, struct syscall_arg *arg);
144 #define SCA_X86_MSR syscall_arg__scnprintf_x86_MSR
145 
146 bool syscall_arg__strtoul_x86_MSR(char *bf, size_t size, struct syscall_arg *arg, u64 *ret);
147 #define STUL_X86_MSR syscall_arg__strtoul_x86_MSR
148 
149 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, struct syscall_arg *arg);
150 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays
151 
152 size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg);
153 #define SCA_FD syscall_arg__scnprintf_fd
154 
155 size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg);
156 #define SCA_HEX syscall_arg__scnprintf_hex
157 
158 size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg);
159 #define SCA_PTR syscall_arg__scnprintf_ptr
160 
161 size_t syscall_arg__scnprintf_int(char *bf, size_t size, struct syscall_arg *arg);
162 #define SCA_INT syscall_arg__scnprintf_int
163 
164 size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg);
165 #define SCA_LONG syscall_arg__scnprintf_long
166 
167 size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg);
168 #define SCA_PID syscall_arg__scnprintf_pid
169 
170 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg);
171 #define SCA_CLONE_FLAGS syscall_arg__scnprintf_clone_flags
172 
173 size_t syscall_arg__scnprintf_fcntl_cmd(char *bf, size_t size, struct syscall_arg *arg);
174 #define SCA_FCNTL_CMD syscall_arg__scnprintf_fcntl_cmd
175 
176 size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arg *arg);
177 #define SCA_FCNTL_ARG syscall_arg__scnprintf_fcntl_arg
178 
179 size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg);
180 #define SCA_FLOCK syscall_arg__scnprintf_flock
181 
182 size_t syscall_arg__scnprintf_fsmount_attr_flags(char *bf, size_t size, struct syscall_arg *arg);
183 #define SCA_FSMOUNT_ATTR_FLAGS syscall_arg__scnprintf_fsmount_attr_flags
184 
185 size_t syscall_arg__scnprintf_fspick_flags(char *bf, size_t size, struct syscall_arg *arg);
186 #define SCA_FSPICK_FLAGS syscall_arg__scnprintf_fspick_flags
187 
188 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg);
189 #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd
190 
191 size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg);
192 #define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type
193 
194 size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg);
195 #define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx
196 
197 unsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg, unsigned long flags);
198 #define SCAMV_MOUNT_FLAGS syscall_arg__mask_val_mount_flags
199 
200 size_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg);
201 #define SCA_MOUNT_FLAGS syscall_arg__scnprintf_mount_flags
202 
203 size_t syscall_arg__scnprintf_move_mount_flags(char *bf, size_t size, struct syscall_arg *arg);
204 #define SCA_MOVE_MOUNT_FLAGS syscall_arg__scnprintf_move_mount_flags
205 
206 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg);
207 #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights
208 
209 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg);
210 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
211 
212 size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg);
213 #define SCA_X86_ARCH_PRCTL_CODE syscall_arg__scnprintf_x86_arch_prctl_code
214 
215 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg);
216 #define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option
217 
218 extern struct strarray strarray__prctl_options;
219 
220 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg);
221 #define SCA_PRCTL_ARG2 syscall_arg__scnprintf_prctl_arg2
222 
223 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg);
224 #define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3
225 
226 size_t syscall_arg__scnprintf_renameat2_flags(char *bf, size_t size, struct syscall_arg *arg);
227 #define SCA_RENAMEAT2_FLAGS syscall_arg__scnprintf_renameat2_flags
228 
229 size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg);
230 #define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr
231 
232 size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg);
233 #define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol
234 
235 size_t syscall_arg__scnprintf_socket_level(char *bf, size_t size, struct syscall_arg *arg);
236 #define SCA_SK_LEVEL syscall_arg__scnprintf_socket_level
237 
238 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg);
239 #define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags
240 
241 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg);
242 #define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask
243 
244 size_t syscall_arg__scnprintf_sync_file_range_flags(char *bf, size_t size, struct syscall_arg *arg);
245 #define SCA_SYNC_FILE_RANGE_FLAGS syscall_arg__scnprintf_sync_file_range_flags
246 
247 size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix);
248 
249 void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
250 				    size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg));
251 
252 const char *arch_syscalls__strerrno(const char *arch, int err);
253 
254 #endif /* _PERF_TRACE_BEAUTY_H */
255