1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_TRACE_BEAUTY_H
3 #define _PERF_TRACE_BEAUTY_H
5 #include <linux/kernel.h>
6 #include <linux/types.h>
14 const char * const *entries
;
17 #define DEFINE_STRARRAY(array, _prefix) struct strarray strarray__##array = { \
18 .nr_entries = ARRAY_SIZE(array), \
23 #define DEFINE_STRARRAY_OFFSET(array, _prefix, off) struct strarray strarray__##array = { \
25 .nr_entries = ARRAY_SIZE(array), \
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
);
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
);
45 struct file
*thread__files_entry(struct thread
*thread
, int fd
);
49 struct strarray
**entries
;
52 #define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \
53 .nr_entries = ARRAY_SIZE(array), \
57 size_t strarrays__scnprintf(struct strarrays
*sas
, char *bf
, size_t size
, const char *intfmt
, bool show_prefix
, int val
);
59 bool strarrays__strtoul(struct strarrays
*sas
, char *bf
, size_t size
, u64
*ret
);
61 size_t pid__scnprintf_fd(struct trace
*trace
, pid_t pid
, int fd
, char *bf
, size_t size
);
63 extern struct strarray strarray__socket_families
;
65 extern struct strarray strarray__socket_level
;
68 * augmented_arg: extra payload for syscall pointer arguments
70 * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts, then
71 * 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/util/bpf_skel/augmented_syscalls.bpf.c that will eventually be
74 * done automagically caching the running kernel tracefs events data into an
75 * eBPF C script, that then gets compiled and its .o file cached for subsequent
76 * use. For char pointers like the ones for 'open' like syscalls its easy, for
77 * the rest we should use DWARF or better, BTF, much more compact.
79 * @size: 8 if all we need is an integer, otherwise all of the augmented arg.
80 * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
81 * @value: u64 aligned, for structs, pathnames
83 struct augmented_arg
{
89 struct syscall_arg_fmt
;
92 * @val: value of syscall argument being formatted
93 * @len: for tracepoint dynamic arrays, if fmt->nr_entries == 0, then its not a fixed array, look at arg->len
94 * @args: All the args, use syscall_args__val(arg, nth) to access one
95 * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc
96 * @augmented_args_size: augmented_args total payload size
97 * @thread: tid state (maps, pid, tid, etc)
98 * @trace: 'perf trace' internals: all threads, etc
99 * @parm: private area, may be an strarray, for instance
100 * @idx: syscall arg idx (is this the first?)
101 * @mask: a syscall arg may mask another arg, see syscall_arg__scnprintf_futex_op
102 * @show_string_prefix: When there is a common prefix in a string table, show it or not
108 struct syscall_arg_fmt
*fmt
;
110 struct augmented_arg
*args
;
113 struct thread
*thread
;
120 bool show_string_prefix
;
123 unsigned long syscall_arg__val(struct syscall_arg
*arg
, u8 idx
);
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
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
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
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
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
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
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
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
149 size_t syscall_arg__scnprintf_strarrays(char *bf
, size_t size
, struct syscall_arg
*arg
);
150 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays
152 size_t syscall_arg__scnprintf_fd(char *bf
, size_t size
, struct syscall_arg
*arg
);
153 #define SCA_FD syscall_arg__scnprintf_fd
155 size_t syscall_arg__scnprintf_hex(char *bf
, size_t size
, struct syscall_arg
*arg
);
156 #define SCA_HEX syscall_arg__scnprintf_hex
158 size_t syscall_arg__scnprintf_ptr(char *bf
, size_t size
, struct syscall_arg
*arg
);
159 #define SCA_PTR syscall_arg__scnprintf_ptr
161 size_t syscall_arg__scnprintf_int(char *bf
, size_t size
, struct syscall_arg
*arg
);
162 #define SCA_INT syscall_arg__scnprintf_int
164 size_t syscall_arg__scnprintf_long(char *bf
, size_t size
, struct syscall_arg
*arg
);
165 #define SCA_LONG syscall_arg__scnprintf_long
167 size_t syscall_arg__scnprintf_pid(char *bf
, size_t size
, struct syscall_arg
*arg
);
168 #define SCA_PID syscall_arg__scnprintf_pid
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
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
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
179 size_t syscall_arg__scnprintf_flock(char *bf
, size_t size
, struct syscall_arg
*arg
);
180 #define SCA_FLOCK syscall_arg__scnprintf_flock
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
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
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
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
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
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
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
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
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
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
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
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
218 extern struct strarray strarray__prctl_options
;
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
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
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
229 size_t syscall_arg__scnprintf_sockaddr(char *bf
, size_t size
, struct syscall_arg
*arg
);
230 #define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr
232 // 'argname' is just documentational at this point, to remove the previous comment with that info
233 #define SCA_SOCKADDR_FROM_USER(argname) \
234 { .scnprintf = SCA_SOCKADDR, \
237 size_t syscall_arg__scnprintf_socket_protocol(char *bf
, size_t size
, struct syscall_arg
*arg
);
238 #define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol
240 size_t syscall_arg__scnprintf_socket_level(char *bf
, size_t size
, struct syscall_arg
*arg
);
241 #define SCA_SK_LEVEL syscall_arg__scnprintf_socket_level
243 size_t syscall_arg__scnprintf_fs_at_flags(char *bf
, size_t size
, struct syscall_arg
*arg
);
244 #define SCA_FS_AT_FLAGS syscall_arg__scnprintf_fs_at_flags
246 size_t syscall_arg__scnprintf_faccessat2_flags(char *bf
, size_t size
, struct syscall_arg
*arg
);
247 #define SCA_FACCESSAT2_FLAGS syscall_arg__scnprintf_faccessat2_flags
249 size_t syscall_arg__scnprintf_statx_mask(char *bf
, size_t size
, struct syscall_arg
*arg
);
250 #define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask
252 size_t syscall_arg__scnprintf_sync_file_range_flags(char *bf
, size_t size
, struct syscall_arg
*arg
);
253 #define SCA_SYNC_FILE_RANGE_FLAGS syscall_arg__scnprintf_sync_file_range_flags
255 size_t syscall_arg__scnprintf_timespec(char *bf
, size_t size
, struct syscall_arg
*arg
);
256 #define SCA_TIMESPEC syscall_arg__scnprintf_timespec
258 // 'argname' is just documentational at this point, to remove the previous comment with that info
259 #define SCA_TIMESPEC_FROM_USER(argname) \
260 { .scnprintf = SCA_TIMESPEC, \
263 size_t open__scnprintf_flags(unsigned long flags
, char *bf
, size_t size
, bool show_prefix
);
265 void syscall_arg__set_ret_scnprintf(struct syscall_arg
*arg
,
266 size_t (*ret_scnprintf
)(char *bf
, size_t size
, struct syscall_arg
*arg
));
268 #endif /* _PERF_TRACE_BEAUTY_H */