Arnaldo Carvalho de Melo | a598bb5 | 2015-08-28 12:02:37 -0300 | [diff] [blame] | 1 | /* |
| 2 | * builtin-trace.c |
| 3 | * |
| 4 | * Builtin 'trace' command: |
| 5 | * |
| 6 | * Display a continuously updated trace of any workload, CPU, specific PID, |
| 7 | * system wide, etc. Default format is loosely strace like, but any other |
| 8 | * event may be specified using --event. |
| 9 | * |
| 10 | * Copyright (C) 2012, 2013, 2014, 2015 Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 11 | * |
| 12 | * Initially based on the 'trace' prototype by Thomas Gleixner: |
| 13 | * |
| 14 | * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'") |
| 15 | * |
| 16 | * Released under the GPL v2. (and only v2, not any later version) |
| 17 | */ |
| 18 | |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 19 | #include <traceevent/event-parse.h> |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 20 | #include <api/fs/tracing_path.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 21 | #include "builtin.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 22 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 23 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 24 | #include "util/evlist.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 25 | #include <subcmd/exec-cmd.h> |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 26 | #include "util/machine.h" |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 27 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 28 | #include "util/thread.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 29 | #include <subcmd/parse-options.h> |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 30 | #include "util/strlist.h" |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 31 | #include "util/intlist.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 32 | #include "util/thread_map.h" |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 33 | #include "util/stat.h" |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 34 | #include "trace-event.h" |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 35 | #include "util/parse-events.h" |
Wang Nan | ba50423 | 2016-02-26 09:31:54 +0000 | [diff] [blame] | 36 | #include "util/bpf-loader.h" |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 37 | #include "callchain.h" |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 38 | #include "syscalltbl.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 39 | |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 40 | #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */ |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 41 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 42 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 43 | #include <linux/futex.h> |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 44 | #include <linux/err.h> |
Arnaldo Carvalho de Melo | 997bba8 | 2016-03-30 19:43:32 -0300 | [diff] [blame] | 45 | #include <linux/seccomp.h> |
| 46 | #include <linux/filter.h> |
| 47 | #include <linux/audit.h> |
| 48 | #include <sys/ptrace.h> |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 49 | #include <linux/random.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 50 | |
Ingo Molnar | 456857b | 2013-09-12 15:29:00 +0200 | [diff] [blame] | 51 | /* For older distros: */ |
| 52 | #ifndef MAP_STACK |
| 53 | # define MAP_STACK 0x20000 |
| 54 | #endif |
| 55 | |
| 56 | #ifndef MADV_HWPOISON |
| 57 | # define MADV_HWPOISON 100 |
Arnaldo Carvalho de Melo | a598bb5 | 2015-08-28 12:02:37 -0300 | [diff] [blame] | 58 | |
Ingo Molnar | 456857b | 2013-09-12 15:29:00 +0200 | [diff] [blame] | 59 | #endif |
| 60 | |
| 61 | #ifndef MADV_MERGEABLE |
| 62 | # define MADV_MERGEABLE 12 |
| 63 | #endif |
| 64 | |
| 65 | #ifndef MADV_UNMERGEABLE |
| 66 | # define MADV_UNMERGEABLE 13 |
| 67 | #endif |
| 68 | |
Ben Hutchings | 79d26a6 | 2014-02-06 01:00:35 +0000 | [diff] [blame] | 69 | #ifndef EFD_SEMAPHORE |
| 70 | # define EFD_SEMAPHORE 1 |
| 71 | #endif |
| 72 | |
Arnaldo Carvalho de Melo | c188e7a | 2015-05-14 17:39:03 -0300 | [diff] [blame] | 73 | #ifndef EFD_NONBLOCK |
| 74 | # define EFD_NONBLOCK 00004000 |
| 75 | #endif |
| 76 | |
| 77 | #ifndef EFD_CLOEXEC |
| 78 | # define EFD_CLOEXEC 02000000 |
| 79 | #endif |
| 80 | |
| 81 | #ifndef O_CLOEXEC |
| 82 | # define O_CLOEXEC 02000000 |
| 83 | #endif |
| 84 | |
| 85 | #ifndef SOCK_DCCP |
| 86 | # define SOCK_DCCP 6 |
| 87 | #endif |
| 88 | |
| 89 | #ifndef SOCK_CLOEXEC |
| 90 | # define SOCK_CLOEXEC 02000000 |
| 91 | #endif |
| 92 | |
| 93 | #ifndef SOCK_NONBLOCK |
| 94 | # define SOCK_NONBLOCK 00004000 |
| 95 | #endif |
| 96 | |
| 97 | #ifndef MSG_CMSG_CLOEXEC |
| 98 | # define MSG_CMSG_CLOEXEC 0x40000000 |
| 99 | #endif |
| 100 | |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 101 | #ifndef PERF_FLAG_FD_NO_GROUP |
| 102 | # define PERF_FLAG_FD_NO_GROUP (1UL << 0) |
| 103 | #endif |
| 104 | |
| 105 | #ifndef PERF_FLAG_FD_OUTPUT |
| 106 | # define PERF_FLAG_FD_OUTPUT (1UL << 1) |
| 107 | #endif |
| 108 | |
| 109 | #ifndef PERF_FLAG_PID_CGROUP |
| 110 | # define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */ |
| 111 | #endif |
| 112 | |
| 113 | #ifndef PERF_FLAG_FD_CLOEXEC |
| 114 | # define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */ |
| 115 | #endif |
| 116 | |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 117 | struct trace { |
| 118 | struct perf_tool tool; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 119 | struct syscalltbl *sctbl; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 120 | struct { |
| 121 | int max; |
| 122 | struct syscall *table; |
| 123 | struct { |
| 124 | struct perf_evsel *sys_enter, |
| 125 | *sys_exit; |
| 126 | } events; |
| 127 | } syscalls; |
| 128 | struct record_opts opts; |
| 129 | struct perf_evlist *evlist; |
| 130 | struct machine *host; |
| 131 | struct thread *current; |
| 132 | u64 base_time; |
| 133 | FILE *output; |
| 134 | unsigned long nr_events; |
| 135 | struct strlist *ev_qualifier; |
| 136 | struct { |
| 137 | size_t nr; |
| 138 | int *entries; |
| 139 | } ev_qualifier_ids; |
| 140 | struct intlist *tid_list; |
| 141 | struct intlist *pid_list; |
| 142 | struct { |
| 143 | size_t nr; |
| 144 | pid_t *entries; |
| 145 | } filter_pids; |
| 146 | double duration_filter; |
| 147 | double runtime_ms; |
| 148 | struct { |
| 149 | u64 vfs_getname, |
| 150 | proc_getname; |
| 151 | } stats; |
| 152 | bool not_ev_qualifier; |
| 153 | bool live; |
| 154 | bool full_time; |
| 155 | bool sched; |
| 156 | bool multiple_threads; |
| 157 | bool summary; |
| 158 | bool summary_only; |
| 159 | bool show_comm; |
| 160 | bool show_tool_stats; |
| 161 | bool trace_syscalls; |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 162 | bool kernel_syscallchains; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 163 | bool force; |
| 164 | bool vfs_getname; |
| 165 | int trace_pgfaults; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 166 | int open_id; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 167 | }; |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 168 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 169 | struct tp_field { |
| 170 | int offset; |
| 171 | union { |
| 172 | u64 (*integer)(struct tp_field *field, struct perf_sample *sample); |
| 173 | void *(*pointer)(struct tp_field *field, struct perf_sample *sample); |
| 174 | }; |
| 175 | }; |
| 176 | |
| 177 | #define TP_UINT_FIELD(bits) \ |
| 178 | static u64 tp_field__u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 179 | { \ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 180 | u##bits value; \ |
| 181 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
| 182 | return value; \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | TP_UINT_FIELD(8); |
| 186 | TP_UINT_FIELD(16); |
| 187 | TP_UINT_FIELD(32); |
| 188 | TP_UINT_FIELD(64); |
| 189 | |
| 190 | #define TP_UINT_FIELD__SWAPPED(bits) \ |
| 191 | static u64 tp_field__swapped_u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 192 | { \ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 193 | u##bits value; \ |
| 194 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 195 | return bswap_##bits(value);\ |
| 196 | } |
| 197 | |
| 198 | TP_UINT_FIELD__SWAPPED(16); |
| 199 | TP_UINT_FIELD__SWAPPED(32); |
| 200 | TP_UINT_FIELD__SWAPPED(64); |
| 201 | |
| 202 | static int tp_field__init_uint(struct tp_field *field, |
| 203 | struct format_field *format_field, |
| 204 | bool needs_swap) |
| 205 | { |
| 206 | field->offset = format_field->offset; |
| 207 | |
| 208 | switch (format_field->size) { |
| 209 | case 1: |
| 210 | field->integer = tp_field__u8; |
| 211 | break; |
| 212 | case 2: |
| 213 | field->integer = needs_swap ? tp_field__swapped_u16 : tp_field__u16; |
| 214 | break; |
| 215 | case 4: |
| 216 | field->integer = needs_swap ? tp_field__swapped_u32 : tp_field__u32; |
| 217 | break; |
| 218 | case 8: |
| 219 | field->integer = needs_swap ? tp_field__swapped_u64 : tp_field__u64; |
| 220 | break; |
| 221 | default: |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static void *tp_field__ptr(struct tp_field *field, struct perf_sample *sample) |
| 229 | { |
| 230 | return sample->raw_data + field->offset; |
| 231 | } |
| 232 | |
| 233 | static int tp_field__init_ptr(struct tp_field *field, struct format_field *format_field) |
| 234 | { |
| 235 | field->offset = format_field->offset; |
| 236 | field->pointer = tp_field__ptr; |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | struct syscall_tp { |
| 241 | struct tp_field id; |
| 242 | union { |
| 243 | struct tp_field args, ret; |
| 244 | }; |
| 245 | }; |
| 246 | |
| 247 | static int perf_evsel__init_tp_uint_field(struct perf_evsel *evsel, |
| 248 | struct tp_field *field, |
| 249 | const char *name) |
| 250 | { |
| 251 | struct format_field *format_field = perf_evsel__field(evsel, name); |
| 252 | |
| 253 | if (format_field == NULL) |
| 254 | return -1; |
| 255 | |
| 256 | return tp_field__init_uint(field, format_field, evsel->needs_swap); |
| 257 | } |
| 258 | |
| 259 | #define perf_evsel__init_sc_tp_uint_field(evsel, name) \ |
| 260 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 261 | perf_evsel__init_tp_uint_field(evsel, &sc->name, #name); }) |
| 262 | |
| 263 | static int perf_evsel__init_tp_ptr_field(struct perf_evsel *evsel, |
| 264 | struct tp_field *field, |
| 265 | const char *name) |
| 266 | { |
| 267 | struct format_field *format_field = perf_evsel__field(evsel, name); |
| 268 | |
| 269 | if (format_field == NULL) |
| 270 | return -1; |
| 271 | |
| 272 | return tp_field__init_ptr(field, format_field); |
| 273 | } |
| 274 | |
| 275 | #define perf_evsel__init_sc_tp_ptr_field(evsel, name) \ |
| 276 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 277 | perf_evsel__init_tp_ptr_field(evsel, &sc->name, #name); }) |
| 278 | |
| 279 | static void perf_evsel__delete_priv(struct perf_evsel *evsel) |
| 280 | { |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 281 | zfree(&evsel->priv); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 282 | perf_evsel__delete(evsel); |
| 283 | } |
| 284 | |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 285 | static int perf_evsel__init_syscall_tp(struct perf_evsel *evsel, void *handler) |
| 286 | { |
| 287 | evsel->priv = malloc(sizeof(struct syscall_tp)); |
| 288 | if (evsel->priv != NULL) { |
| 289 | if (perf_evsel__init_sc_tp_uint_field(evsel, id)) |
| 290 | goto out_delete; |
| 291 | |
| 292 | evsel->handler = handler; |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | return -ENOMEM; |
| 297 | |
| 298 | out_delete: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 299 | zfree(&evsel->priv); |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 300 | return -ENOENT; |
| 301 | } |
| 302 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 303 | static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void *handler) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 304 | { |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 305 | struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 306 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 307 | /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */ |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 308 | if (IS_ERR(evsel)) |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 309 | evsel = perf_evsel__newtp("syscalls", direction); |
| 310 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 311 | if (IS_ERR(evsel)) |
| 312 | return NULL; |
| 313 | |
| 314 | if (perf_evsel__init_syscall_tp(evsel, handler)) |
| 315 | goto out_delete; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 316 | |
| 317 | return evsel; |
| 318 | |
| 319 | out_delete: |
| 320 | perf_evsel__delete_priv(evsel); |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | #define perf_evsel__sc_tp_uint(evsel, name, sample) \ |
| 325 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 326 | fields->name.integer(&fields->name, sample); }) |
| 327 | |
| 328 | #define perf_evsel__sc_tp_ptr(evsel, name, sample) \ |
| 329 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 330 | fields->name.pointer(&fields->name, sample); }) |
| 331 | |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 332 | struct syscall_arg { |
| 333 | unsigned long val; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 334 | struct thread *thread; |
| 335 | struct trace *trace; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 336 | void *parm; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 337 | u8 idx; |
| 338 | u8 mask; |
| 339 | }; |
| 340 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 341 | struct strarray { |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 342 | int offset; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 343 | int nr_entries; |
| 344 | const char **entries; |
| 345 | }; |
| 346 | |
| 347 | #define DEFINE_STRARRAY(array) struct strarray strarray__##array = { \ |
| 348 | .nr_entries = ARRAY_SIZE(array), \ |
| 349 | .entries = array, \ |
| 350 | } |
| 351 | |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 352 | #define DEFINE_STRARRAY_OFFSET(array, off) struct strarray strarray__##array = { \ |
| 353 | .offset = off, \ |
| 354 | .nr_entries = ARRAY_SIZE(array), \ |
| 355 | .entries = array, \ |
| 356 | } |
| 357 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 358 | static size_t __syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 359 | const char *intfmt, |
| 360 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 361 | { |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 362 | struct strarray *sa = arg->parm; |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 363 | int idx = arg->val - sa->offset; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 364 | |
| 365 | if (idx < 0 || idx >= sa->nr_entries) |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 366 | return scnprintf(bf, size, intfmt, arg->val); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 367 | |
| 368 | return scnprintf(bf, size, "%s", sa->entries[idx]); |
| 369 | } |
| 370 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 371 | static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 372 | struct syscall_arg *arg) |
| 373 | { |
| 374 | return __syscall_arg__scnprintf_strarray(bf, size, "%d", arg); |
| 375 | } |
| 376 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 377 | #define SCA_STRARRAY syscall_arg__scnprintf_strarray |
| 378 | |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 379 | #if defined(__i386__) || defined(__x86_64__) |
| 380 | /* |
| 381 | * FIXME: Make this available to all arches as soon as the ioctl beautifier |
| 382 | * gets rewritten to support all arches. |
| 383 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 384 | static size_t syscall_arg__scnprintf_strhexarray(char *bf, size_t size, |
| 385 | struct syscall_arg *arg) |
| 386 | { |
| 387 | return __syscall_arg__scnprintf_strarray(bf, size, "%#x", arg); |
| 388 | } |
| 389 | |
| 390 | #define SCA_STRHEXARRAY syscall_arg__scnprintf_strhexarray |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 391 | #endif /* defined(__i386__) || defined(__x86_64__) */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 392 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 393 | static size_t syscall_arg__scnprintf_fd(char *bf, size_t size, |
| 394 | struct syscall_arg *arg); |
| 395 | |
| 396 | #define SCA_FD syscall_arg__scnprintf_fd |
| 397 | |
| 398 | static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size, |
| 399 | struct syscall_arg *arg) |
| 400 | { |
| 401 | int fd = arg->val; |
| 402 | |
| 403 | if (fd == AT_FDCWD) |
| 404 | return scnprintf(bf, size, "CWD"); |
| 405 | |
| 406 | return syscall_arg__scnprintf_fd(bf, size, arg); |
| 407 | } |
| 408 | |
| 409 | #define SCA_FDAT syscall_arg__scnprintf_fd_at |
| 410 | |
| 411 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 412 | struct syscall_arg *arg); |
| 413 | |
| 414 | #define SCA_CLOSE_FD syscall_arg__scnprintf_close_fd |
| 415 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 416 | static size_t syscall_arg__scnprintf_hex(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 417 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 418 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 419 | return scnprintf(bf, size, "%#lx", arg->val); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 420 | } |
| 421 | |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 422 | #define SCA_HEX syscall_arg__scnprintf_hex |
| 423 | |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 424 | static size_t syscall_arg__scnprintf_int(char *bf, size_t size, |
| 425 | struct syscall_arg *arg) |
| 426 | { |
| 427 | return scnprintf(bf, size, "%d", arg->val); |
| 428 | } |
| 429 | |
| 430 | #define SCA_INT syscall_arg__scnprintf_int |
| 431 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 432 | static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 433 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 434 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 435 | int printed = 0, prot = arg->val; |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 436 | |
| 437 | if (prot == PROT_NONE) |
| 438 | return scnprintf(bf, size, "NONE"); |
| 439 | #define P_MMAP_PROT(n) \ |
| 440 | if (prot & PROT_##n) { \ |
| 441 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 442 | prot &= ~PROT_##n; \ |
| 443 | } |
| 444 | |
| 445 | P_MMAP_PROT(EXEC); |
| 446 | P_MMAP_PROT(READ); |
| 447 | P_MMAP_PROT(WRITE); |
| 448 | #ifdef PROT_SEM |
| 449 | P_MMAP_PROT(SEM); |
| 450 | #endif |
| 451 | P_MMAP_PROT(GROWSDOWN); |
| 452 | P_MMAP_PROT(GROWSUP); |
| 453 | #undef P_MMAP_PROT |
| 454 | |
| 455 | if (prot) |
| 456 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot); |
| 457 | |
| 458 | return printed; |
| 459 | } |
| 460 | |
| 461 | #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot |
| 462 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 463 | static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 464 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 465 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 466 | int printed = 0, flags = arg->val; |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 467 | |
| 468 | #define P_MMAP_FLAG(n) \ |
| 469 | if (flags & MAP_##n) { \ |
| 470 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 471 | flags &= ~MAP_##n; \ |
| 472 | } |
| 473 | |
| 474 | P_MMAP_FLAG(SHARED); |
| 475 | P_MMAP_FLAG(PRIVATE); |
Kyle McMartin | 4181781 | 2013-09-05 10:29:47 -0400 | [diff] [blame] | 476 | #ifdef MAP_32BIT |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 477 | P_MMAP_FLAG(32BIT); |
Kyle McMartin | 4181781 | 2013-09-05 10:29:47 -0400 | [diff] [blame] | 478 | #endif |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 479 | P_MMAP_FLAG(ANONYMOUS); |
| 480 | P_MMAP_FLAG(DENYWRITE); |
| 481 | P_MMAP_FLAG(EXECUTABLE); |
| 482 | P_MMAP_FLAG(FILE); |
| 483 | P_MMAP_FLAG(FIXED); |
| 484 | P_MMAP_FLAG(GROWSDOWN); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 485 | #ifdef MAP_HUGETLB |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 486 | P_MMAP_FLAG(HUGETLB); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 487 | #endif |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 488 | P_MMAP_FLAG(LOCKED); |
| 489 | P_MMAP_FLAG(NONBLOCK); |
| 490 | P_MMAP_FLAG(NORESERVE); |
| 491 | P_MMAP_FLAG(POPULATE); |
| 492 | P_MMAP_FLAG(STACK); |
| 493 | #ifdef MAP_UNINITIALIZED |
| 494 | P_MMAP_FLAG(UNINITIALIZED); |
| 495 | #endif |
| 496 | #undef P_MMAP_FLAG |
| 497 | |
| 498 | if (flags) |
| 499 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 500 | |
| 501 | return printed; |
| 502 | } |
| 503 | |
| 504 | #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags |
| 505 | |
Alex Snast | 86998dd | 2014-08-13 18:42:40 +0300 | [diff] [blame] | 506 | static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, |
| 507 | struct syscall_arg *arg) |
| 508 | { |
| 509 | int printed = 0, flags = arg->val; |
| 510 | |
| 511 | #define P_MREMAP_FLAG(n) \ |
| 512 | if (flags & MREMAP_##n) { \ |
| 513 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 514 | flags &= ~MREMAP_##n; \ |
| 515 | } |
| 516 | |
| 517 | P_MREMAP_FLAG(MAYMOVE); |
| 518 | #ifdef MREMAP_FIXED |
| 519 | P_MREMAP_FLAG(FIXED); |
| 520 | #endif |
| 521 | #undef P_MREMAP_FLAG |
| 522 | |
| 523 | if (flags) |
| 524 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 525 | |
| 526 | return printed; |
| 527 | } |
| 528 | |
| 529 | #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags |
| 530 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 531 | static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 532 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 533 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 534 | int behavior = arg->val; |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 535 | |
| 536 | switch (behavior) { |
| 537 | #define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n) |
| 538 | P_MADV_BHV(NORMAL); |
| 539 | P_MADV_BHV(RANDOM); |
| 540 | P_MADV_BHV(SEQUENTIAL); |
| 541 | P_MADV_BHV(WILLNEED); |
| 542 | P_MADV_BHV(DONTNEED); |
| 543 | P_MADV_BHV(REMOVE); |
| 544 | P_MADV_BHV(DONTFORK); |
| 545 | P_MADV_BHV(DOFORK); |
| 546 | P_MADV_BHV(HWPOISON); |
| 547 | #ifdef MADV_SOFT_OFFLINE |
| 548 | P_MADV_BHV(SOFT_OFFLINE); |
| 549 | #endif |
| 550 | P_MADV_BHV(MERGEABLE); |
| 551 | P_MADV_BHV(UNMERGEABLE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 552 | #ifdef MADV_HUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 553 | P_MADV_BHV(HUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 554 | #endif |
| 555 | #ifdef MADV_NOHUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 556 | P_MADV_BHV(NOHUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 557 | #endif |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 558 | #ifdef MADV_DONTDUMP |
| 559 | P_MADV_BHV(DONTDUMP); |
| 560 | #endif |
| 561 | #ifdef MADV_DODUMP |
| 562 | P_MADV_BHV(DODUMP); |
| 563 | #endif |
| 564 | #undef P_MADV_PHV |
| 565 | default: break; |
| 566 | } |
| 567 | |
| 568 | return scnprintf(bf, size, "%#x", behavior); |
| 569 | } |
| 570 | |
| 571 | #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior |
| 572 | |
Arnaldo Carvalho de Melo | 5cea6ff | 2013-09-20 11:49:50 -0300 | [diff] [blame] | 573 | static size_t syscall_arg__scnprintf_flock(char *bf, size_t size, |
| 574 | struct syscall_arg *arg) |
| 575 | { |
| 576 | int printed = 0, op = arg->val; |
| 577 | |
| 578 | if (op == 0) |
| 579 | return scnprintf(bf, size, "NONE"); |
| 580 | #define P_CMD(cmd) \ |
| 581 | if ((op & LOCK_##cmd) == LOCK_##cmd) { \ |
| 582 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #cmd); \ |
| 583 | op &= ~LOCK_##cmd; \ |
| 584 | } |
| 585 | |
| 586 | P_CMD(SH); |
| 587 | P_CMD(EX); |
| 588 | P_CMD(NB); |
| 589 | P_CMD(UN); |
| 590 | P_CMD(MAND); |
| 591 | P_CMD(RW); |
| 592 | P_CMD(READ); |
| 593 | P_CMD(WRITE); |
| 594 | #undef P_OP |
| 595 | |
| 596 | if (op) |
| 597 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", op); |
| 598 | |
| 599 | return printed; |
| 600 | } |
| 601 | |
| 602 | #define SCA_FLOCK syscall_arg__scnprintf_flock |
| 603 | |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 604 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 605 | { |
| 606 | enum syscall_futex_args { |
| 607 | SCF_UADDR = (1 << 0), |
| 608 | SCF_OP = (1 << 1), |
| 609 | SCF_VAL = (1 << 2), |
| 610 | SCF_TIMEOUT = (1 << 3), |
| 611 | SCF_UADDR2 = (1 << 4), |
| 612 | SCF_VAL3 = (1 << 5), |
| 613 | }; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 614 | int op = arg->val; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 615 | int cmd = op & FUTEX_CMD_MASK; |
| 616 | size_t printed = 0; |
| 617 | |
| 618 | switch (cmd) { |
| 619 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 620 | P_FUTEX_OP(WAIT); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 621 | P_FUTEX_OP(WAKE); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 622 | P_FUTEX_OP(FD); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 623 | P_FUTEX_OP(REQUEUE); arg->mask |= SCF_VAL3|SCF_TIMEOUT; break; |
| 624 | P_FUTEX_OP(CMP_REQUEUE); arg->mask |= SCF_TIMEOUT; break; |
| 625 | P_FUTEX_OP(CMP_REQUEUE_PI); arg->mask |= SCF_TIMEOUT; break; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 626 | P_FUTEX_OP(WAKE_OP); break; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 627 | P_FUTEX_OP(LOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 628 | P_FUTEX_OP(UNLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 629 | P_FUTEX_OP(TRYLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 630 | P_FUTEX_OP(WAIT_BITSET); arg->mask |= SCF_UADDR2; break; |
| 631 | P_FUTEX_OP(WAKE_BITSET); arg->mask |= SCF_UADDR2; break; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 632 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; |
| 633 | default: printed = scnprintf(bf, size, "%#x", cmd); break; |
| 634 | } |
| 635 | |
| 636 | if (op & FUTEX_PRIVATE_FLAG) |
| 637 | printed += scnprintf(bf + printed, size - printed, "|PRIV"); |
| 638 | |
| 639 | if (op & FUTEX_CLOCK_REALTIME) |
| 640 | printed += scnprintf(bf + printed, size - printed, "|CLKRT"); |
| 641 | |
| 642 | return printed; |
| 643 | } |
| 644 | |
Arnaldo Carvalho de Melo | efe6b88 | 2013-09-03 16:15:12 -0300 | [diff] [blame] | 645 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op |
| 646 | |
Arnaldo Carvalho de Melo | 729a784 | 2015-10-29 11:48:18 -0300 | [diff] [blame] | 647 | static const char *bpf_cmd[] = { |
| 648 | "MAP_CREATE", "MAP_LOOKUP_ELEM", "MAP_UPDATE_ELEM", "MAP_DELETE_ELEM", |
| 649 | "MAP_GET_NEXT_KEY", "PROG_LOAD", |
| 650 | }; |
| 651 | static DEFINE_STRARRAY(bpf_cmd); |
| 652 | |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 653 | static const char *epoll_ctl_ops[] = { "ADD", "DEL", "MOD", }; |
| 654 | static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, 1); |
Arnaldo Carvalho de Melo | eac032c | 2013-09-20 11:27:32 -0300 | [diff] [blame] | 655 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 656 | static const char *itimers[] = { "REAL", "VIRTUAL", "PROF", }; |
| 657 | static DEFINE_STRARRAY(itimers); |
| 658 | |
Arnaldo Carvalho de Melo | b62bee1 | 2015-08-11 11:05:36 -0300 | [diff] [blame] | 659 | static const char *keyctl_options[] = { |
| 660 | "GET_KEYRING_ID", "JOIN_SESSION_KEYRING", "UPDATE", "REVOKE", "CHOWN", |
| 661 | "SETPERM", "DESCRIBE", "CLEAR", "LINK", "UNLINK", "SEARCH", "READ", |
| 662 | "INSTANTIATE", "NEGATE", "SET_REQKEY_KEYRING", "SET_TIMEOUT", |
| 663 | "ASSUME_AUTHORITY", "GET_SECURITY", "SESSION_TO_PARENT", "REJECT", |
| 664 | "INSTANTIATE_IOV", "INVALIDATE", "GET_PERSISTENT", |
| 665 | }; |
| 666 | static DEFINE_STRARRAY(keyctl_options); |
| 667 | |
Arnaldo Carvalho de Melo | efe6b88 | 2013-09-03 16:15:12 -0300 | [diff] [blame] | 668 | static const char *whences[] = { "SET", "CUR", "END", |
| 669 | #ifdef SEEK_DATA |
| 670 | "DATA", |
| 671 | #endif |
| 672 | #ifdef SEEK_HOLE |
| 673 | "HOLE", |
| 674 | #endif |
| 675 | }; |
| 676 | static DEFINE_STRARRAY(whences); |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 677 | |
Arnaldo Carvalho de Melo | 80f587d | 2013-09-03 16:28:58 -0300 | [diff] [blame] | 678 | static const char *fcntl_cmds[] = { |
| 679 | "DUPFD", "GETFD", "SETFD", "GETFL", "SETFL", "GETLK", "SETLK", |
| 680 | "SETLKW", "SETOWN", "GETOWN", "SETSIG", "GETSIG", "F_GETLK64", |
| 681 | "F_SETLK64", "F_SETLKW64", "F_SETOWN_EX", "F_GETOWN_EX", |
| 682 | "F_GETOWNER_UIDS", |
| 683 | }; |
| 684 | static DEFINE_STRARRAY(fcntl_cmds); |
| 685 | |
Arnaldo Carvalho de Melo | c045bf0 | 2013-09-04 11:52:33 -0300 | [diff] [blame] | 686 | static const char *rlimit_resources[] = { |
| 687 | "CPU", "FSIZE", "DATA", "STACK", "CORE", "RSS", "NPROC", "NOFILE", |
| 688 | "MEMLOCK", "AS", "LOCKS", "SIGPENDING", "MSGQUEUE", "NICE", "RTPRIO", |
| 689 | "RTTIME", |
| 690 | }; |
| 691 | static DEFINE_STRARRAY(rlimit_resources); |
| 692 | |
Arnaldo Carvalho de Melo | eb5b1b1 | 2013-09-03 16:37:46 -0300 | [diff] [blame] | 693 | static const char *sighow[] = { "BLOCK", "UNBLOCK", "SETMASK", }; |
| 694 | static DEFINE_STRARRAY(sighow); |
| 695 | |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 696 | static const char *clockid[] = { |
| 697 | "REALTIME", "MONOTONIC", "PROCESS_CPUTIME_ID", "THREAD_CPUTIME_ID", |
Arnaldo Carvalho de Melo | 28ebb87 | 2015-08-11 10:38:38 -0300 | [diff] [blame] | 698 | "MONOTONIC_RAW", "REALTIME_COARSE", "MONOTONIC_COARSE", "BOOTTIME", |
| 699 | "REALTIME_ALARM", "BOOTTIME_ALARM", "SGI_CYCLE", "TAI" |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 700 | }; |
| 701 | static DEFINE_STRARRAY(clockid); |
| 702 | |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 703 | static const char *socket_families[] = { |
| 704 | "UNSPEC", "LOCAL", "INET", "AX25", "IPX", "APPLETALK", "NETROM", |
| 705 | "BRIDGE", "ATMPVC", "X25", "INET6", "ROSE", "DECnet", "NETBEUI", |
| 706 | "SECURITY", "KEY", "NETLINK", "PACKET", "ASH", "ECONET", "ATMSVC", |
| 707 | "RDS", "SNA", "IRDA", "PPPOX", "WANPIPE", "LLC", "IB", "CAN", "TIPC", |
| 708 | "BLUETOOTH", "IUCV", "RXRPC", "ISDN", "PHONET", "IEEE802154", "CAIF", |
| 709 | "ALG", "NFC", "VSOCK", |
| 710 | }; |
| 711 | static DEFINE_STRARRAY(socket_families); |
| 712 | |
Arnaldo Carvalho de Melo | a28b24b | 2013-09-04 11:00:44 -0300 | [diff] [blame] | 713 | #ifndef SOCK_TYPE_MASK |
| 714 | #define SOCK_TYPE_MASK 0xf |
| 715 | #endif |
| 716 | |
| 717 | static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, |
| 718 | struct syscall_arg *arg) |
| 719 | { |
| 720 | size_t printed; |
| 721 | int type = arg->val, |
| 722 | flags = type & ~SOCK_TYPE_MASK; |
| 723 | |
| 724 | type &= SOCK_TYPE_MASK; |
| 725 | /* |
| 726 | * Can't use a strarray, MIPS may override for ABI reasons. |
| 727 | */ |
| 728 | switch (type) { |
| 729 | #define P_SK_TYPE(n) case SOCK_##n: printed = scnprintf(bf, size, #n); break; |
| 730 | P_SK_TYPE(STREAM); |
| 731 | P_SK_TYPE(DGRAM); |
| 732 | P_SK_TYPE(RAW); |
| 733 | P_SK_TYPE(RDM); |
| 734 | P_SK_TYPE(SEQPACKET); |
| 735 | P_SK_TYPE(DCCP); |
| 736 | P_SK_TYPE(PACKET); |
| 737 | #undef P_SK_TYPE |
| 738 | default: |
| 739 | printed = scnprintf(bf, size, "%#x", type); |
| 740 | } |
| 741 | |
| 742 | #define P_SK_FLAG(n) \ |
| 743 | if (flags & SOCK_##n) { \ |
| 744 | printed += scnprintf(bf + printed, size - printed, "|%s", #n); \ |
| 745 | flags &= ~SOCK_##n; \ |
| 746 | } |
| 747 | |
| 748 | P_SK_FLAG(CLOEXEC); |
| 749 | P_SK_FLAG(NONBLOCK); |
| 750 | #undef P_SK_FLAG |
| 751 | |
| 752 | if (flags) |
| 753 | printed += scnprintf(bf + printed, size - printed, "|%#x", flags); |
| 754 | |
| 755 | return printed; |
| 756 | } |
| 757 | |
| 758 | #define SCA_SK_TYPE syscall_arg__scnprintf_socket_type |
| 759 | |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 760 | #ifndef MSG_PROBE |
| 761 | #define MSG_PROBE 0x10 |
| 762 | #endif |
David Ahern | b6e8f8f | 2013-09-22 19:44:56 -0600 | [diff] [blame] | 763 | #ifndef MSG_WAITFORONE |
| 764 | #define MSG_WAITFORONE 0x10000 |
| 765 | #endif |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 766 | #ifndef MSG_SENDPAGE_NOTLAST |
| 767 | #define MSG_SENDPAGE_NOTLAST 0x20000 |
| 768 | #endif |
| 769 | #ifndef MSG_FASTOPEN |
| 770 | #define MSG_FASTOPEN 0x20000000 |
| 771 | #endif |
| 772 | |
| 773 | static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size, |
| 774 | struct syscall_arg *arg) |
| 775 | { |
| 776 | int printed = 0, flags = arg->val; |
| 777 | |
| 778 | if (flags == 0) |
| 779 | return scnprintf(bf, size, "NONE"); |
| 780 | #define P_MSG_FLAG(n) \ |
| 781 | if (flags & MSG_##n) { \ |
| 782 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 783 | flags &= ~MSG_##n; \ |
| 784 | } |
| 785 | |
| 786 | P_MSG_FLAG(OOB); |
| 787 | P_MSG_FLAG(PEEK); |
| 788 | P_MSG_FLAG(DONTROUTE); |
| 789 | P_MSG_FLAG(TRYHARD); |
| 790 | P_MSG_FLAG(CTRUNC); |
| 791 | P_MSG_FLAG(PROBE); |
| 792 | P_MSG_FLAG(TRUNC); |
| 793 | P_MSG_FLAG(DONTWAIT); |
| 794 | P_MSG_FLAG(EOR); |
| 795 | P_MSG_FLAG(WAITALL); |
| 796 | P_MSG_FLAG(FIN); |
| 797 | P_MSG_FLAG(SYN); |
| 798 | P_MSG_FLAG(CONFIRM); |
| 799 | P_MSG_FLAG(RST); |
| 800 | P_MSG_FLAG(ERRQUEUE); |
| 801 | P_MSG_FLAG(NOSIGNAL); |
| 802 | P_MSG_FLAG(MORE); |
| 803 | P_MSG_FLAG(WAITFORONE); |
| 804 | P_MSG_FLAG(SENDPAGE_NOTLAST); |
| 805 | P_MSG_FLAG(FASTOPEN); |
| 806 | P_MSG_FLAG(CMSG_CLOEXEC); |
| 807 | #undef P_MSG_FLAG |
| 808 | |
| 809 | if (flags) |
| 810 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 811 | |
| 812 | return printed; |
| 813 | } |
| 814 | |
| 815 | #define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags |
| 816 | |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 817 | static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size, |
| 818 | struct syscall_arg *arg) |
| 819 | { |
| 820 | size_t printed = 0; |
| 821 | int mode = arg->val; |
| 822 | |
| 823 | if (mode == F_OK) /* 0 */ |
| 824 | return scnprintf(bf, size, "F"); |
| 825 | #define P_MODE(n) \ |
| 826 | if (mode & n##_OK) { \ |
| 827 | printed += scnprintf(bf + printed, size - printed, "%s", #n); \ |
| 828 | mode &= ~n##_OK; \ |
| 829 | } |
| 830 | |
| 831 | P_MODE(R); |
| 832 | P_MODE(W); |
| 833 | P_MODE(X); |
| 834 | #undef P_MODE |
| 835 | |
| 836 | if (mode) |
| 837 | printed += scnprintf(bf + printed, size - printed, "|%#x", mode); |
| 838 | |
| 839 | return printed; |
| 840 | } |
| 841 | |
| 842 | #define SCA_ACCMODE syscall_arg__scnprintf_access_mode |
| 843 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 844 | static size_t syscall_arg__scnprintf_filename(char *bf, size_t size, |
| 845 | struct syscall_arg *arg); |
| 846 | |
| 847 | #define SCA_FILENAME syscall_arg__scnprintf_filename |
| 848 | |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 849 | static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 850 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 851 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 852 | int printed = 0, flags = arg->val; |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 853 | |
| 854 | if (!(flags & O_CREAT)) |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 855 | arg->mask |= 1 << (arg->idx + 1); /* Mask the mode parm */ |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 856 | |
| 857 | if (flags == 0) |
| 858 | return scnprintf(bf, size, "RDONLY"); |
| 859 | #define P_FLAG(n) \ |
| 860 | if (flags & O_##n) { \ |
| 861 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 862 | flags &= ~O_##n; \ |
| 863 | } |
| 864 | |
| 865 | P_FLAG(APPEND); |
| 866 | P_FLAG(ASYNC); |
| 867 | P_FLAG(CLOEXEC); |
| 868 | P_FLAG(CREAT); |
| 869 | P_FLAG(DIRECT); |
| 870 | P_FLAG(DIRECTORY); |
| 871 | P_FLAG(EXCL); |
| 872 | P_FLAG(LARGEFILE); |
| 873 | P_FLAG(NOATIME); |
| 874 | P_FLAG(NOCTTY); |
| 875 | #ifdef O_NONBLOCK |
| 876 | P_FLAG(NONBLOCK); |
| 877 | #elif O_NDELAY |
| 878 | P_FLAG(NDELAY); |
| 879 | #endif |
| 880 | #ifdef O_PATH |
| 881 | P_FLAG(PATH); |
| 882 | #endif |
| 883 | P_FLAG(RDWR); |
| 884 | #ifdef O_DSYNC |
| 885 | if ((flags & O_SYNC) == O_SYNC) |
| 886 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", "SYNC"); |
| 887 | else { |
| 888 | P_FLAG(DSYNC); |
| 889 | } |
| 890 | #else |
| 891 | P_FLAG(SYNC); |
| 892 | #endif |
| 893 | P_FLAG(TRUNC); |
| 894 | P_FLAG(WRONLY); |
| 895 | #undef P_FLAG |
| 896 | |
| 897 | if (flags) |
| 898 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 899 | |
| 900 | return printed; |
| 901 | } |
| 902 | |
| 903 | #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags |
| 904 | |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 905 | static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size, |
| 906 | struct syscall_arg *arg) |
| 907 | { |
| 908 | int printed = 0, flags = arg->val; |
| 909 | |
| 910 | if (flags == 0) |
| 911 | return 0; |
| 912 | |
| 913 | #define P_FLAG(n) \ |
| 914 | if (flags & PERF_FLAG_##n) { \ |
| 915 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 916 | flags &= ~PERF_FLAG_##n; \ |
| 917 | } |
| 918 | |
| 919 | P_FLAG(FD_NO_GROUP); |
| 920 | P_FLAG(FD_OUTPUT); |
| 921 | P_FLAG(PID_CGROUP); |
| 922 | P_FLAG(FD_CLOEXEC); |
| 923 | #undef P_FLAG |
| 924 | |
| 925 | if (flags) |
| 926 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 927 | |
| 928 | return printed; |
| 929 | } |
| 930 | |
| 931 | #define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags |
| 932 | |
Arnaldo Carvalho de Melo | 49af9e9 | 2013-09-12 12:18:56 -0300 | [diff] [blame] | 933 | static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, |
| 934 | struct syscall_arg *arg) |
| 935 | { |
| 936 | int printed = 0, flags = arg->val; |
| 937 | |
| 938 | if (flags == 0) |
| 939 | return scnprintf(bf, size, "NONE"); |
| 940 | #define P_FLAG(n) \ |
| 941 | if (flags & EFD_##n) { \ |
| 942 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 943 | flags &= ~EFD_##n; \ |
| 944 | } |
| 945 | |
| 946 | P_FLAG(SEMAPHORE); |
| 947 | P_FLAG(CLOEXEC); |
| 948 | P_FLAG(NONBLOCK); |
| 949 | #undef P_FLAG |
| 950 | |
| 951 | if (flags) |
| 952 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 953 | |
| 954 | return printed; |
| 955 | } |
| 956 | |
| 957 | #define SCA_EFD_FLAGS syscall_arg__scnprintf_eventfd_flags |
| 958 | |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 959 | static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size, |
| 960 | struct syscall_arg *arg) |
| 961 | { |
| 962 | int printed = 0, flags = arg->val; |
| 963 | |
| 964 | #define P_FLAG(n) \ |
| 965 | if (flags & O_##n) { \ |
| 966 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 967 | flags &= ~O_##n; \ |
| 968 | } |
| 969 | |
| 970 | P_FLAG(CLOEXEC); |
| 971 | P_FLAG(NONBLOCK); |
| 972 | #undef P_FLAG |
| 973 | |
| 974 | if (flags) |
| 975 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 976 | |
| 977 | return printed; |
| 978 | } |
| 979 | |
| 980 | #define SCA_PIPE_FLAGS syscall_arg__scnprintf_pipe_flags |
| 981 | |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 982 | static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) |
| 983 | { |
| 984 | int sig = arg->val; |
| 985 | |
| 986 | switch (sig) { |
| 987 | #define P_SIGNUM(n) case SIG##n: return scnprintf(bf, size, #n) |
| 988 | P_SIGNUM(HUP); |
| 989 | P_SIGNUM(INT); |
| 990 | P_SIGNUM(QUIT); |
| 991 | P_SIGNUM(ILL); |
| 992 | P_SIGNUM(TRAP); |
| 993 | P_SIGNUM(ABRT); |
| 994 | P_SIGNUM(BUS); |
| 995 | P_SIGNUM(FPE); |
| 996 | P_SIGNUM(KILL); |
| 997 | P_SIGNUM(USR1); |
| 998 | P_SIGNUM(SEGV); |
| 999 | P_SIGNUM(USR2); |
| 1000 | P_SIGNUM(PIPE); |
| 1001 | P_SIGNUM(ALRM); |
| 1002 | P_SIGNUM(TERM); |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1003 | P_SIGNUM(CHLD); |
| 1004 | P_SIGNUM(CONT); |
| 1005 | P_SIGNUM(STOP); |
| 1006 | P_SIGNUM(TSTP); |
| 1007 | P_SIGNUM(TTIN); |
| 1008 | P_SIGNUM(TTOU); |
| 1009 | P_SIGNUM(URG); |
| 1010 | P_SIGNUM(XCPU); |
| 1011 | P_SIGNUM(XFSZ); |
| 1012 | P_SIGNUM(VTALRM); |
| 1013 | P_SIGNUM(PROF); |
| 1014 | P_SIGNUM(WINCH); |
| 1015 | P_SIGNUM(IO); |
| 1016 | P_SIGNUM(PWR); |
| 1017 | P_SIGNUM(SYS); |
Ben Hutchings | 02c5bb4 | 2014-02-06 01:00:41 +0000 | [diff] [blame] | 1018 | #ifdef SIGEMT |
| 1019 | P_SIGNUM(EMT); |
| 1020 | #endif |
| 1021 | #ifdef SIGSTKFLT |
| 1022 | P_SIGNUM(STKFLT); |
| 1023 | #endif |
| 1024 | #ifdef SIGSWI |
| 1025 | P_SIGNUM(SWI); |
| 1026 | #endif |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1027 | default: break; |
| 1028 | } |
| 1029 | |
| 1030 | return scnprintf(bf, size, "%#x", sig); |
| 1031 | } |
| 1032 | |
| 1033 | #define SCA_SIGNUM syscall_arg__scnprintf_signum |
| 1034 | |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 1035 | #if defined(__i386__) || defined(__x86_64__) |
| 1036 | /* |
| 1037 | * FIXME: Make this available to all arches. |
| 1038 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 1039 | #define TCGETS 0x5401 |
| 1040 | |
| 1041 | static const char *tioctls[] = { |
| 1042 | "TCGETS", "TCSETS", "TCSETSW", "TCSETSF", "TCGETA", "TCSETA", "TCSETAW", |
| 1043 | "TCSETAF", "TCSBRK", "TCXONC", "TCFLSH", "TIOCEXCL", "TIOCNXCL", |
| 1044 | "TIOCSCTTY", "TIOCGPGRP", "TIOCSPGRP", "TIOCOUTQ", "TIOCSTI", |
| 1045 | "TIOCGWINSZ", "TIOCSWINSZ", "TIOCMGET", "TIOCMBIS", "TIOCMBIC", |
| 1046 | "TIOCMSET", "TIOCGSOFTCAR", "TIOCSSOFTCAR", "FIONREAD", "TIOCLINUX", |
| 1047 | "TIOCCONS", "TIOCGSERIAL", "TIOCSSERIAL", "TIOCPKT", "FIONBIO", |
| 1048 | "TIOCNOTTY", "TIOCSETD", "TIOCGETD", "TCSBRKP", [0x27] = "TIOCSBRK", |
| 1049 | "TIOCCBRK", "TIOCGSID", "TCGETS2", "TCSETS2", "TCSETSW2", "TCSETSF2", |
| 1050 | "TIOCGRS485", "TIOCSRS485", "TIOCGPTN", "TIOCSPTLCK", |
| 1051 | "TIOCGDEV||TCGETX", "TCSETX", "TCSETXF", "TCSETXW", "TIOCSIG", |
| 1052 | "TIOCVHANGUP", "TIOCGPKT", "TIOCGPTLCK", "TIOCGEXCL", |
| 1053 | [0x50] = "FIONCLEX", "FIOCLEX", "FIOASYNC", "TIOCSERCONFIG", |
| 1054 | "TIOCSERGWILD", "TIOCSERSWILD", "TIOCGLCKTRMIOS", "TIOCSLCKTRMIOS", |
| 1055 | "TIOCSERGSTRUCT", "TIOCSERGETLSR", "TIOCSERGETMULTI", "TIOCSERSETMULTI", |
| 1056 | "TIOCMIWAIT", "TIOCGICOUNT", [0x60] = "FIOQSIZE", |
| 1057 | }; |
| 1058 | |
| 1059 | static DEFINE_STRARRAY_OFFSET(tioctls, 0x5401); |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 1060 | #endif /* defined(__i386__) || defined(__x86_64__) */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 1061 | |
Arnaldo Carvalho de Melo | 6fb35b9 | 2016-04-13 11:50:23 -0300 | [diff] [blame^] | 1062 | #ifndef SECCOMP_SET_MODE_STRICT |
| 1063 | #define SECCOMP_SET_MODE_STRICT 0 |
| 1064 | #endif |
| 1065 | #ifndef SECCOMP_SET_MODE_FILTER |
| 1066 | #define SECCOMP_SET_MODE_FILTER 1 |
| 1067 | #endif |
| 1068 | |
Arnaldo Carvalho de Melo | 997bba8 | 2016-03-30 19:43:32 -0300 | [diff] [blame] | 1069 | static size_t syscall_arg__scnprintf_seccomp_op(char *bf, size_t size, struct syscall_arg *arg) |
| 1070 | { |
| 1071 | int op = arg->val; |
| 1072 | size_t printed = 0; |
| 1073 | |
| 1074 | switch (op) { |
| 1075 | #define P_SECCOMP_SET_MODE_OP(n) case SECCOMP_SET_MODE_##n: printed = scnprintf(bf, size, #n); break |
| 1076 | P_SECCOMP_SET_MODE_OP(STRICT); |
| 1077 | P_SECCOMP_SET_MODE_OP(FILTER); |
| 1078 | #undef P_SECCOMP_SET_MODE_OP |
| 1079 | default: printed = scnprintf(bf, size, "%#x", op); break; |
| 1080 | } |
| 1081 | |
| 1082 | return printed; |
| 1083 | } |
| 1084 | |
| 1085 | #define SCA_SECCOMP_OP syscall_arg__scnprintf_seccomp_op |
| 1086 | |
Arnaldo Carvalho de Melo | 6fb35b9 | 2016-04-13 11:50:23 -0300 | [diff] [blame^] | 1087 | #ifndef SECCOMP_FILTER_FLAG_TSYNC |
| 1088 | #define SECCOMP_FILTER_FLAG_TSYNC 1 |
| 1089 | #endif |
| 1090 | |
Arnaldo Carvalho de Melo | 997bba8 | 2016-03-30 19:43:32 -0300 | [diff] [blame] | 1091 | static size_t syscall_arg__scnprintf_seccomp_flags(char *bf, size_t size, |
| 1092 | struct syscall_arg *arg) |
| 1093 | { |
| 1094 | int printed = 0, flags = arg->val; |
| 1095 | |
| 1096 | #define P_FLAG(n) \ |
| 1097 | if (flags & SECCOMP_FILTER_FLAG_##n) { \ |
| 1098 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 1099 | flags &= ~SECCOMP_FILTER_FLAG_##n; \ |
| 1100 | } |
| 1101 | |
| 1102 | P_FLAG(TSYNC); |
| 1103 | #undef P_FLAG |
| 1104 | |
| 1105 | if (flags) |
| 1106 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 1107 | |
| 1108 | return printed; |
| 1109 | } |
| 1110 | |
| 1111 | #define SCA_SECCOMP_FLAGS syscall_arg__scnprintf_seccomp_flags |
| 1112 | |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 1113 | static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size, |
| 1114 | struct syscall_arg *arg) |
| 1115 | { |
| 1116 | int printed = 0, flags = arg->val; |
| 1117 | |
| 1118 | #define P_FLAG(n) \ |
| 1119 | if (flags & GRND_##n) { \ |
| 1120 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 1121 | flags &= ~GRND_##n; \ |
| 1122 | } |
| 1123 | |
| 1124 | P_FLAG(RANDOM); |
| 1125 | P_FLAG(NONBLOCK); |
| 1126 | #undef P_FLAG |
| 1127 | |
| 1128 | if (flags) |
| 1129 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 1130 | |
| 1131 | return printed; |
| 1132 | } |
| 1133 | |
| 1134 | #define SCA_GETRANDOM_FLAGS syscall_arg__scnprintf_getrandom_flags |
| 1135 | |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1136 | #define STRARRAY(arg, name, array) \ |
| 1137 | .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \ |
| 1138 | .arg_parm = { [arg] = &strarray__##array, } |
| 1139 | |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 1140 | #include "trace/beauty/pid.c" |
Arnaldo Carvalho de Melo | ba2f22c | 2016-04-07 12:05:51 -0300 | [diff] [blame] | 1141 | #include "trace/beauty/mode_t.c" |
Arnaldo Carvalho de Melo | a3bca91 | 2016-04-06 12:51:33 -0300 | [diff] [blame] | 1142 | #include "trace/beauty/sched_policy.c" |
Arnaldo Carvalho de Melo | 7206b90 | 2016-04-06 14:11:36 -0300 | [diff] [blame] | 1143 | #include "trace/beauty/waitid_options.c" |
Arnaldo Carvalho de Melo | a3bca91 | 2016-04-06 12:51:33 -0300 | [diff] [blame] | 1144 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1145 | static struct syscall_fmt { |
| 1146 | const char *name; |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1147 | const char *alias; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1148 | size_t (*arg_scnprintf[6])(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1149 | void *arg_parm[6]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1150 | bool errmsg; |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 1151 | bool errpid; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1152 | bool timeout; |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 1153 | bool hexret; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1154 | } syscall_fmts[] = { |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 1155 | { .name = "access", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1156 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ |
| 1157 | [1] = SCA_ACCMODE, /* mode */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1158 | { .name = "arch_prctl", .errmsg = true, .alias = "prctl", }, |
Arnaldo Carvalho de Melo | 729a784 | 2015-10-29 11:48:18 -0300 | [diff] [blame] | 1159 | { .name = "bpf", .errmsg = true, STRARRAY(0, cmd, bpf_cmd), }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1160 | { .name = "brk", .hexret = true, |
| 1161 | .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1162 | { .name = "chdir", .errmsg = true, |
| 1163 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
| 1164 | { .name = "chmod", .errmsg = true, |
| 1165 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
| 1166 | { .name = "chroot", .errmsg = true, |
| 1167 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 1168 | { .name = "clock_gettime", .errmsg = true, STRARRAY(0, clk_id, clockid), }, |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 1169 | { .name = "clone", .errpid = true, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1170 | { .name = "close", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1171 | .arg_scnprintf = { [0] = SCA_CLOSE_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | a14bb86 | 2013-07-30 16:38:23 -0300 | [diff] [blame] | 1172 | { .name = "connect", .errmsg = true, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1173 | { .name = "creat", .errmsg = true, |
| 1174 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1175 | { .name = "dup", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1176 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1177 | { .name = "dup2", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1178 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1179 | { .name = "dup3", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1180 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1181 | { .name = "epoll_ctl", .errmsg = true, STRARRAY(1, op, epoll_ctl_ops), }, |
Arnaldo Carvalho de Melo | 49af9e9 | 2013-09-12 12:18:56 -0300 | [diff] [blame] | 1182 | { .name = "eventfd2", .errmsg = true, |
| 1183 | .arg_scnprintf = { [1] = SCA_EFD_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1184 | { .name = "faccessat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1185 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1186 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1187 | { .name = "fadvise64", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1188 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1189 | { .name = "fallocate", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1190 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1191 | { .name = "fchdir", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1192 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1193 | { .name = "fchmod", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1194 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1195 | { .name = "fchmodat", .errmsg = true, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1196 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ |
| 1197 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1198 | { .name = "fchown", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1199 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1200 | { .name = "fchownat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1201 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ |
| 1202 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1203 | { .name = "fcntl", .errmsg = true, |
| 1204 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1205 | [1] = SCA_STRARRAY, /* cmd */ }, |
| 1206 | .arg_parm = { [1] = &strarray__fcntl_cmds, /* cmd */ }, }, |
| 1207 | { .name = "fdatasync", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1208 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 5cea6ff | 2013-09-20 11:49:50 -0300 | [diff] [blame] | 1209 | { .name = "flock", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1210 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1211 | [1] = SCA_FLOCK, /* cmd */ }, }, |
| 1212 | { .name = "fsetxattr", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1213 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1214 | { .name = "fstat", .errmsg = true, .alias = "newfstat", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1215 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1216 | { .name = "fstatat", .errmsg = true, .alias = "newfstatat", |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1217 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1218 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1219 | { .name = "fstatfs", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1220 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1221 | { .name = "fsync", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1222 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1223 | { .name = "ftruncate", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1224 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 1225 | { .name = "futex", .errmsg = true, |
| 1226 | .arg_scnprintf = { [1] = SCA_FUTEX_OP, /* op */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1227 | { .name = "futimesat", .errmsg = true, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1228 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ |
| 1229 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1230 | { .name = "getdents", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1231 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1232 | { .name = "getdents64", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1233 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1234 | { .name = "getitimer", .errmsg = true, STRARRAY(0, which, itimers), }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 1235 | { .name = "getpid", .errpid = true, }, |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 1236 | { .name = "getpgid", .errpid = true, }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 1237 | { .name = "getppid", .errpid = true, }, |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 1238 | { .name = "getrandom", .errmsg = true, |
| 1239 | .arg_scnprintf = { [2] = SCA_GETRANDOM_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1240 | { .name = "getrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1241 | { .name = "getxattr", .errmsg = true, |
| 1242 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
| 1243 | { .name = "inotify_add_watch", .errmsg = true, |
| 1244 | .arg_scnprintf = { [1] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1245 | { .name = "ioctl", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1246 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 1247 | #if defined(__i386__) || defined(__x86_64__) |
| 1248 | /* |
| 1249 | * FIXME: Make this available to all arches. |
| 1250 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 1251 | [1] = SCA_STRHEXARRAY, /* cmd */ |
| 1252 | [2] = SCA_HEX, /* arg */ }, |
| 1253 | .arg_parm = { [1] = &strarray__tioctls, /* cmd */ }, }, |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 1254 | #else |
| 1255 | [2] = SCA_HEX, /* arg */ }, }, |
| 1256 | #endif |
Arnaldo Carvalho de Melo | b62bee1 | 2015-08-11 11:05:36 -0300 | [diff] [blame] | 1257 | { .name = "keyctl", .errmsg = true, STRARRAY(0, option, keyctl_options), }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1258 | { .name = "kill", .errmsg = true, |
| 1259 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1260 | { .name = "lchown", .errmsg = true, |
| 1261 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
| 1262 | { .name = "lgetxattr", .errmsg = true, |
| 1263 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1264 | { .name = "linkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1265 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1266 | { .name = "listxattr", .errmsg = true, |
| 1267 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1268 | { .name = "llistxattr", .errmsg = true, |
| 1269 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
| 1270 | { .name = "lremovexattr", .errmsg = true, |
| 1271 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1272 | { .name = "lseek", .errmsg = true, |
| 1273 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1274 | [2] = SCA_STRARRAY, /* whence */ }, |
| 1275 | .arg_parm = { [2] = &strarray__whences, /* whence */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1276 | { .name = "lsetxattr", .errmsg = true, |
| 1277 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1278 | { .name = "lstat", .errmsg = true, .alias = "newlstat", |
| 1279 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1280 | { .name = "lsxattr", .errmsg = true, |
| 1281 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 1282 | { .name = "madvise", .errmsg = true, |
| 1283 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 1284 | [2] = SCA_MADV_BHV, /* behavior */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1285 | { .name = "mkdir", .errmsg = true, |
| 1286 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1287 | { .name = "mkdirat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1288 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ |
| 1289 | [1] = SCA_FILENAME, /* pathname */ }, }, |
| 1290 | { .name = "mknod", .errmsg = true, |
| 1291 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1292 | { .name = "mknodat", .errmsg = true, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1293 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ |
| 1294 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 3d903aa | 2013-09-24 00:09:38 -0300 | [diff] [blame] | 1295 | { .name = "mlock", .errmsg = true, |
| 1296 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
| 1297 | { .name = "mlockall", .errmsg = true, |
| 1298 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1299 | { .name = "mmap", .hexret = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1300 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 1301 | [2] = SCA_MMAP_PROT, /* prot */ |
Namhyung Kim | 73faab3 | 2013-11-12 15:24:59 +0900 | [diff] [blame] | 1302 | [3] = SCA_MMAP_FLAGS, /* flags */ |
| 1303 | [4] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1304 | { .name = "mprotect", .errmsg = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1305 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 1306 | [2] = SCA_MMAP_PROT, /* prot */ }, }, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1307 | { .name = "mq_unlink", .errmsg = true, |
| 1308 | .arg_scnprintf = { [0] = SCA_FILENAME, /* u_name */ }, }, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1309 | { .name = "mremap", .hexret = true, |
| 1310 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
Alex Snast | 86998dd | 2014-08-13 18:42:40 +0300 | [diff] [blame] | 1311 | [3] = SCA_MREMAP_FLAGS, /* flags */ |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1312 | [4] = SCA_HEX, /* new_addr */ }, }, |
Arnaldo Carvalho de Melo | 3d903aa | 2013-09-24 00:09:38 -0300 | [diff] [blame] | 1313 | { .name = "munlock", .errmsg = true, |
| 1314 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1315 | { .name = "munmap", .errmsg = true, |
| 1316 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1317 | { .name = "name_to_handle_at", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1318 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1319 | { .name = "newfstatat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1320 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1321 | [1] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 1322 | { .name = "open", .errmsg = true, |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1323 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ |
| 1324 | [1] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame] | 1325 | { .name = "open_by_handle_at", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1326 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1327 | [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame] | 1328 | { .name = "openat", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1329 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1330 | [1] = SCA_FILENAME, /* filename */ |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1331 | [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 1332 | { .name = "perf_event_open", .errmsg = true, |
| 1333 | .arg_scnprintf = { [1] = SCA_INT, /* pid */ |
| 1334 | [2] = SCA_INT, /* cpu */ |
| 1335 | [3] = SCA_FD, /* group_fd */ |
| 1336 | [4] = SCA_PERF_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 1337 | { .name = "pipe2", .errmsg = true, |
| 1338 | .arg_scnprintf = { [1] = SCA_PIPE_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1339 | { .name = "poll", .errmsg = true, .timeout = true, }, |
| 1340 | { .name = "ppoll", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1341 | { .name = "pread", .errmsg = true, .alias = "pread64", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1342 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1343 | { .name = "preadv", .errmsg = true, .alias = "pread", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1344 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1345 | { .name = "prlimit64", .errmsg = true, STRARRAY(1, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1346 | { .name = "pwrite", .errmsg = true, .alias = "pwrite64", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1347 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1348 | { .name = "pwritev", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1349 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1350 | { .name = "read", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1351 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1352 | { .name = "readlink", .errmsg = true, |
| 1353 | .arg_scnprintf = { [0] = SCA_FILENAME, /* path */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1354 | { .name = "readlinkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1355 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1356 | [1] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1357 | { .name = "readv", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1358 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1359 | { .name = "recvfrom", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1360 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1361 | [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1362 | { .name = "recvmmsg", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1363 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1364 | [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1365 | { .name = "recvmsg", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1366 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1367 | [2] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1368 | { .name = "removexattr", .errmsg = true, |
| 1369 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1370 | { .name = "renameat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1371 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1372 | { .name = "rmdir", .errmsg = true, |
| 1373 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1374 | { .name = "rt_sigaction", .errmsg = true, |
| 1375 | .arg_scnprintf = { [0] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1376 | { .name = "rt_sigprocmask", .errmsg = true, STRARRAY(0, how, sighow), }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1377 | { .name = "rt_sigqueueinfo", .errmsg = true, |
| 1378 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
| 1379 | { .name = "rt_tgsigqueueinfo", .errmsg = true, |
| 1380 | .arg_scnprintf = { [2] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | a3bca91 | 2016-04-06 12:51:33 -0300 | [diff] [blame] | 1381 | { .name = "sched_setscheduler", .errmsg = true, |
| 1382 | .arg_scnprintf = { [1] = SCA_SCHED_POLICY, /* policy */ }, }, |
Arnaldo Carvalho de Melo | 997bba8 | 2016-03-30 19:43:32 -0300 | [diff] [blame] | 1383 | { .name = "seccomp", .errmsg = true, |
| 1384 | .arg_scnprintf = { [0] = SCA_SECCOMP_OP, /* op */ |
| 1385 | [1] = SCA_SECCOMP_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1386 | { .name = "select", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1387 | { .name = "sendmmsg", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1388 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1389 | [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1390 | { .name = "sendmsg", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1391 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1392 | [2] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1393 | { .name = "sendto", .errmsg = true, |
Arnaldo Carvalho de Melo | 8d8c66a | 2015-08-11 10:57:02 -0300 | [diff] [blame] | 1394 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1395 | [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 1396 | { .name = "set_tid_address", .errpid = true, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1397 | { .name = "setitimer", .errmsg = true, STRARRAY(0, which, itimers), }, |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 1398 | { .name = "setpgid", .errmsg = true, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1399 | { .name = "setrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1400 | { .name = "setxattr", .errmsg = true, |
| 1401 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1402 | { .name = "shutdown", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1403 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 1404 | { .name = "socket", .errmsg = true, |
Arnaldo Carvalho de Melo | a28b24b | 2013-09-04 11:00:44 -0300 | [diff] [blame] | 1405 | .arg_scnprintf = { [0] = SCA_STRARRAY, /* family */ |
| 1406 | [1] = SCA_SK_TYPE, /* type */ }, |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 1407 | .arg_parm = { [0] = &strarray__socket_families, /* family */ }, }, |
Arnaldo Carvalho de Melo | 07120aa | 2013-09-20 12:24:20 -0300 | [diff] [blame] | 1408 | { .name = "socketpair", .errmsg = true, |
| 1409 | .arg_scnprintf = { [0] = SCA_STRARRAY, /* family */ |
| 1410 | [1] = SCA_SK_TYPE, /* type */ }, |
| 1411 | .arg_parm = { [0] = &strarray__socket_families, /* family */ }, }, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1412 | { .name = "stat", .errmsg = true, .alias = "newstat", |
| 1413 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1414 | { .name = "statfs", .errmsg = true, |
| 1415 | .arg_scnprintf = { [0] = SCA_FILENAME, /* pathname */ }, }, |
| 1416 | { .name = "swapoff", .errmsg = true, |
| 1417 | .arg_scnprintf = { [0] = SCA_FILENAME, /* specialfile */ }, }, |
| 1418 | { .name = "swapon", .errmsg = true, |
| 1419 | .arg_scnprintf = { [0] = SCA_FILENAME, /* specialfile */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1420 | { .name = "symlinkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1421 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1422 | { .name = "tgkill", .errmsg = true, |
| 1423 | .arg_scnprintf = { [2] = SCA_SIGNUM, /* sig */ }, }, |
| 1424 | { .name = "tkill", .errmsg = true, |
| 1425 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1426 | { .name = "truncate", .errmsg = true, |
| 1427 | .arg_scnprintf = { [0] = SCA_FILENAME, /* path */ }, }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 1428 | { .name = "uname", .errmsg = true, .alias = "newuname", }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1429 | { .name = "unlinkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1430 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1431 | [1] = SCA_FILENAME, /* pathname */ }, }, |
| 1432 | { .name = "utime", .errmsg = true, |
| 1433 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1434 | { .name = "utimensat", .errmsg = true, |
Arnaldo Carvalho de Melo | 3422111 | 2015-08-04 23:31:25 -0300 | [diff] [blame] | 1435 | .arg_scnprintf = { [0] = SCA_FDAT, /* dirfd */ |
| 1436 | [1] = SCA_FILENAME, /* filename */ }, }, |
| 1437 | { .name = "utimes", .errmsg = true, |
| 1438 | .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */ }, }, |
Arnaldo Carvalho de Melo | 090389b6 | 2015-08-10 19:20:52 -0300 | [diff] [blame] | 1439 | { .name = "vmsplice", .errmsg = true, |
| 1440 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 1441 | { .name = "wait4", .errpid = true, |
Arnaldo Carvalho de Melo | 7206b90 | 2016-04-06 14:11:36 -0300 | [diff] [blame] | 1442 | .arg_scnprintf = { [2] = SCA_WAITID_OPTIONS, /* options */ }, }, |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 1443 | { .name = "waitid", .errpid = true, |
Arnaldo Carvalho de Melo | 7206b90 | 2016-04-06 14:11:36 -0300 | [diff] [blame] | 1444 | .arg_scnprintf = { [3] = SCA_WAITID_OPTIONS, /* options */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1445 | { .name = "write", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1446 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1447 | { .name = "writev", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1448 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1449 | }; |
| 1450 | |
| 1451 | static int syscall_fmt__cmp(const void *name, const void *fmtp) |
| 1452 | { |
| 1453 | const struct syscall_fmt *fmt = fmtp; |
| 1454 | return strcmp(name, fmt->name); |
| 1455 | } |
| 1456 | |
| 1457 | static struct syscall_fmt *syscall_fmt__find(const char *name) |
| 1458 | { |
| 1459 | const int nmemb = ARRAY_SIZE(syscall_fmts); |
| 1460 | return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); |
| 1461 | } |
| 1462 | |
| 1463 | struct syscall { |
| 1464 | struct event_format *tp_format; |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1465 | int nr_args; |
| 1466 | struct format_field *args; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1467 | const char *name; |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1468 | bool is_exit; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1469 | struct syscall_fmt *fmt; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1470 | size_t (**arg_scnprintf)(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1471 | void **arg_parm; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1472 | }; |
| 1473 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1474 | static size_t fprintf_duration(unsigned long t, FILE *fp) |
| 1475 | { |
| 1476 | double duration = (double)t / NSEC_PER_MSEC; |
| 1477 | size_t printed = fprintf(fp, "("); |
| 1478 | |
| 1479 | if (duration >= 1.0) |
| 1480 | printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); |
| 1481 | else if (duration >= 0.01) |
| 1482 | printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); |
| 1483 | else |
| 1484 | printed += color_fprintf(fp, PERF_COLOR_NORMAL, "%6.3f ms", duration); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1485 | return printed + fprintf(fp, "): "); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1486 | } |
| 1487 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1488 | /** |
| 1489 | * filename.ptr: The filename char pointer that will be vfs_getname'd |
| 1490 | * filename.entry_str_pos: Where to insert the string translated from |
| 1491 | * filename.ptr by the vfs_getname tracepoint/kprobe. |
| 1492 | */ |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1493 | struct thread_trace { |
| 1494 | u64 entry_time; |
| 1495 | u64 exit_time; |
| 1496 | bool entry_pending; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1497 | unsigned long nr_events; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 1498 | unsigned long pfmaj, pfmin; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1499 | char *entry_str; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1500 | double runtime_ms; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1501 | struct { |
| 1502 | unsigned long ptr; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 1503 | short int entry_str_pos; |
| 1504 | bool pending_open; |
| 1505 | unsigned int namelen; |
| 1506 | char *name; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1507 | } filename; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1508 | struct { |
| 1509 | int max; |
| 1510 | char **table; |
| 1511 | } paths; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1512 | |
| 1513 | struct intlist *syscall_stats; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1514 | }; |
| 1515 | |
| 1516 | static struct thread_trace *thread_trace__new(void) |
| 1517 | { |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1518 | struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); |
| 1519 | |
| 1520 | if (ttrace) |
| 1521 | ttrace->paths.max = -1; |
| 1522 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1523 | ttrace->syscall_stats = intlist__new(NULL); |
| 1524 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1525 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1526 | } |
| 1527 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1528 | static struct thread_trace *thread__trace(struct thread *thread, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1529 | { |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1530 | struct thread_trace *ttrace; |
| 1531 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1532 | if (thread == NULL) |
| 1533 | goto fail; |
| 1534 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1535 | if (thread__priv(thread) == NULL) |
| 1536 | thread__set_priv(thread, thread_trace__new()); |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1537 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1538 | if (thread__priv(thread) == NULL) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1539 | goto fail; |
| 1540 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1541 | ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1542 | ++ttrace->nr_events; |
| 1543 | |
| 1544 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1545 | fail: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1546 | color_fprintf(fp, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1547 | "WARNING: not enough memory, dropping samples!\n"); |
| 1548 | return NULL; |
| 1549 | } |
| 1550 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1551 | #define TRACE_PFMAJ (1 << 0) |
| 1552 | #define TRACE_PFMIN (1 << 1) |
| 1553 | |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 1554 | static const size_t trace__entry_str_size = 2048; |
| 1555 | |
Arnaldo Carvalho de Melo | 97119f3 | 2013-09-27 17:34:10 -0300 | [diff] [blame] | 1556 | static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1557 | { |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1558 | struct thread_trace *ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1559 | |
| 1560 | if (fd > ttrace->paths.max) { |
| 1561 | char **npath = realloc(ttrace->paths.table, (fd + 1) * sizeof(char *)); |
| 1562 | |
| 1563 | if (npath == NULL) |
| 1564 | return -1; |
| 1565 | |
| 1566 | if (ttrace->paths.max != -1) { |
| 1567 | memset(npath + ttrace->paths.max + 1, 0, |
| 1568 | (fd - ttrace->paths.max) * sizeof(char *)); |
| 1569 | } else { |
| 1570 | memset(npath, 0, (fd + 1) * sizeof(char *)); |
| 1571 | } |
| 1572 | |
| 1573 | ttrace->paths.table = npath; |
| 1574 | ttrace->paths.max = fd; |
| 1575 | } |
| 1576 | |
| 1577 | ttrace->paths.table[fd] = strdup(pathname); |
| 1578 | |
| 1579 | return ttrace->paths.table[fd] != NULL ? 0 : -1; |
| 1580 | } |
| 1581 | |
Arnaldo Carvalho de Melo | 97119f3 | 2013-09-27 17:34:10 -0300 | [diff] [blame] | 1582 | static int thread__read_fd_path(struct thread *thread, int fd) |
| 1583 | { |
| 1584 | char linkname[PATH_MAX], pathname[PATH_MAX]; |
| 1585 | struct stat st; |
| 1586 | int ret; |
| 1587 | |
| 1588 | if (thread->pid_ == thread->tid) { |
| 1589 | scnprintf(linkname, sizeof(linkname), |
| 1590 | "/proc/%d/fd/%d", thread->pid_, fd); |
| 1591 | } else { |
| 1592 | scnprintf(linkname, sizeof(linkname), |
| 1593 | "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd); |
| 1594 | } |
| 1595 | |
| 1596 | if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname)) |
| 1597 | return -1; |
| 1598 | |
| 1599 | ret = readlink(linkname, pathname, sizeof(pathname)); |
| 1600 | |
| 1601 | if (ret < 0 || ret > st.st_size) |
| 1602 | return -1; |
| 1603 | |
| 1604 | pathname[ret] = '\0'; |
| 1605 | return trace__set_fd_pathname(thread, fd, pathname); |
| 1606 | } |
| 1607 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1608 | static const char *thread__fd_path(struct thread *thread, int fd, |
| 1609 | struct trace *trace) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1610 | { |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1611 | struct thread_trace *ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1612 | |
| 1613 | if (ttrace == NULL) |
| 1614 | return NULL; |
| 1615 | |
| 1616 | if (fd < 0) |
| 1617 | return NULL; |
| 1618 | |
Arnaldo Carvalho de Melo | cdcd1e6 | 2014-06-10 16:00:18 -0300 | [diff] [blame] | 1619 | if ((fd > ttrace->paths.max || ttrace->paths.table[fd] == NULL)) { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1620 | if (!trace->live) |
| 1621 | return NULL; |
| 1622 | ++trace->stats.proc_getname; |
Arnaldo Carvalho de Melo | cdcd1e6 | 2014-06-10 16:00:18 -0300 | [diff] [blame] | 1623 | if (thread__read_fd_path(thread, fd)) |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1624 | return NULL; |
| 1625 | } |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1626 | |
| 1627 | return ttrace->paths.table[fd]; |
| 1628 | } |
| 1629 | |
| 1630 | static size_t syscall_arg__scnprintf_fd(char *bf, size_t size, |
| 1631 | struct syscall_arg *arg) |
| 1632 | { |
| 1633 | int fd = arg->val; |
| 1634 | size_t printed = scnprintf(bf, size, "%d", fd); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1635 | const char *path = thread__fd_path(arg->thread, fd, arg->trace); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1636 | |
| 1637 | if (path) |
| 1638 | printed += scnprintf(bf + printed, size - printed, "<%s>", path); |
| 1639 | |
| 1640 | return printed; |
| 1641 | } |
| 1642 | |
| 1643 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 1644 | struct syscall_arg *arg) |
| 1645 | { |
| 1646 | int fd = arg->val; |
| 1647 | size_t printed = syscall_arg__scnprintf_fd(bf, size, arg); |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1648 | struct thread_trace *ttrace = thread__priv(arg->thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1649 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1650 | if (ttrace && fd >= 0 && fd <= ttrace->paths.max) |
| 1651 | zfree(&ttrace->paths.table[fd]); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1652 | |
| 1653 | return printed; |
| 1654 | } |
| 1655 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1656 | static void thread__set_filename_pos(struct thread *thread, const char *bf, |
| 1657 | unsigned long ptr) |
| 1658 | { |
| 1659 | struct thread_trace *ttrace = thread__priv(thread); |
| 1660 | |
| 1661 | ttrace->filename.ptr = ptr; |
| 1662 | ttrace->filename.entry_str_pos = bf - ttrace->entry_str; |
| 1663 | } |
| 1664 | |
| 1665 | static size_t syscall_arg__scnprintf_filename(char *bf, size_t size, |
| 1666 | struct syscall_arg *arg) |
| 1667 | { |
| 1668 | unsigned long ptr = arg->val; |
| 1669 | |
| 1670 | if (!arg->trace->vfs_getname) |
| 1671 | return scnprintf(bf, size, "%#x", ptr); |
| 1672 | |
| 1673 | thread__set_filename_pos(arg->thread, bf, ptr); |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1677 | static bool trace__filter_duration(struct trace *trace, double t) |
| 1678 | { |
| 1679 | return t < (trace->duration_filter * NSEC_PER_MSEC); |
| 1680 | } |
| 1681 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1682 | static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
| 1683 | { |
| 1684 | double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; |
| 1685 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1686 | return fprintf(fp, "%10.3f ", ts); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1687 | } |
| 1688 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1689 | static bool done = false; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1690 | static bool interrupted = false; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1691 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1692 | static void sig_handler(int sig) |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1693 | { |
| 1694 | done = true; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1695 | interrupted = sig == SIGINT; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1696 | } |
| 1697 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1698 | static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1699 | u64 duration, u64 tstamp, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1700 | { |
| 1701 | size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1702 | printed += fprintf_duration(duration, fp); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1703 | |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1704 | if (trace->multiple_threads) { |
| 1705 | if (trace->show_comm) |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 1706 | printed += fprintf(fp, "%.14s/", thread__comm_str(thread)); |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1707 | printed += fprintf(fp, "%d ", thread->tid); |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1708 | } |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1709 | |
| 1710 | return printed; |
| 1711 | } |
| 1712 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1713 | static int trace__process_event(struct trace *trace, struct machine *machine, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1714 | union perf_event *event, struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1715 | { |
| 1716 | int ret = 0; |
| 1717 | |
| 1718 | switch (event->header.type) { |
| 1719 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1720 | color_fprintf(trace->output, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1721 | "LOST %" PRIu64 " events!\n", event->lost.lost); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1722 | ret = machine__process_lost_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 3ed5ca2 | 2016-03-30 16:51:17 -0300 | [diff] [blame] | 1723 | break; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1724 | default: |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1725 | ret = machine__process_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1726 | break; |
| 1727 | } |
| 1728 | |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1732 | static int trace__tool_process(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1733 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1734 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1735 | struct machine *machine) |
| 1736 | { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1737 | struct trace *trace = container_of(tool, struct trace, tool); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1738 | return trace__process_event(trace, machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) |
| 1742 | { |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1743 | int err = symbol__init(NULL); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1744 | |
| 1745 | if (err) |
| 1746 | return err; |
| 1747 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1748 | trace->host = machine__new_host(); |
| 1749 | if (trace->host == NULL) |
| 1750 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1751 | |
Arnaldo Carvalho de Melo | 959c219 | 2015-07-24 12:13:05 -0300 | [diff] [blame] | 1752 | if (trace_event__register_resolver(trace->host, machine__resolve_kernel_addr) < 0) |
Arnaldo Carvalho de Melo | 706c3da | 2015-07-22 16:16:16 -0300 | [diff] [blame] | 1753 | return -errno; |
| 1754 | |
Arnaldo Carvalho de Melo | a33fbd5 | 2013-11-11 11:36:12 -0300 | [diff] [blame] | 1755 | err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 1756 | evlist->threads, trace__tool_process, false, |
| 1757 | trace->opts.proc_map_timeout); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1758 | if (err) |
| 1759 | symbol__exit(); |
| 1760 | |
| 1761 | return err; |
| 1762 | } |
| 1763 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1764 | static int syscall__set_arg_fmts(struct syscall *sc) |
| 1765 | { |
| 1766 | struct format_field *field; |
| 1767 | int idx = 0; |
| 1768 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1769 | sc->arg_scnprintf = calloc(sc->nr_args, sizeof(void *)); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1770 | if (sc->arg_scnprintf == NULL) |
| 1771 | return -1; |
| 1772 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1773 | if (sc->fmt) |
| 1774 | sc->arg_parm = sc->fmt->arg_parm; |
| 1775 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1776 | for (field = sc->args; field; field = field->next) { |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1777 | if (sc->fmt && sc->fmt->arg_scnprintf[idx]) |
| 1778 | sc->arg_scnprintf[idx] = sc->fmt->arg_scnprintf[idx]; |
| 1779 | else if (field->flags & FIELD_IS_POINTER) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1780 | sc->arg_scnprintf[idx] = syscall_arg__scnprintf_hex; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 1781 | else if (strcmp(field->type, "pid_t") == 0) |
| 1782 | sc->arg_scnprintf[idx] = SCA_PID; |
Arnaldo Carvalho de Melo | ba2f22c | 2016-04-07 12:05:51 -0300 | [diff] [blame] | 1783 | else if (strcmp(field->type, "umode_t") == 0) |
| 1784 | sc->arg_scnprintf[idx] = SCA_MODE_T; |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1785 | ++idx; |
| 1786 | } |
| 1787 | |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1791 | static int trace__read_syscall_info(struct trace *trace, int id) |
| 1792 | { |
| 1793 | char tp_name[128]; |
| 1794 | struct syscall *sc; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 1795 | const char *name = syscalltbl__name(trace->sctbl, id); |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1796 | |
| 1797 | if (name == NULL) |
| 1798 | return -1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1799 | |
| 1800 | if (id > trace->syscalls.max) { |
| 1801 | struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); |
| 1802 | |
| 1803 | if (nsyscalls == NULL) |
| 1804 | return -1; |
| 1805 | |
| 1806 | if (trace->syscalls.max != -1) { |
| 1807 | memset(nsyscalls + trace->syscalls.max + 1, 0, |
| 1808 | (id - trace->syscalls.max) * sizeof(*sc)); |
| 1809 | } else { |
| 1810 | memset(nsyscalls, 0, (id + 1) * sizeof(*sc)); |
| 1811 | } |
| 1812 | |
| 1813 | trace->syscalls.table = nsyscalls; |
| 1814 | trace->syscalls.max = id; |
| 1815 | } |
| 1816 | |
| 1817 | sc = trace->syscalls.table + id; |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1818 | sc->name = name; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1819 | |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1820 | sc->fmt = syscall_fmt__find(sc->name); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1821 | |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1822 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1823 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1824 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 1825 | if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) { |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1826 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1827 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1828 | } |
| 1829 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 1830 | if (IS_ERR(sc->tp_format)) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1831 | return -1; |
| 1832 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1833 | sc->args = sc->tp_format->format.fields; |
| 1834 | sc->nr_args = sc->tp_format->format.nr_fields; |
Taeung Song | c42de70 | 2016-02-26 22:14:25 +0900 | [diff] [blame] | 1835 | /* |
| 1836 | * We need to check and discard the first variable '__syscall_nr' |
| 1837 | * or 'nr' that mean the syscall number. It is needless here. |
| 1838 | * So drop '__syscall_nr' or 'nr' field but does not exist on older kernels. |
| 1839 | */ |
| 1840 | if (sc->args && (!strcmp(sc->args->name, "__syscall_nr") || !strcmp(sc->args->name, "nr"))) { |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1841 | sc->args = sc->args->next; |
| 1842 | --sc->nr_args; |
| 1843 | } |
| 1844 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1845 | sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); |
| 1846 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1847 | return syscall__set_arg_fmts(sc); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1848 | } |
| 1849 | |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1850 | static int trace__validate_ev_qualifier(struct trace *trace) |
| 1851 | { |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1852 | int err = 0, i; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1853 | struct str_node *pos; |
| 1854 | |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1855 | trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier); |
| 1856 | trace->ev_qualifier_ids.entries = malloc(trace->ev_qualifier_ids.nr * |
| 1857 | sizeof(trace->ev_qualifier_ids.entries[0])); |
| 1858 | |
| 1859 | if (trace->ev_qualifier_ids.entries == NULL) { |
| 1860 | fputs("Error:\tNot enough memory for allocating events qualifier ids\n", |
| 1861 | trace->output); |
| 1862 | err = -EINVAL; |
| 1863 | goto out; |
| 1864 | } |
| 1865 | |
| 1866 | i = 0; |
| 1867 | |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1868 | strlist__for_each(pos, trace->ev_qualifier) { |
| 1869 | const char *sc = pos->s; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 1870 | int id = syscalltbl__id(trace->sctbl, sc); |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1871 | |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1872 | if (id < 0) { |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1873 | if (err == 0) { |
| 1874 | fputs("Error:\tInvalid syscall ", trace->output); |
| 1875 | err = -EINVAL; |
| 1876 | } else { |
| 1877 | fputs(", ", trace->output); |
| 1878 | } |
| 1879 | |
| 1880 | fputs(sc, trace->output); |
| 1881 | } |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1882 | |
| 1883 | trace->ev_qualifier_ids.entries[i++] = id; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | if (err < 0) { |
| 1887 | fputs("\nHint:\ttry 'perf list syscalls:sys_enter_*'" |
| 1888 | "\nHint:\tand: 'man syscalls'\n", trace->output); |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1889 | zfree(&trace->ev_qualifier_ids.entries); |
| 1890 | trace->ev_qualifier_ids.nr = 0; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1891 | } |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1892 | out: |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1893 | return err; |
| 1894 | } |
| 1895 | |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1896 | /* |
| 1897 | * args is to be interpreted as a series of longs but we need to handle |
| 1898 | * 8-byte unaligned accesses. args points to raw_data within the event |
| 1899 | * and raw_data is guaranteed to be 8-byte unaligned because it is |
| 1900 | * preceded by raw_size which is a u32. So we need to copy args to a temp |
| 1901 | * variable to read it. Most notably this avoids extended load instructions |
| 1902 | * on unaligned addresses |
| 1903 | */ |
| 1904 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1905 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1906 | unsigned char *args, struct trace *trace, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1907 | struct thread *thread) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1908 | { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1909 | size_t printed = 0; |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1910 | unsigned char *p; |
| 1911 | unsigned long val; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1912 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1913 | if (sc->args != NULL) { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1914 | struct format_field *field; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1915 | u8 bit = 1; |
| 1916 | struct syscall_arg arg = { |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1917 | .idx = 0, |
| 1918 | .mask = 0, |
| 1919 | .trace = trace, |
| 1920 | .thread = thread, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1921 | }; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1922 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1923 | for (field = sc->args; field; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1924 | field = field->next, ++arg.idx, bit <<= 1) { |
| 1925 | if (arg.mask & bit) |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1926 | continue; |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1927 | |
| 1928 | /* special care for unaligned accesses */ |
| 1929 | p = args + sizeof(unsigned long) * arg.idx; |
| 1930 | memcpy(&val, p, sizeof(val)); |
| 1931 | |
Arnaldo Carvalho de Melo | 4aa5823 | 2013-09-20 12:19:41 -0300 | [diff] [blame] | 1932 | /* |
| 1933 | * Suppress this argument if its value is zero and |
| 1934 | * and we don't have a string associated in an |
| 1935 | * strarray for it. |
| 1936 | */ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1937 | if (val == 0 && |
Arnaldo Carvalho de Melo | 4aa5823 | 2013-09-20 12:19:41 -0300 | [diff] [blame] | 1938 | !(sc->arg_scnprintf && |
| 1939 | sc->arg_scnprintf[arg.idx] == SCA_STRARRAY && |
| 1940 | sc->arg_parm[arg.idx])) |
Arnaldo Carvalho de Melo | 22ae5cf1 | 2013-09-12 11:27:34 -0300 | [diff] [blame] | 1941 | continue; |
| 1942 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1943 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1944 | "%s%s: ", printed ? ", " : "", field->name); |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1945 | if (sc->arg_scnprintf && sc->arg_scnprintf[arg.idx]) { |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1946 | arg.val = val; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1947 | if (sc->arg_parm) |
| 1948 | arg.parm = sc->arg_parm[arg.idx]; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1949 | printed += sc->arg_scnprintf[arg.idx](bf + printed, |
| 1950 | size - printed, &arg); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1951 | } else { |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1952 | printed += scnprintf(bf + printed, size - printed, |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1953 | "%ld", val); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1954 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1955 | } |
| 1956 | } else { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1957 | int i = 0; |
| 1958 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1959 | while (i < 6) { |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1960 | /* special care for unaligned accesses */ |
| 1961 | p = args + sizeof(unsigned long) * i; |
| 1962 | memcpy(&val, p, sizeof(val)); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1963 | printed += scnprintf(bf + printed, size - printed, |
| 1964 | "%sarg%d: %ld", |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1965 | printed ? ", " : "", i, val); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1966 | ++i; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | return printed; |
| 1971 | } |
| 1972 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1973 | typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1974 | union perf_event *event, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1975 | struct perf_sample *sample); |
| 1976 | |
| 1977 | static struct syscall *trace__syscall_info(struct trace *trace, |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1978 | struct perf_evsel *evsel, int id) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1979 | { |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1980 | |
| 1981 | if (id < 0) { |
Arnaldo Carvalho de Melo | adaa18b | 2013-08-22 17:55:25 -0300 | [diff] [blame] | 1982 | |
| 1983 | /* |
| 1984 | * XXX: Noticed on x86_64, reproduced as far back as 3.0.36, haven't tried |
| 1985 | * before that, leaving at a higher verbosity level till that is |
| 1986 | * explained. Reproduced with plain ftrace with: |
| 1987 | * |
| 1988 | * echo 1 > /t/events/raw_syscalls/sys_exit/enable |
| 1989 | * grep "NR -1 " /t/trace_pipe |
| 1990 | * |
| 1991 | * After generating some load on the machine. |
| 1992 | */ |
| 1993 | if (verbose > 1) { |
| 1994 | static u64 n; |
| 1995 | fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", |
| 1996 | id, perf_evsel__name(evsel), ++n); |
| 1997 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1998 | return NULL; |
| 1999 | } |
| 2000 | |
| 2001 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && |
| 2002 | trace__read_syscall_info(trace, id)) |
| 2003 | goto out_cant_read; |
| 2004 | |
| 2005 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) |
| 2006 | goto out_cant_read; |
| 2007 | |
| 2008 | return &trace->syscalls.table[id]; |
| 2009 | |
| 2010 | out_cant_read: |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 2011 | if (verbose) { |
| 2012 | fprintf(trace->output, "Problems reading syscall %d", id); |
| 2013 | if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) |
| 2014 | fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); |
| 2015 | fputs(" information\n", trace->output); |
| 2016 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2017 | return NULL; |
| 2018 | } |
| 2019 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2020 | static void thread__update_stats(struct thread_trace *ttrace, |
| 2021 | int id, struct perf_sample *sample) |
| 2022 | { |
| 2023 | struct int_node *inode; |
| 2024 | struct stats *stats; |
| 2025 | u64 duration = 0; |
| 2026 | |
| 2027 | inode = intlist__findnew(ttrace->syscall_stats, id); |
| 2028 | if (inode == NULL) |
| 2029 | return; |
| 2030 | |
| 2031 | stats = inode->priv; |
| 2032 | if (stats == NULL) { |
| 2033 | stats = malloc(sizeof(struct stats)); |
| 2034 | if (stats == NULL) |
| 2035 | return; |
| 2036 | init_stats(stats); |
| 2037 | inode->priv = stats; |
| 2038 | } |
| 2039 | |
| 2040 | if (ttrace->entry_time && sample->time > ttrace->entry_time) |
| 2041 | duration = sample->time - ttrace->entry_time; |
| 2042 | |
| 2043 | update_stats(stats, duration); |
| 2044 | } |
| 2045 | |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 2046 | static int trace__printf_interrupted_entry(struct trace *trace, struct perf_sample *sample) |
| 2047 | { |
| 2048 | struct thread_trace *ttrace; |
| 2049 | u64 duration; |
| 2050 | size_t printed; |
| 2051 | |
| 2052 | if (trace->current == NULL) |
| 2053 | return 0; |
| 2054 | |
| 2055 | ttrace = thread__priv(trace->current); |
| 2056 | |
| 2057 | if (!ttrace->entry_pending) |
| 2058 | return 0; |
| 2059 | |
| 2060 | duration = sample->time - ttrace->entry_time; |
| 2061 | |
| 2062 | printed = trace__fprintf_entry_head(trace, trace->current, duration, sample->time, trace->output); |
| 2063 | printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str); |
| 2064 | ttrace->entry_pending = false; |
| 2065 | |
| 2066 | return printed; |
| 2067 | } |
| 2068 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2069 | static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2070 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2071 | struct perf_sample *sample) |
| 2072 | { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2073 | char *msg; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2074 | void *args; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2075 | size_t printed = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2076 | struct thread *thread; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2077 | int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2078 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2079 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2080 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2081 | if (sc == NULL) |
| 2082 | return -1; |
| 2083 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2084 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2085 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2086 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2087 | goto out_put; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2088 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 2089 | args = perf_evsel__sc_tp_ptr(evsel, args, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2090 | |
| 2091 | if (ttrace->entry_str == NULL) { |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 2092 | ttrace->entry_str = malloc(trace__entry_str_size); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2093 | if (!ttrace->entry_str) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2094 | goto out_put; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2095 | } |
| 2096 | |
David Ahern | 13f22a2 | 2015-03-19 12:23:03 -0600 | [diff] [blame] | 2097 | if (!trace->summary_only) |
Arnaldo Carvalho de Melo | 6ebad5c | 2015-03-25 18:01:15 -0300 | [diff] [blame] | 2098 | trace__printf_interrupted_entry(trace, sample); |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 2099 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2100 | ttrace->entry_time = sample->time; |
| 2101 | msg = ttrace->entry_str; |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 2102 | printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2103 | |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 2104 | printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 2105 | args, trace, thread); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2106 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 2107 | if (sc->is_exit) { |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 2108 | if (!trace->duration_filter && !trace->summary_only) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2109 | trace__fprintf_entry_head(trace, thread, 1, sample->time, trace->output); |
| 2110 | fprintf(trace->output, "%-70s\n", ttrace->entry_str); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2111 | } |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2112 | } else { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2113 | ttrace->entry_pending = true; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2114 | /* See trace__vfs_getname & trace__sys_exit */ |
| 2115 | ttrace->filename.pending_open = false; |
| 2116 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2117 | |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 2118 | if (trace->current != thread) { |
| 2119 | thread__put(trace->current); |
| 2120 | trace->current = thread__get(thread); |
| 2121 | } |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2122 | err = 0; |
| 2123 | out_put: |
| 2124 | thread__put(thread); |
| 2125 | return err; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2126 | } |
| 2127 | |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2128 | static int trace__fprintf_callchain(struct trace *trace, struct perf_evsel *evsel, |
| 2129 | struct perf_sample *sample) |
| 2130 | { |
| 2131 | struct addr_location al; |
| 2132 | /* TODO: user-configurable print_opts */ |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 2133 | const unsigned int print_opts = EVSEL__PRINT_SYM | |
| 2134 | EVSEL__PRINT_DSO | |
| 2135 | EVSEL__PRINT_UNKNOWN_AS_ADDR; |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2136 | |
| 2137 | if (sample->callchain == NULL) |
| 2138 | return 0; |
| 2139 | |
| 2140 | if (machine__resolve(trace->host, &al, sample) < 0) { |
| 2141 | pr_err("Problem processing %s callchain, skipping...\n", |
| 2142 | perf_evsel__name(evsel)); |
| 2143 | return 0; |
| 2144 | } |
| 2145 | |
| 2146 | return perf_evsel__fprintf_callchain(evsel, sample, &al, 38, print_opts, |
| 2147 | scripting_max_stack, trace->output); |
| 2148 | } |
| 2149 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2150 | static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2151 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2152 | struct perf_sample *sample) |
| 2153 | { |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 2154 | long ret; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2155 | u64 duration = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2156 | struct thread *thread; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2157 | int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2158 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2159 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2160 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2161 | if (sc == NULL) |
| 2162 | return -1; |
| 2163 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2164 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2165 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2166 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2167 | goto out_put; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2168 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2169 | if (trace->summary) |
| 2170 | thread__update_stats(ttrace, id, sample); |
| 2171 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 2172 | ret = perf_evsel__sc_tp_uint(evsel, ret, sample); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2173 | |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 2174 | if (id == trace->open_id && ret >= 0 && ttrace->filename.pending_open) { |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2175 | trace__set_fd_pathname(thread, ret, ttrace->filename.name); |
| 2176 | ttrace->filename.pending_open = false; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2177 | ++trace->stats.vfs_getname; |
| 2178 | } |
| 2179 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2180 | ttrace->exit_time = sample->time; |
| 2181 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2182 | if (ttrace->entry_time) { |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2183 | duration = sample->time - ttrace->entry_time; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2184 | if (trace__filter_duration(trace, duration)) |
| 2185 | goto out; |
| 2186 | } else if (trace->duration_filter) |
| 2187 | goto out; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2188 | |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 2189 | if (trace->summary_only) |
| 2190 | goto out; |
| 2191 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2192 | trace__fprintf_entry_head(trace, thread, duration, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2193 | |
| 2194 | if (ttrace->entry_pending) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2195 | fprintf(trace->output, "%-70s", ttrace->entry_str); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2196 | } else { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2197 | fprintf(trace->output, " ... ["); |
| 2198 | color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); |
| 2199 | fprintf(trace->output, "]: %s()", sc->name); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2200 | } |
| 2201 | |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2202 | if (sc->fmt == NULL) { |
| 2203 | signed_print: |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 2204 | fprintf(trace->output, ") = %ld", ret); |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 2205 | } else if (ret < 0 && (sc->fmt->errmsg || sc->fmt->errpid)) { |
Masami Hiramatsu | 942a91e | 2014-08-14 02:22:41 +0000 | [diff] [blame] | 2206 | char bf[STRERR_BUFSIZE]; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2207 | const char *emsg = strerror_r(-ret, bf, sizeof(bf)), |
| 2208 | *e = audit_errno_to_name(-ret); |
| 2209 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2210 | fprintf(trace->output, ") = -1 %s %s", e, emsg); |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2211 | } else if (ret == 0 && sc->fmt->timeout) |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2212 | fprintf(trace->output, ") = 0 Timeout"); |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 2213 | else if (sc->fmt->hexret) |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 2214 | fprintf(trace->output, ") = %#lx", ret); |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 2215 | else if (sc->fmt->errpid) { |
| 2216 | struct thread *child = machine__find_thread(trace->host, ret, ret); |
| 2217 | |
| 2218 | if (child != NULL) { |
| 2219 | fprintf(trace->output, ") = %ld", ret); |
| 2220 | if (child->comm_set) |
| 2221 | fprintf(trace->output, " (%s)", thread__comm_str(child)); |
| 2222 | thread__put(child); |
| 2223 | } |
| 2224 | } else |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2225 | goto signed_print; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2226 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2227 | fputc('\n', trace->output); |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 2228 | |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2229 | trace__fprintf_callchain(trace, evsel, sample); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2230 | out: |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2231 | ttrace->entry_pending = false; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2232 | err = 0; |
| 2233 | out_put: |
| 2234 | thread__put(thread); |
| 2235 | return err; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2236 | } |
| 2237 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2238 | static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2239 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2240 | struct perf_sample *sample) |
| 2241 | { |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2242 | struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
| 2243 | struct thread_trace *ttrace; |
| 2244 | size_t filename_len, entry_str_len, to_move; |
| 2245 | ssize_t remaining_space; |
| 2246 | char *pos; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2247 | const char *filename = perf_evsel__rawptr(evsel, sample, "pathname"); |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2248 | |
| 2249 | if (!thread) |
| 2250 | goto out; |
| 2251 | |
| 2252 | ttrace = thread__priv(thread); |
| 2253 | if (!ttrace) |
| 2254 | goto out; |
| 2255 | |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2256 | filename_len = strlen(filename); |
| 2257 | |
| 2258 | if (ttrace->filename.namelen < filename_len) { |
| 2259 | char *f = realloc(ttrace->filename.name, filename_len + 1); |
| 2260 | |
| 2261 | if (f == NULL) |
| 2262 | goto out; |
| 2263 | |
| 2264 | ttrace->filename.namelen = filename_len; |
| 2265 | ttrace->filename.name = f; |
| 2266 | } |
| 2267 | |
| 2268 | strcpy(ttrace->filename.name, filename); |
| 2269 | ttrace->filename.pending_open = true; |
| 2270 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2271 | if (!ttrace->filename.ptr) |
| 2272 | goto out; |
| 2273 | |
| 2274 | entry_str_len = strlen(ttrace->entry_str); |
| 2275 | remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */ |
| 2276 | if (remaining_space <= 0) |
| 2277 | goto out; |
| 2278 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2279 | if (filename_len > (size_t)remaining_space) { |
| 2280 | filename += filename_len - remaining_space; |
| 2281 | filename_len = remaining_space; |
| 2282 | } |
| 2283 | |
| 2284 | to_move = entry_str_len - ttrace->filename.entry_str_pos + 1; /* \0 */ |
| 2285 | pos = ttrace->entry_str + ttrace->filename.entry_str_pos; |
| 2286 | memmove(pos + filename_len, pos, to_move); |
| 2287 | memcpy(pos, filename, filename_len); |
| 2288 | |
| 2289 | ttrace->filename.ptr = 0; |
| 2290 | ttrace->filename.entry_str_pos = 0; |
| 2291 | out: |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2292 | return 0; |
| 2293 | } |
| 2294 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2295 | static int trace__sched_stat_runtime(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2296 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2297 | struct perf_sample *sample) |
| 2298 | { |
| 2299 | u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); |
| 2300 | double runtime_ms = (double)runtime / NSEC_PER_MSEC; |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2301 | struct thread *thread = machine__findnew_thread(trace->host, |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 2302 | sample->pid, |
| 2303 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2304 | struct thread_trace *ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2305 | |
| 2306 | if (ttrace == NULL) |
| 2307 | goto out_dump; |
| 2308 | |
| 2309 | ttrace->runtime_ms += runtime_ms; |
| 2310 | trace->runtime_ms += runtime_ms; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2311 | thread__put(thread); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2312 | return 0; |
| 2313 | |
| 2314 | out_dump: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2315 | fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n", |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2316 | evsel->name, |
| 2317 | perf_evsel__strval(evsel, sample, "comm"), |
| 2318 | (pid_t)perf_evsel__intval(evsel, sample, "pid"), |
| 2319 | runtime, |
| 2320 | perf_evsel__intval(evsel, sample, "vruntime")); |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2321 | thread__put(thread); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2322 | return 0; |
| 2323 | } |
| 2324 | |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2325 | static void bpf_output__printer(enum binary_printer_ops op, |
| 2326 | unsigned int val, void *extra) |
| 2327 | { |
| 2328 | FILE *output = extra; |
| 2329 | unsigned char ch = (unsigned char)val; |
| 2330 | |
| 2331 | switch (op) { |
| 2332 | case BINARY_PRINT_CHAR_DATA: |
| 2333 | fprintf(output, "%c", isprint(ch) ? ch : '.'); |
| 2334 | break; |
| 2335 | case BINARY_PRINT_DATA_BEGIN: |
| 2336 | case BINARY_PRINT_LINE_BEGIN: |
| 2337 | case BINARY_PRINT_ADDR: |
| 2338 | case BINARY_PRINT_NUM_DATA: |
| 2339 | case BINARY_PRINT_NUM_PAD: |
| 2340 | case BINARY_PRINT_SEP: |
| 2341 | case BINARY_PRINT_CHAR_PAD: |
| 2342 | case BINARY_PRINT_LINE_END: |
| 2343 | case BINARY_PRINT_DATA_END: |
| 2344 | default: |
| 2345 | break; |
| 2346 | } |
| 2347 | } |
| 2348 | |
| 2349 | static void bpf_output__fprintf(struct trace *trace, |
| 2350 | struct perf_sample *sample) |
| 2351 | { |
| 2352 | print_binary(sample->raw_data, sample->raw_size, 8, |
| 2353 | bpf_output__printer, trace->output); |
| 2354 | } |
| 2355 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2356 | static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel, |
| 2357 | union perf_event *event __maybe_unused, |
| 2358 | struct perf_sample *sample) |
| 2359 | { |
| 2360 | trace__printf_interrupted_entry(trace, sample); |
| 2361 | trace__fprintf_tstamp(trace, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 0808921 | 2015-02-19 21:51:50 -0800 | [diff] [blame] | 2362 | |
| 2363 | if (trace->trace_syscalls) |
| 2364 | fprintf(trace->output, "( ): "); |
| 2365 | |
| 2366 | fprintf(trace->output, "%s:", evsel->name); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2367 | |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2368 | if (perf_evsel__is_bpf_output(evsel)) { |
| 2369 | bpf_output__fprintf(trace, sample); |
| 2370 | } else if (evsel->tp_format) { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2371 | event_format__fprintf(evsel->tp_format, sample->cpu, |
| 2372 | sample->raw_data, sample->raw_size, |
| 2373 | trace->output); |
| 2374 | } |
| 2375 | |
| 2376 | fprintf(trace->output, ")\n"); |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2377 | |
| 2378 | trace__fprintf_callchain(trace, evsel, sample); |
| 2379 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2380 | return 0; |
| 2381 | } |
| 2382 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2383 | static void print_location(FILE *f, struct perf_sample *sample, |
| 2384 | struct addr_location *al, |
| 2385 | bool print_dso, bool print_sym) |
| 2386 | { |
| 2387 | |
| 2388 | if ((verbose || print_dso) && al->map) |
| 2389 | fprintf(f, "%s@", al->map->dso->long_name); |
| 2390 | |
| 2391 | if ((verbose || print_sym) && al->sym) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2392 | fprintf(f, "%s+0x%" PRIx64, al->sym->name, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2393 | al->addr - al->sym->start); |
| 2394 | else if (al->map) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2395 | fprintf(f, "0x%" PRIx64, al->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2396 | else |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2397 | fprintf(f, "0x%" PRIx64, sample->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | static int trace__pgfault(struct trace *trace, |
| 2401 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 2402 | union perf_event *event __maybe_unused, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2403 | struct perf_sample *sample) |
| 2404 | { |
| 2405 | struct thread *thread; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2406 | struct addr_location al; |
| 2407 | char map_type = 'd'; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2408 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2409 | int err = -1; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2410 | |
| 2411 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2412 | ttrace = thread__trace(thread, trace->output); |
| 2413 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2414 | goto out_put; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2415 | |
| 2416 | if (evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ) |
| 2417 | ttrace->pfmaj++; |
| 2418 | else |
| 2419 | ttrace->pfmin++; |
| 2420 | |
| 2421 | if (trace->summary_only) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2422 | goto out; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2423 | |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 2424 | thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2425 | sample->ip, &al); |
| 2426 | |
| 2427 | trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); |
| 2428 | |
| 2429 | fprintf(trace->output, "%sfault [", |
| 2430 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? |
| 2431 | "maj" : "min"); |
| 2432 | |
| 2433 | print_location(trace->output, sample, &al, false, true); |
| 2434 | |
| 2435 | fprintf(trace->output, "] => "); |
| 2436 | |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 2437 | thread__find_addr_location(thread, sample->cpumode, MAP__VARIABLE, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2438 | sample->addr, &al); |
| 2439 | |
| 2440 | if (!al.map) { |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 2441 | thread__find_addr_location(thread, sample->cpumode, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2442 | MAP__FUNCTION, sample->addr, &al); |
| 2443 | |
| 2444 | if (al.map) |
| 2445 | map_type = 'x'; |
| 2446 | else |
| 2447 | map_type = '?'; |
| 2448 | } |
| 2449 | |
| 2450 | print_location(trace->output, sample, &al, true, false); |
| 2451 | |
| 2452 | fprintf(trace->output, " (%c%c)\n", map_type, al.level); |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2453 | out: |
| 2454 | err = 0; |
| 2455 | out_put: |
| 2456 | thread__put(thread); |
| 2457 | return err; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2458 | } |
| 2459 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2460 | static bool skip_sample(struct trace *trace, struct perf_sample *sample) |
| 2461 | { |
| 2462 | if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) || |
| 2463 | (trace->tid_list && intlist__find(trace->tid_list, sample->tid))) |
| 2464 | return false; |
| 2465 | |
| 2466 | if (trace->pid_list || trace->tid_list) |
| 2467 | return true; |
| 2468 | |
| 2469 | return false; |
| 2470 | } |
| 2471 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2472 | static void trace__set_base_time(struct trace *trace, |
Arnaldo Carvalho de Melo | 8a07a80 | 2016-03-31 15:19:39 -0300 | [diff] [blame] | 2473 | struct perf_evsel *evsel, |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2474 | struct perf_sample *sample) |
| 2475 | { |
Arnaldo Carvalho de Melo | 8a07a80 | 2016-03-31 15:19:39 -0300 | [diff] [blame] | 2476 | /* |
| 2477 | * BPF events were not setting PERF_SAMPLE_TIME, so be more robust |
| 2478 | * and don't use sample->time unconditionally, we may end up having |
| 2479 | * some other event in the future without PERF_SAMPLE_TIME for good |
| 2480 | * reason, i.e. we may not be interested in its timestamps, just in |
| 2481 | * it taking place, picking some piece of information when it |
| 2482 | * appears in our event stream (vfs_getname comes to mind). |
| 2483 | */ |
| 2484 | if (trace->base_time == 0 && !trace->full_time && |
| 2485 | (evsel->attr.sample_type & PERF_SAMPLE_TIME)) |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2486 | trace->base_time = sample->time; |
| 2487 | } |
| 2488 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2489 | static int trace__process_sample(struct perf_tool *tool, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2490 | union perf_event *event, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2491 | struct perf_sample *sample, |
| 2492 | struct perf_evsel *evsel, |
| 2493 | struct machine *machine __maybe_unused) |
| 2494 | { |
| 2495 | struct trace *trace = container_of(tool, struct trace, tool); |
| 2496 | int err = 0; |
| 2497 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2498 | tracepoint_handler handler = evsel->handler; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2499 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2500 | if (skip_sample(trace, sample)) |
| 2501 | return 0; |
| 2502 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2503 | trace__set_base_time(trace, evsel, sample); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2504 | |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2505 | if (handler) { |
| 2506 | ++trace->nr_events; |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2507 | handler(trace, evsel, event, sample); |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2508 | } |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2509 | |
| 2510 | return err; |
| 2511 | } |
| 2512 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2513 | static int parse_target_str(struct trace *trace) |
| 2514 | { |
| 2515 | if (trace->opts.target.pid) { |
| 2516 | trace->pid_list = intlist__new(trace->opts.target.pid); |
| 2517 | if (trace->pid_list == NULL) { |
| 2518 | pr_err("Error parsing process id string\n"); |
| 2519 | return -EINVAL; |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | if (trace->opts.target.tid) { |
| 2524 | trace->tid_list = intlist__new(trace->opts.target.tid); |
| 2525 | if (trace->tid_list == NULL) { |
| 2526 | pr_err("Error parsing thread id string\n"); |
| 2527 | return -EINVAL; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2534 | static int trace__record(struct trace *trace, int argc, const char **argv) |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2535 | { |
| 2536 | unsigned int rec_argc, i, j; |
| 2537 | const char **rec_argv; |
| 2538 | const char * const record_args[] = { |
| 2539 | "record", |
| 2540 | "-R", |
| 2541 | "-m", "1024", |
| 2542 | "-c", "1", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2543 | }; |
| 2544 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2545 | const char * const sc_args[] = { "-e", }; |
| 2546 | unsigned int sc_args_nr = ARRAY_SIZE(sc_args); |
| 2547 | const char * const majpf_args[] = { "-e", "major-faults" }; |
| 2548 | unsigned int majpf_args_nr = ARRAY_SIZE(majpf_args); |
| 2549 | const char * const minpf_args[] = { "-e", "minor-faults" }; |
| 2550 | unsigned int minpf_args_nr = ARRAY_SIZE(minpf_args); |
| 2551 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2552 | /* +1 is for the event string below */ |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2553 | rec_argc = ARRAY_SIZE(record_args) + sc_args_nr + 1 + |
| 2554 | majpf_args_nr + minpf_args_nr + argc; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2555 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 2556 | |
| 2557 | if (rec_argv == NULL) |
| 2558 | return -ENOMEM; |
| 2559 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2560 | j = 0; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2561 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2562 | rec_argv[j++] = record_args[i]; |
| 2563 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2564 | if (trace->trace_syscalls) { |
| 2565 | for (i = 0; i < sc_args_nr; i++) |
| 2566 | rec_argv[j++] = sc_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2567 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2568 | /* event string may be different for older kernels - e.g., RHEL6 */ |
| 2569 | if (is_valid_tracepoint("raw_syscalls:sys_enter")) |
| 2570 | rec_argv[j++] = "raw_syscalls:sys_enter,raw_syscalls:sys_exit"; |
| 2571 | else if (is_valid_tracepoint("syscalls:sys_enter")) |
| 2572 | rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit"; |
| 2573 | else { |
| 2574 | pr_err("Neither raw_syscalls nor syscalls events exist.\n"); |
| 2575 | return -1; |
| 2576 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2577 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2578 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2579 | if (trace->trace_pgfaults & TRACE_PFMAJ) |
| 2580 | for (i = 0; i < majpf_args_nr; i++) |
| 2581 | rec_argv[j++] = majpf_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2582 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2583 | if (trace->trace_pgfaults & TRACE_PFMIN) |
| 2584 | for (i = 0; i < minpf_args_nr; i++) |
| 2585 | rec_argv[j++] = minpf_args[i]; |
| 2586 | |
| 2587 | for (i = 0; i < (unsigned int)argc; i++) |
| 2588 | rec_argv[j++] = argv[i]; |
| 2589 | |
| 2590 | return cmd_record(j, rec_argv, NULL); |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2591 | } |
| 2592 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2593 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); |
| 2594 | |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2595 | static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist) |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2596 | { |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 2597 | struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname"); |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 2598 | |
| 2599 | if (IS_ERR(evsel)) |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2600 | return false; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2601 | |
| 2602 | if (perf_evsel__field(evsel, "pathname") == NULL) { |
| 2603 | perf_evsel__delete(evsel); |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2604 | return false; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2605 | } |
| 2606 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2607 | evsel->handler = trace__vfs_getname; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2608 | perf_evlist__add(evlist, evsel); |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2609 | return true; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2610 | } |
| 2611 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2612 | static int perf_evlist__add_pgfault(struct perf_evlist *evlist, |
| 2613 | u64 config) |
| 2614 | { |
| 2615 | struct perf_evsel *evsel; |
| 2616 | struct perf_event_attr attr = { |
| 2617 | .type = PERF_TYPE_SOFTWARE, |
| 2618 | .mmap_data = 1, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2619 | }; |
| 2620 | |
| 2621 | attr.config = config; |
Arnaldo Carvalho de Melo | 0524798 | 2014-07-23 18:15:09 -0300 | [diff] [blame] | 2622 | attr.sample_period = 1; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2623 | |
| 2624 | event_attr_init(&attr); |
| 2625 | |
| 2626 | evsel = perf_evsel__new(&attr); |
| 2627 | if (!evsel) |
| 2628 | return -ENOMEM; |
| 2629 | |
| 2630 | evsel->handler = trace__pgfault; |
| 2631 | perf_evlist__add(evlist, evsel); |
| 2632 | |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2636 | static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) |
| 2637 | { |
| 2638 | const u32 type = event->header.type; |
| 2639 | struct perf_evsel *evsel; |
| 2640 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2641 | if (type != PERF_RECORD_SAMPLE) { |
| 2642 | trace__process_event(trace, trace->host, event, sample); |
| 2643 | return; |
| 2644 | } |
| 2645 | |
| 2646 | evsel = perf_evlist__id2evsel(trace->evlist, sample->id); |
| 2647 | if (evsel == NULL) { |
| 2648 | fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); |
| 2649 | return; |
| 2650 | } |
| 2651 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2652 | trace__set_base_time(trace, evsel, sample); |
| 2653 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2654 | if (evsel->attr.type == PERF_TYPE_TRACEPOINT && |
| 2655 | sample->raw_data == NULL) { |
| 2656 | fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", |
| 2657 | perf_evsel__name(evsel), sample->tid, |
| 2658 | sample->cpu, sample->raw_size); |
| 2659 | } else { |
| 2660 | tracepoint_handler handler = evsel->handler; |
| 2661 | handler(trace, evsel, event, sample); |
| 2662 | } |
| 2663 | } |
| 2664 | |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2665 | static int trace__add_syscall_newtp(struct trace *trace) |
| 2666 | { |
| 2667 | int ret = -1; |
| 2668 | struct perf_evlist *evlist = trace->evlist; |
| 2669 | struct perf_evsel *sys_enter, *sys_exit; |
| 2670 | |
| 2671 | sys_enter = perf_evsel__syscall_newtp("sys_enter", trace__sys_enter); |
| 2672 | if (sys_enter == NULL) |
| 2673 | goto out; |
| 2674 | |
| 2675 | if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) |
| 2676 | goto out_delete_sys_enter; |
| 2677 | |
| 2678 | sys_exit = perf_evsel__syscall_newtp("sys_exit", trace__sys_exit); |
| 2679 | if (sys_exit == NULL) |
| 2680 | goto out_delete_sys_enter; |
| 2681 | |
| 2682 | if (perf_evsel__init_sc_tp_uint_field(sys_exit, ret)) |
| 2683 | goto out_delete_sys_exit; |
| 2684 | |
| 2685 | perf_evlist__add(evlist, sys_enter); |
| 2686 | perf_evlist__add(evlist, sys_exit); |
| 2687 | |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 2688 | if (trace->opts.callgraph_set && !trace->kernel_syscallchains) { |
| 2689 | /* |
| 2690 | * We're interested only in the user space callchain |
| 2691 | * leading to the syscall, allow overriding that for |
| 2692 | * debugging reasons using --kernel_syscall_callchains |
| 2693 | */ |
| 2694 | sys_exit->attr.exclude_callchain_kernel = 1; |
| 2695 | } |
| 2696 | |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 2697 | trace->syscalls.events.sys_enter = sys_enter; |
| 2698 | trace->syscalls.events.sys_exit = sys_exit; |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2699 | |
| 2700 | ret = 0; |
| 2701 | out: |
| 2702 | return ret; |
| 2703 | |
| 2704 | out_delete_sys_exit: |
| 2705 | perf_evsel__delete_priv(sys_exit); |
| 2706 | out_delete_sys_enter: |
| 2707 | perf_evsel__delete_priv(sys_enter); |
| 2708 | goto out; |
| 2709 | } |
| 2710 | |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2711 | static int trace__set_ev_qualifier_filter(struct trace *trace) |
| 2712 | { |
| 2713 | int err = -1; |
| 2714 | char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, |
| 2715 | trace->ev_qualifier_ids.nr, |
| 2716 | trace->ev_qualifier_ids.entries); |
| 2717 | |
| 2718 | if (filter == NULL) |
| 2719 | goto out_enomem; |
| 2720 | |
| 2721 | if (!perf_evsel__append_filter(trace->syscalls.events.sys_enter, "&&", filter)) |
| 2722 | err = perf_evsel__append_filter(trace->syscalls.events.sys_exit, "&&", filter); |
| 2723 | |
| 2724 | free(filter); |
| 2725 | out: |
| 2726 | return err; |
| 2727 | out_enomem: |
| 2728 | errno = ENOMEM; |
| 2729 | goto out; |
| 2730 | } |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2731 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2732 | static int trace__run(struct trace *trace, int argc, const char **argv) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2733 | { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2734 | struct perf_evlist *evlist = trace->evlist; |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 2735 | struct perf_evsel *evsel; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2736 | int err = -1, i; |
| 2737 | unsigned long before; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2738 | const bool forks = argc > 0; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2739 | bool draining = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2740 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 2741 | trace->live = true; |
| 2742 | |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2743 | if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) |
Arnaldo Carvalho de Melo | 801c67b | 2015-01-22 10:52:55 -0300 | [diff] [blame] | 2744 | goto out_error_raw_syscalls; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2745 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2746 | if (trace->trace_syscalls) |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2747 | trace->vfs_getname = perf_evlist__add_vfs_getname(evlist); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2748 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2749 | if ((trace->trace_pgfaults & TRACE_PFMAJ) && |
Arnaldo Carvalho de Melo | e2726d9 | 2015-01-22 10:34:22 -0300 | [diff] [blame] | 2750 | perf_evlist__add_pgfault(evlist, PERF_COUNT_SW_PAGE_FAULTS_MAJ)) { |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2751 | goto out_error_mem; |
Arnaldo Carvalho de Melo | e2726d9 | 2015-01-22 10:34:22 -0300 | [diff] [blame] | 2752 | } |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2753 | |
| 2754 | if ((trace->trace_pgfaults & TRACE_PFMIN) && |
| 2755 | perf_evlist__add_pgfault(evlist, PERF_COUNT_SW_PAGE_FAULTS_MIN)) |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2756 | goto out_error_mem; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2757 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2758 | if (trace->sched && |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2759 | perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime", |
| 2760 | trace__sched_stat_runtime)) |
| 2761 | goto out_error_sched_stat_runtime; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2762 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2763 | err = perf_evlist__create_maps(evlist, &trace->opts.target); |
| 2764 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2765 | fprintf(trace->output, "Problems parsing the target to trace, check your options!\n"); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2766 | goto out_delete_evlist; |
| 2767 | } |
| 2768 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2769 | err = trace__symbols_init(trace, evlist); |
| 2770 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2771 | fprintf(trace->output, "Problems initializing symbol libraries!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 2772 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2773 | } |
| 2774 | |
Arnaldo Carvalho de Melo | fde54b7 | 2016-04-11 18:42:37 -0300 | [diff] [blame] | 2775 | perf_evlist__config(evlist, &trace->opts, NULL); |
| 2776 | |
| 2777 | if (trace->opts.callgraph_set && trace->syscalls.events.sys_exit) { |
| 2778 | perf_evsel__config_callchain(trace->syscalls.events.sys_exit, |
| 2779 | &trace->opts, &callchain_param); |
| 2780 | /* |
| 2781 | * Now we have evsels with different sample_ids, use |
| 2782 | * PERF_SAMPLE_IDENTIFIER to map from sample to evsel |
| 2783 | * from a fixed position in each ring buffer record. |
| 2784 | * |
| 2785 | * As of this the changeset introducing this comment, this |
| 2786 | * isn't strictly needed, as the fields that can come before |
| 2787 | * PERF_SAMPLE_ID are all used, but we'll probably disable |
| 2788 | * some of those for things like copying the payload of |
| 2789 | * pointer syscall arguments, and for vfs_getname we don't |
| 2790 | * need PERF_SAMPLE_ADDR and PERF_SAMPLE_IP, so do this |
| 2791 | * here as a warning we need to use PERF_SAMPLE_IDENTIFIER. |
| 2792 | */ |
| 2793 | perf_evlist__set_sample_bit(evlist, IDENTIFIER); |
| 2794 | perf_evlist__reset_sample_bit(evlist, ID); |
| 2795 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2796 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2797 | signal(SIGCHLD, sig_handler); |
| 2798 | signal(SIGINT, sig_handler); |
| 2799 | |
| 2800 | if (forks) { |
Namhyung Kim | 6ef73ec | 2013-03-11 16:43:15 +0900 | [diff] [blame] | 2801 | err = perf_evlist__prepare_workload(evlist, &trace->opts.target, |
Arnaldo Carvalho de Melo | 735f7e0 | 2014-01-03 14:56:49 -0300 | [diff] [blame] | 2802 | argv, false, NULL); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2803 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2804 | fprintf(trace->output, "Couldn't run the workload!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 2805 | goto out_delete_evlist; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2809 | err = perf_evlist__open(evlist); |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2810 | if (err < 0) |
| 2811 | goto out_error_open; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2812 | |
Wang Nan | ba50423 | 2016-02-26 09:31:54 +0000 | [diff] [blame] | 2813 | err = bpf__apply_obj_config(); |
| 2814 | if (err) { |
| 2815 | char errbuf[BUFSIZ]; |
| 2816 | |
| 2817 | bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf)); |
| 2818 | pr_err("ERROR: Apply config to BPF failed: %s\n", |
| 2819 | errbuf); |
| 2820 | goto out_error_open; |
| 2821 | } |
| 2822 | |
Arnaldo Carvalho de Melo | 241b057 | 2015-02-21 10:15:21 -0800 | [diff] [blame] | 2823 | /* |
| 2824 | * Better not use !target__has_task() here because we need to cover the |
| 2825 | * case where no threads were specified in the command line, but a |
| 2826 | * workload was, and in that case we will fill in the thread_map when |
| 2827 | * we fork the workload in perf_evlist__prepare_workload. |
| 2828 | */ |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 2829 | if (trace->filter_pids.nr > 0) |
| 2830 | err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); |
Jiri Olsa | e13798c | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 2831 | else if (thread_map__pid(evlist->threads, 0) == -1) |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 2832 | err = perf_evlist__set_filter_pid(evlist, getpid()); |
| 2833 | |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 2834 | if (err < 0) |
| 2835 | goto out_error_mem; |
| 2836 | |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2837 | if (trace->ev_qualifier_ids.nr > 0) { |
| 2838 | err = trace__set_ev_qualifier_filter(trace); |
| 2839 | if (err < 0) |
| 2840 | goto out_errno; |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2841 | |
Arnaldo Carvalho de Melo | 2e5e5f8 | 2015-08-03 17:12:29 -0300 | [diff] [blame] | 2842 | pr_debug("event qualifier tracepoint filter: %s\n", |
| 2843 | trace->syscalls.events.sys_exit->filter); |
| 2844 | } |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2845 | |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 2846 | err = perf_evlist__apply_filters(evlist, &evsel); |
| 2847 | if (err < 0) |
| 2848 | goto out_error_apply_filters; |
Arnaldo Carvalho de Melo | 241b057 | 2015-02-21 10:15:21 -0800 | [diff] [blame] | 2849 | |
Jiri Olsa | f885037 | 2013-11-28 17:57:22 +0100 | [diff] [blame] | 2850 | err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false); |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 2851 | if (err < 0) |
| 2852 | goto out_error_mmap; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2853 | |
Arnaldo Carvalho de Melo | cb24d01 | 2015-04-22 10:04:23 -0300 | [diff] [blame] | 2854 | if (!target__none(&trace->opts.target)) |
| 2855 | perf_evlist__enable(evlist); |
| 2856 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2857 | if (forks) |
| 2858 | perf_evlist__start_workload(evlist); |
| 2859 | |
Jiri Olsa | e13798c | 2015-06-23 00:36:02 +0200 | [diff] [blame] | 2860 | trace->multiple_threads = thread_map__pid(evlist->threads, 0) == -1 || |
Arnaldo Carvalho de Melo | 42052be | 2015-02-13 12:32:45 -0300 | [diff] [blame] | 2861 | evlist->threads->nr > 1 || |
| 2862 | perf_evlist__first(evlist)->attr.inherit; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2863 | again: |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2864 | before = trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2865 | |
| 2866 | for (i = 0; i < evlist->nr_mmaps; i++) { |
| 2867 | union perf_event *event; |
| 2868 | |
| 2869 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2870 | struct perf_sample sample; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2871 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2872 | ++trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2873 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2874 | err = perf_evlist__parse_sample(evlist, event, &sample); |
| 2875 | if (err) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2876 | fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 2877 | goto next_event; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2878 | } |
| 2879 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2880 | trace__handle_event(trace, event, &sample); |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 2881 | next_event: |
| 2882 | perf_evlist__mmap_consume(evlist, i); |
Arnaldo Carvalho de Melo | 20c5f10 | 2013-09-03 11:55:07 -0300 | [diff] [blame] | 2883 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2884 | if (interrupted) |
| 2885 | goto out_disable; |
Arnaldo Carvalho de Melo | 02ac542 | 2015-04-22 11:11:57 -0300 | [diff] [blame] | 2886 | |
| 2887 | if (done && !draining) { |
| 2888 | perf_evlist__disable(evlist); |
| 2889 | draining = true; |
| 2890 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2891 | } |
| 2892 | } |
| 2893 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2894 | if (trace->nr_events == before) { |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2895 | int timeout = done ? 100 : -1; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2896 | |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2897 | if (!draining && perf_evlist__poll(evlist, timeout) > 0) { |
| 2898 | if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP) == 0) |
| 2899 | draining = true; |
| 2900 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2901 | goto again; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2902 | } |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2903 | } else { |
| 2904 | goto again; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2905 | } |
| 2906 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2907 | out_disable: |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 2908 | thread__zput(trace->current); |
| 2909 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2910 | perf_evlist__disable(evlist); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2911 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2912 | if (!err) { |
| 2913 | if (trace->summary) |
| 2914 | trace__fprintf_thread_summary(trace, trace->output); |
| 2915 | |
| 2916 | if (trace->show_tool_stats) { |
| 2917 | fprintf(trace->output, "Stats:\n " |
| 2918 | " vfs_getname : %" PRIu64 "\n" |
| 2919 | " proc_getname: %" PRIu64 "\n", |
| 2920 | trace->stats.vfs_getname, |
| 2921 | trace->stats.proc_getname); |
| 2922 | } |
| 2923 | } |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2924 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2925 | out_delete_evlist: |
| 2926 | perf_evlist__delete(evlist); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2927 | trace->evlist = NULL; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 2928 | trace->live = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2929 | return err; |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 2930 | { |
| 2931 | char errbuf[BUFSIZ]; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2932 | |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2933 | out_error_sched_stat_runtime: |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 2934 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime"); |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2935 | goto out_error; |
| 2936 | |
Arnaldo Carvalho de Melo | 801c67b | 2015-01-22 10:52:55 -0300 | [diff] [blame] | 2937 | out_error_raw_syscalls: |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 2938 | tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "raw_syscalls", "sys_(enter|exit)"); |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2939 | goto out_error; |
| 2940 | |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 2941 | out_error_mmap: |
| 2942 | perf_evlist__strerror_mmap(evlist, errno, errbuf, sizeof(errbuf)); |
| 2943 | goto out_error; |
| 2944 | |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2945 | out_error_open: |
| 2946 | perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); |
| 2947 | |
| 2948 | out_error: |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 2949 | fprintf(trace->output, "%s\n", errbuf); |
Ramkumar Ramachandra | 87f9186 | 2013-10-04 10:47:31 +0530 | [diff] [blame] | 2950 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 2951 | |
| 2952 | out_error_apply_filters: |
| 2953 | fprintf(trace->output, |
| 2954 | "Failed to set filter \"%s\" on event %s with %d (%s)\n", |
| 2955 | evsel->filter, perf_evsel__name(evsel), errno, |
| 2956 | strerror_r(errno, errbuf, sizeof(errbuf))); |
| 2957 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2958 | } |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2959 | out_error_mem: |
| 2960 | fprintf(trace->output, "Not enough memory to run!\n"); |
| 2961 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2962 | |
| 2963 | out_errno: |
| 2964 | fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); |
| 2965 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2966 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2967 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2968 | static int trace__replay(struct trace *trace) |
| 2969 | { |
| 2970 | const struct perf_evsel_str_handler handlers[] = { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2971 | { "probe:vfs_getname", trace__vfs_getname, }, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2972 | }; |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2973 | struct perf_data_file file = { |
| 2974 | .path = input_name, |
| 2975 | .mode = PERF_DATA_MODE_READ, |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 2976 | .force = trace->force, |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2977 | }; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2978 | struct perf_session *session; |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 2979 | struct perf_evsel *evsel; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2980 | int err = -1; |
| 2981 | |
| 2982 | trace->tool.sample = trace__process_sample; |
| 2983 | trace->tool.mmap = perf_event__process_mmap; |
David Ahern | 384c671 | 2013-09-22 19:44:58 -0600 | [diff] [blame] | 2984 | trace->tool.mmap2 = perf_event__process_mmap2; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2985 | trace->tool.comm = perf_event__process_comm; |
| 2986 | trace->tool.exit = perf_event__process_exit; |
| 2987 | trace->tool.fork = perf_event__process_fork; |
| 2988 | trace->tool.attr = perf_event__process_attr; |
| 2989 | trace->tool.tracing_data = perf_event__process_tracing_data; |
| 2990 | trace->tool.build_id = perf_event__process_build_id; |
| 2991 | |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 2992 | trace->tool.ordered_events = true; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2993 | trace->tool.ordering_requires_timestamps = true; |
| 2994 | |
| 2995 | /* add tid to output */ |
| 2996 | trace->multiple_threads = true; |
| 2997 | |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2998 | session = perf_session__new(&file, false, &trace->tool); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2999 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 3000 | return -1; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3001 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 3002 | if (symbol__init(&session->header.env) < 0) |
Namhyung Kim | cb2ffae | 2014-08-12 15:40:44 +0900 | [diff] [blame] | 3003 | goto out; |
| 3004 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 3005 | trace->host = &session->machines.host; |
| 3006 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3007 | err = perf_session__set_tracepoints_handlers(session, handlers); |
| 3008 | if (err) |
| 3009 | goto out; |
| 3010 | |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3011 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3012 | "raw_syscalls:sys_enter"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 3013 | /* older kernels have syscalls tp versus raw_syscalls */ |
| 3014 | if (evsel == NULL) |
| 3015 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3016 | "syscalls:sys_enter"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3017 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3018 | if (evsel && |
| 3019 | (perf_evsel__init_syscall_tp(evsel, trace__sys_enter) < 0 || |
| 3020 | perf_evsel__init_sc_tp_ptr_field(evsel, args))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3021 | pr_err("Error during initialize raw_syscalls:sys_enter event\n"); |
| 3022 | goto out; |
| 3023 | } |
| 3024 | |
| 3025 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3026 | "raw_syscalls:sys_exit"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 3027 | if (evsel == NULL) |
| 3028 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3029 | "syscalls:sys_exit"); |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3030 | if (evsel && |
| 3031 | (perf_evsel__init_syscall_tp(evsel, trace__sys_exit) < 0 || |
| 3032 | perf_evsel__init_sc_tp_uint_field(evsel, ret))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3033 | pr_err("Error during initialize raw_syscalls:sys_exit event\n"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3034 | goto out; |
| 3035 | } |
| 3036 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 3037 | evlist__for_each(session->evlist, evsel) { |
| 3038 | if (evsel->attr.type == PERF_TYPE_SOFTWARE && |
| 3039 | (evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ || |
| 3040 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MIN || |
| 3041 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS)) |
| 3042 | evsel->handler = trace__pgfault; |
| 3043 | } |
| 3044 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 3045 | err = parse_target_str(trace); |
| 3046 | if (err != 0) |
| 3047 | goto out; |
| 3048 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3049 | setup_pager(); |
| 3050 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 3051 | err = perf_session__process_events(session); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3052 | if (err) |
| 3053 | pr_err("Failed to process events, error %d", err); |
| 3054 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3055 | else if (trace->summary) |
| 3056 | trace__fprintf_thread_summary(trace, trace->output); |
| 3057 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3058 | out: |
| 3059 | perf_session__delete(session); |
| 3060 | |
| 3061 | return err; |
| 3062 | } |
| 3063 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3064 | static size_t trace__fprintf_threads_header(FILE *fp) |
| 3065 | { |
| 3066 | size_t printed; |
| 3067 | |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3068 | printed = fprintf(fp, "\n Summary of events:\n\n"); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3069 | |
| 3070 | return printed; |
| 3071 | } |
| 3072 | |
| 3073 | static size_t thread__dump_stats(struct thread_trace *ttrace, |
| 3074 | struct trace *trace, FILE *fp) |
| 3075 | { |
| 3076 | struct stats *stats; |
| 3077 | size_t printed = 0; |
| 3078 | struct syscall *sc; |
| 3079 | struct int_node *inode = intlist__first(ttrace->syscall_stats); |
| 3080 | |
| 3081 | if (inode == NULL) |
| 3082 | return 0; |
| 3083 | |
| 3084 | printed += fprintf(fp, "\n"); |
| 3085 | |
Milian Wolff | 834fd46 | 2015-08-06 11:24:29 +0200 | [diff] [blame] | 3086 | printed += fprintf(fp, " syscall calls total min avg max stddev\n"); |
| 3087 | printed += fprintf(fp, " (msec) (msec) (msec) (msec) (%%)\n"); |
| 3088 | printed += fprintf(fp, " --------------- -------- --------- --------- --------- --------- ------\n"); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3089 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3090 | /* each int_node is a syscall */ |
| 3091 | while (inode) { |
| 3092 | stats = inode->priv; |
| 3093 | if (stats) { |
| 3094 | double min = (double)(stats->min) / NSEC_PER_MSEC; |
| 3095 | double max = (double)(stats->max) / NSEC_PER_MSEC; |
| 3096 | double avg = avg_stats(stats); |
| 3097 | double pct; |
| 3098 | u64 n = (u64) stats->n; |
| 3099 | |
| 3100 | pct = avg ? 100.0 * stddev_stats(stats)/avg : 0.0; |
| 3101 | avg /= NSEC_PER_MSEC; |
| 3102 | |
| 3103 | sc = &trace->syscalls.table[inode->i]; |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3104 | printed += fprintf(fp, " %-15s", sc->name); |
Milian Wolff | 834fd46 | 2015-08-06 11:24:29 +0200 | [diff] [blame] | 3105 | printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f %9.3f", |
| 3106 | n, avg * n, min, avg); |
Pekka Enberg | 27a778b | 2013-11-13 14:21:48 +0200 | [diff] [blame] | 3107 | printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | inode = intlist__next(inode); |
| 3111 | } |
| 3112 | |
| 3113 | printed += fprintf(fp, "\n\n"); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3114 | |
| 3115 | return printed; |
| 3116 | } |
| 3117 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3118 | /* struct used to pass data to per-thread function */ |
| 3119 | struct summary_data { |
| 3120 | FILE *fp; |
| 3121 | struct trace *trace; |
| 3122 | size_t printed; |
| 3123 | }; |
| 3124 | |
| 3125 | static int trace__fprintf_one_thread(struct thread *thread, void *priv) |
| 3126 | { |
| 3127 | struct summary_data *data = priv; |
| 3128 | FILE *fp = data->fp; |
| 3129 | size_t printed = data->printed; |
| 3130 | struct trace *trace = data->trace; |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 3131 | struct thread_trace *ttrace = thread__priv(thread); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3132 | double ratio; |
| 3133 | |
| 3134 | if (ttrace == NULL) |
| 3135 | return 0; |
| 3136 | |
| 3137 | ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; |
| 3138 | |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 3139 | printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3140 | printed += fprintf(fp, "%lu events, ", ttrace->nr_events); |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 3141 | printed += fprintf(fp, "%.1f%%", ratio); |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 3142 | if (ttrace->pfmaj) |
| 3143 | printed += fprintf(fp, ", %lu majfaults", ttrace->pfmaj); |
| 3144 | if (ttrace->pfmin) |
| 3145 | printed += fprintf(fp, ", %lu minfaults", ttrace->pfmin); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3146 | printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3147 | printed += thread__dump_stats(ttrace, trace, fp); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3148 | |
| 3149 | data->printed += printed; |
| 3150 | |
| 3151 | return 0; |
| 3152 | } |
| 3153 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3154 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) |
| 3155 | { |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3156 | struct summary_data data = { |
| 3157 | .fp = fp, |
| 3158 | .trace = trace |
| 3159 | }; |
| 3160 | data.printed = trace__fprintf_threads_header(fp); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3161 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3162 | machine__for_each_thread(trace->host, trace__fprintf_one_thread, &data); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3163 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3164 | return data.printed; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3165 | } |
| 3166 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 3167 | static int trace__set_duration(const struct option *opt, const char *str, |
| 3168 | int unset __maybe_unused) |
| 3169 | { |
| 3170 | struct trace *trace = opt->value; |
| 3171 | |
| 3172 | trace->duration_filter = atof(str); |
| 3173 | return 0; |
| 3174 | } |
| 3175 | |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 3176 | static int trace__set_filter_pids(const struct option *opt, const char *str, |
| 3177 | int unset __maybe_unused) |
| 3178 | { |
| 3179 | int ret = -1; |
| 3180 | size_t i; |
| 3181 | struct trace *trace = opt->value; |
| 3182 | /* |
| 3183 | * FIXME: introduce a intarray class, plain parse csv and create a |
| 3184 | * { int nr, int entries[] } struct... |
| 3185 | */ |
| 3186 | struct intlist *list = intlist__new(str); |
| 3187 | |
| 3188 | if (list == NULL) |
| 3189 | return -1; |
| 3190 | |
| 3191 | i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; |
| 3192 | trace->filter_pids.entries = calloc(i, sizeof(pid_t)); |
| 3193 | |
| 3194 | if (trace->filter_pids.entries == NULL) |
| 3195 | goto out; |
| 3196 | |
| 3197 | trace->filter_pids.entries[0] = getpid(); |
| 3198 | |
| 3199 | for (i = 1; i < trace->filter_pids.nr; ++i) |
| 3200 | trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; |
| 3201 | |
| 3202 | intlist__delete(list); |
| 3203 | ret = 0; |
| 3204 | out: |
| 3205 | return ret; |
| 3206 | } |
| 3207 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3208 | static int trace__open_output(struct trace *trace, const char *filename) |
| 3209 | { |
| 3210 | struct stat st; |
| 3211 | |
| 3212 | if (!stat(filename, &st) && st.st_size) { |
| 3213 | char oldname[PATH_MAX]; |
| 3214 | |
| 3215 | scnprintf(oldname, sizeof(oldname), "%s.old", filename); |
| 3216 | unlink(oldname); |
| 3217 | rename(filename, oldname); |
| 3218 | } |
| 3219 | |
| 3220 | trace->output = fopen(filename, "w"); |
| 3221 | |
| 3222 | return trace->output == NULL ? -errno : 0; |
| 3223 | } |
| 3224 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3225 | static int parse_pagefaults(const struct option *opt, const char *str, |
| 3226 | int unset __maybe_unused) |
| 3227 | { |
| 3228 | int *trace_pgfaults = opt->value; |
| 3229 | |
| 3230 | if (strcmp(str, "all") == 0) |
| 3231 | *trace_pgfaults |= TRACE_PFMAJ | TRACE_PFMIN; |
| 3232 | else if (strcmp(str, "maj") == 0) |
| 3233 | *trace_pgfaults |= TRACE_PFMAJ; |
| 3234 | else if (strcmp(str, "min") == 0) |
| 3235 | *trace_pgfaults |= TRACE_PFMIN; |
| 3236 | else |
| 3237 | return -1; |
| 3238 | |
| 3239 | return 0; |
| 3240 | } |
| 3241 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3242 | static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler) |
| 3243 | { |
| 3244 | struct perf_evsel *evsel; |
| 3245 | |
| 3246 | evlist__for_each(evlist, evsel) |
| 3247 | evsel->handler = handler; |
| 3248 | } |
| 3249 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3250 | int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) |
| 3251 | { |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 3252 | const char *trace_usage[] = { |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3253 | "perf trace [<options>] [<command>]", |
| 3254 | "perf trace [<options>] -- <command> [<options>]", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 3255 | "perf trace record [<options>] [<command>]", |
| 3256 | "perf trace record [<options>] -- <command> [<options>]", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3257 | NULL |
| 3258 | }; |
| 3259 | struct trace trace = { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3260 | .syscalls = { |
| 3261 | . max = -1, |
| 3262 | }, |
| 3263 | .opts = { |
| 3264 | .target = { |
| 3265 | .uid = UINT_MAX, |
| 3266 | .uses_mmap = true, |
| 3267 | }, |
| 3268 | .user_freq = UINT_MAX, |
| 3269 | .user_interval = ULLONG_MAX, |
Arnaldo Carvalho de Melo | 509051e | 2014-01-14 17:52:14 -0300 | [diff] [blame] | 3270 | .no_buffering = true, |
Arnaldo Carvalho de Melo | 38d5447 | 2014-12-12 17:28:32 -0300 | [diff] [blame] | 3271 | .mmap_pages = UINT_MAX, |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 3272 | .proc_map_timeout = 500, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3273 | }, |
Milian Wolff | 007d66a | 2015-08-05 16:52:23 -0300 | [diff] [blame] | 3274 | .output = stderr, |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 3275 | .show_comm = true, |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3276 | .trace_syscalls = true, |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 3277 | .kernel_syscallchains = false, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3278 | }; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3279 | const char *output_name = NULL; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 3280 | const char *ev_qualifier_str = NULL; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3281 | const struct option trace_options[] = { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3282 | OPT_CALLBACK(0, "event", &trace.evlist, "event", |
| 3283 | "event selector. use 'perf list' to list available events", |
| 3284 | parse_events_option), |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 3285 | OPT_BOOLEAN(0, "comm", &trace.show_comm, |
| 3286 | "show the thread COMM next to its id"), |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 3287 | OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), |
Arnaldo Carvalho de Melo | d303e85 | 2015-04-23 12:02:07 -0300 | [diff] [blame] | 3288 | OPT_STRING('e', "expr", &ev_qualifier_str, "expr", "list of syscalls to trace"), |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3289 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3290 | OPT_STRING('i', "input", &input_name, "file", "Analyze events in file"), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3291 | OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", |
| 3292 | "trace events on existing process id"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 3293 | OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3294 | "trace events on existing thread id"), |
Arnaldo Carvalho de Melo | fa0e4ff | 2015-04-23 11:59:20 -0300 | [diff] [blame] | 3295 | OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", |
| 3296 | "pids to filter (by the kernel)", trace__set_filter_pids), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 3297 | OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3298 | "system-wide collection from all CPUs"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 3299 | OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3300 | "list of cpus to monitor"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3301 | OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3302 | "child tasks do not inherit counters"), |
Jiri Olsa | 994a1f7 | 2013-09-01 12:36:12 +0200 | [diff] [blame] | 3303 | OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", |
| 3304 | "number of mmap data pages", |
| 3305 | perf_evlist__parse_mmap_pages), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 3306 | OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3307 | "user to profile"), |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 3308 | OPT_CALLBACK(0, "duration", &trace, "float", |
| 3309 | "show only events with duration > N.M ms", |
| 3310 | trace__set_duration), |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3311 | OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 3312 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
David Ahern | 4bb0919 | 2013-09-04 12:37:43 -0600 | [diff] [blame] | 3313 | OPT_BOOLEAN('T', "time", &trace.full_time, |
| 3314 | "Show full timestamp, not time relative to first start"), |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 3315 | OPT_BOOLEAN('s', "summary", &trace.summary_only, |
| 3316 | "Show only syscall summary with statistics"), |
| 3317 | OPT_BOOLEAN('S', "with-summary", &trace.summary, |
| 3318 | "Show all syscalls and summary with statistics"), |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3319 | OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", |
| 3320 | "Trace pagefaults", parse_pagefaults, "maj"), |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3321 | OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 3322 | OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 3323 | OPT_CALLBACK(0, "call-graph", &trace.opts, |
| 3324 | "record_mode[,record_size]", record_callchain_help, |
| 3325 | &record_parse_callchain_opt), |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 3326 | OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, |
| 3327 | "Show the kernel callchains on the syscall exit path"), |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 3328 | OPT_UINTEGER(0, "proc-map-timeout", &trace.opts.proc_map_timeout, |
| 3329 | "per thread proc mmap processing timeout in ms"), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3330 | OPT_END() |
| 3331 | }; |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 3332 | const char * const trace_subcommands[] = { "record", NULL }; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3333 | int err; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 3334 | char bf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3335 | |
Arnaldo Carvalho de Melo | 4d08cb8 | 2015-02-24 15:35:55 -0300 | [diff] [blame] | 3336 | signal(SIGSEGV, sighandler_dump_stack); |
| 3337 | signal(SIGFPE, sighandler_dump_stack); |
| 3338 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3339 | trace.evlist = perf_evlist__new(); |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 3340 | trace.sctbl = syscalltbl__new(); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3341 | |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 3342 | if (trace.evlist == NULL || trace.sctbl == NULL) { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3343 | pr_err("Not enough memory to run!\n"); |
He Kuang | ff8f695 | 2015-05-11 12:28:36 +0000 | [diff] [blame] | 3344 | err = -ENOMEM; |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3345 | goto out; |
| 3346 | } |
| 3347 | |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 3348 | argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands, |
| 3349 | trace_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 3350 | |
Wang Nan | d788857 | 2016-04-08 15:07:24 +0000 | [diff] [blame] | 3351 | err = bpf__setup_stdout(trace.evlist); |
| 3352 | if (err) { |
| 3353 | bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf)); |
| 3354 | pr_err("ERROR: Setup BPF stdout failed: %s\n", bf); |
| 3355 | goto out; |
| 3356 | } |
| 3357 | |
Arnaldo Carvalho de Melo | 59247e3 | 2016-04-12 16:05:02 -0300 | [diff] [blame] | 3358 | err = -1; |
| 3359 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3360 | if (trace.trace_pgfaults) { |
| 3361 | trace.opts.sample_address = true; |
| 3362 | trace.opts.sample_time = true; |
| 3363 | } |
| 3364 | |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 3365 | if (trace.opts.callgraph_set) |
| 3366 | symbol_conf.use_callchain = true; |
| 3367 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3368 | if (trace.evlist->nr_entries > 0) |
| 3369 | evlist__set_evsel_handler(trace.evlist, trace__event_handler); |
| 3370 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 3371 | if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) |
| 3372 | return trace__record(&trace, argc-1, &argv[1]); |
| 3373 | |
| 3374 | /* summary_only implies summary option, but don't overwrite summary if set */ |
| 3375 | if (trace.summary_only) |
| 3376 | trace.summary = trace.summary_only; |
| 3377 | |
Arnaldo Carvalho de Melo | 726f323 | 2015-02-06 10:16:45 +0100 | [diff] [blame] | 3378 | if (!trace.trace_syscalls && !trace.trace_pgfaults && |
| 3379 | trace.evlist->nr_entries == 0 /* Was --events used? */) { |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3380 | pr_err("Please specify something to trace.\n"); |
| 3381 | return -1; |
| 3382 | } |
| 3383 | |
Arnaldo Carvalho de Melo | 59247e3 | 2016-04-12 16:05:02 -0300 | [diff] [blame] | 3384 | if (!trace.trace_syscalls && ev_qualifier_str) { |
| 3385 | pr_err("The -e option can't be used with --no-syscalls.\n"); |
| 3386 | goto out; |
| 3387 | } |
| 3388 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3389 | if (output_name != NULL) { |
| 3390 | err = trace__open_output(&trace, output_name); |
| 3391 | if (err < 0) { |
| 3392 | perror("failed to create output file"); |
| 3393 | goto out; |
| 3394 | } |
| 3395 | } |
| 3396 | |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 3397 | trace.open_id = syscalltbl__id(trace.sctbl, "open"); |
| 3398 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 3399 | if (ev_qualifier_str != NULL) { |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 3400 | const char *s = ev_qualifier_str; |
Arnaldo Carvalho de Melo | 005438a8 | 2015-07-20 12:02:09 -0300 | [diff] [blame] | 3401 | struct strlist_config slist_config = { |
| 3402 | .dirname = system_path(STRACE_GROUPS_DIR), |
| 3403 | }; |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 3404 | |
| 3405 | trace.not_ev_qualifier = *s == '!'; |
| 3406 | if (trace.not_ev_qualifier) |
| 3407 | ++s; |
Arnaldo Carvalho de Melo | 005438a8 | 2015-07-20 12:02:09 -0300 | [diff] [blame] | 3408 | trace.ev_qualifier = strlist__new(s, &slist_config); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 3409 | if (trace.ev_qualifier == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3410 | fputs("Not enough memory to parse event qualifier", |
| 3411 | trace.output); |
| 3412 | err = -ENOMEM; |
| 3413 | goto out_close; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 3414 | } |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 3415 | |
| 3416 | err = trace__validate_ev_qualifier(&trace); |
| 3417 | if (err) |
| 3418 | goto out_close; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 3419 | } |
| 3420 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3421 | err = target__validate(&trace.opts.target); |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 3422 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3423 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3424 | fprintf(trace.output, "%s", bf); |
| 3425 | goto out_close; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 3426 | } |
| 3427 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3428 | err = target__parse_uid(&trace.opts.target); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3429 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3430 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3431 | fprintf(trace.output, "%s", bf); |
| 3432 | goto out_close; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3433 | } |
| 3434 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 3435 | if (!argc && target__none(&trace.opts.target)) |
Namhyung Kim | ee76120 | 2012-10-05 14:02:14 +0900 | [diff] [blame] | 3436 | trace.opts.target.system_wide = true; |
| 3437 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3438 | if (input_name) |
| 3439 | err = trace__replay(&trace); |
| 3440 | else |
| 3441 | err = trace__run(&trace, argc, argv); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3442 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3443 | out_close: |
| 3444 | if (output_name != NULL) |
| 3445 | fclose(trace.output); |
| 3446 | out: |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3447 | return err; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3448 | } |