xref: /openbmc/linux/tools/perf/trace/beauty/beauty.h (revision a2818ee4)
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 
9 struct strarray {
10 	int	    offset;
11 	int	    nr_entries;
12 	const char *prefix;
13 	const char **entries;
14 };
15 
16 #define DEFINE_STRARRAY(array, _prefix) struct strarray strarray__##array = { \
17 	.nr_entries = ARRAY_SIZE(array), \
18 	.entries = array, \
19 	.prefix = _prefix, \
20 }
21 
22 #define DEFINE_STRARRAY_OFFSET(array, _prefix, off) struct strarray strarray__##array = { \
23 	.offset	    = off, \
24 	.nr_entries = ARRAY_SIZE(array), \
25 	.entries = array, \
26 	.prefix = _prefix, \
27 }
28 
29 size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
30 size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, bool show_prefix, unsigned long flags);
31 
32 struct trace;
33 struct thread;
34 
35 struct strarrays {
36 	int		nr_entries;
37 	struct strarray **entries;
38 };
39 
40 #define DEFINE_STRARRAYS(array) struct strarrays strarrays__##array = { \
41 	.nr_entries = ARRAY_SIZE(array), \
42 	.entries = array, \
43 }
44 
45 size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val);
46 
47 size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
48 
49 extern struct strarray strarray__socket_families;
50 
51 /**
52  * augmented_arg: extra payload for syscall pointer arguments
53 
54  * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts,
55  * then its the arguments contents, so that we can show more than just a
56  * pointer. This will be done initially with eBPF, the start of that is at the
57  * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but
58  * will eventually be done automagically caching the running kernel tracefs
59  * events data into an eBPF C script, that then gets compiled and its .o file
60  * cached for subsequent use. For char pointers like the ones for 'open' like
61  * syscalls its easy, for the rest we should use DWARF or better, BTF, much
62  * more compact.
63  *
64  * @size: 8 if all we need is an integer, otherwise all of the augmented arg.
65  * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
66  * @value: u64 aligned, for structs, pathnames
67  */
68 struct augmented_arg {
69 	int  size;
70 	int  int_arg;
71 	u64  value[];
72 };
73 
74 /**
75  * @val: value of syscall argument being formatted
76  * @args: All the args, use syscall_args__val(arg, nth) to access one
77  * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc
78  * @augmented_args_size: augmented_args total payload size
79  * @thread: tid state (maps, pid, tid, etc)
80  * @trace: 'perf trace' internals: all threads, etc
81  * @parm: private area, may be an strarray, for instance
82  * @idx: syscall arg idx (is this the first?)
83  * @mask: a syscall arg may mask another arg, see syscall_arg__scnprintf_futex_op
84  * @show_string_prefix: When there is a common prefix in a string table, show it or not
85  */
86 
87 struct syscall_arg {
88 	unsigned long val;
89 	unsigned char *args;
90 	struct {
91 		struct augmented_arg *args;
92 		int		     size;
93 	} augmented;
94 	struct thread *thread;
95 	struct trace  *trace;
96 	void	      *parm;
97 	u8	      idx;
98 	u8	      mask;
99 	bool	      show_string_prefix;
100 };
101 
102 unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx);
103 
104 size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, struct syscall_arg *arg);
105 #define SCA_STRARRAYS syscall_arg__scnprintf_strarrays
106 
107 size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg);
108 #define SCA_FD syscall_arg__scnprintf_fd
109 
110 size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg);
111 #define SCA_HEX syscall_arg__scnprintf_hex
112 
113 size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg);
114 #define SCA_PTR syscall_arg__scnprintf_ptr
115 
116 size_t syscall_arg__scnprintf_int(char *bf, size_t size, struct syscall_arg *arg);
117 #define SCA_INT syscall_arg__scnprintf_int
118 
119 size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg);
120 #define SCA_LONG syscall_arg__scnprintf_long
121 
122 size_t syscall_arg__scnprintf_pid(char *bf, size_t size, struct syscall_arg *arg);
123 #define SCA_PID syscall_arg__scnprintf_pid
124 
125 size_t syscall_arg__scnprintf_clone_flags(char *bf, size_t size, struct syscall_arg *arg);
126 #define SCA_CLONE_FLAGS syscall_arg__scnprintf_clone_flags
127 
128 size_t syscall_arg__scnprintf_fcntl_cmd(char *bf, size_t size, struct syscall_arg *arg);
129 #define SCA_FCNTL_CMD syscall_arg__scnprintf_fcntl_cmd
130 
131 size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_arg *arg);
132 #define SCA_FCNTL_ARG syscall_arg__scnprintf_fcntl_arg
133 
134 size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg);
135 #define SCA_FLOCK syscall_arg__scnprintf_flock
136 
137 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg);
138 #define SCA_IOCTL_CMD syscall_arg__scnprintf_ioctl_cmd
139 
140 size_t syscall_arg__scnprintf_kcmp_type(char *bf, size_t size, struct syscall_arg *arg);
141 #define SCA_KCMP_TYPE syscall_arg__scnprintf_kcmp_type
142 
143 size_t syscall_arg__scnprintf_kcmp_idx(char *bf, size_t size, struct syscall_arg *arg);
144 #define SCA_KCMP_IDX syscall_arg__scnprintf_kcmp_idx
145 
146 unsigned long syscall_arg__mask_val_mount_flags(struct syscall_arg *arg, unsigned long flags);
147 #define SCAMV_MOUNT_FLAGS syscall_arg__mask_val_mount_flags
148 
149 size_t syscall_arg__scnprintf_mount_flags(char *bf, size_t size, struct syscall_arg *arg);
150 #define SCA_MOUNT_FLAGS syscall_arg__scnprintf_mount_flags
151 
152 size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg);
153 #define SCA_PKEY_ALLOC_ACCESS_RIGHTS syscall_arg__scnprintf_pkey_alloc_access_rights
154 
155 size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, struct syscall_arg *arg);
156 #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
157 
158 size_t syscall_arg__scnprintf_x86_arch_prctl_code(char *bf, size_t size, struct syscall_arg *arg);
159 #define SCA_X86_ARCH_PRCTL_CODE syscall_arg__scnprintf_x86_arch_prctl_code
160 
161 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg);
162 #define SCA_PRCTL_OPTION syscall_arg__scnprintf_prctl_option
163 
164 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg);
165 #define SCA_PRCTL_ARG2 syscall_arg__scnprintf_prctl_arg2
166 
167 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg);
168 #define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3
169 
170 size_t syscall_arg__scnprintf_renameat2_flags(char *bf, size_t size, struct syscall_arg *arg);
171 #define SCA_RENAMEAT2_FLAGS syscall_arg__scnprintf_renameat2_flags
172 
173 size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg);
174 #define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr
175 
176 size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg);
177 #define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol
178 
179 size_t syscall_arg__scnprintf_statx_flags(char *bf, size_t size, struct syscall_arg *arg);
180 #define SCA_STATX_FLAGS syscall_arg__scnprintf_statx_flags
181 
182 size_t syscall_arg__scnprintf_statx_mask(char *bf, size_t size, struct syscall_arg *arg);
183 #define SCA_STATX_MASK syscall_arg__scnprintf_statx_mask
184 
185 size_t open__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix);
186 
187 void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg,
188 				    size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg));
189 
190 const char *arch_syscalls__strerrno(const char *arch, int err);
191 
192 #endif /* _PERF_TRACE_BEAUTY_H */
193