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'") |
Arnaldo Carvalho de Melo | a598bb5 | 2015-08-28 12:02:37 -0300 | [diff] [blame] | 15 | */ |
| 16 | |
Arnaldo Carvalho de Melo | aeb00b1 | 2019-08-22 15:40:29 -0300 | [diff] [blame] | 17 | #include "util/record.h" |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 18 | #include <traceevent/event-parse.h> |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 19 | #include <api/fs/tracing_path.h> |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 20 | #include <bpf/bpf.h> |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 21 | #include "util/bpf_map.h" |
Arnaldo Carvalho de Melo | c3e78a3 | 2019-07-09 16:36:45 -0300 | [diff] [blame] | 22 | #include "util/rlimit.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 23 | #include "builtin.h" |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 24 | #include "util/cgroup.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 25 | #include "util/color.h" |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 26 | #include "util/config.h" |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 27 | #include "util/debug.h" |
Hendrik Brueckner | 092bd3c | 2018-01-19 09:56:16 +0100 | [diff] [blame] | 28 | #include "util/env.h" |
Arnaldo Carvalho de Melo | 5ab8c68 | 2017-04-25 15:30:47 -0300 | [diff] [blame] | 29 | #include "util/event.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 30 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 22ac431 | 2019-08-15 12:15:39 -0300 | [diff] [blame] | 31 | #include "util/evswitch.h" |
Arnaldo Carvalho de Melo | 8520a98 | 2019-08-29 16:18:59 -0300 | [diff] [blame^] | 32 | #include <subcmd/pager.h> |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 33 | #include <subcmd/exec-cmd.h> |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 34 | #include "util/machine.h" |
Arnaldo Carvalho de Melo | 1101f69 | 2019-01-27 13:42:37 +0100 | [diff] [blame] | 35 | #include "util/map.h" |
Arnaldo Carvalho de Melo | daecf9e | 2019-01-28 00:03:34 +0100 | [diff] [blame] | 36 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | 9a3993d | 2017-04-18 11:33:48 -0300 | [diff] [blame] | 37 | #include "util/path.h" |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 38 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 39 | #include "util/thread.h" |
Josh Poimboeuf | 4b6ab94 | 2015-12-15 09:39:39 -0600 | [diff] [blame] | 40 | #include <subcmd/parse-options.h> |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 41 | #include "util/strlist.h" |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 42 | #include "util/intlist.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 43 | #include "util/thread_map.h" |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 44 | #include "util/stat.h" |
Arnaldo Carvalho de Melo | 2da39f1 | 2019-08-27 11:51:18 -0300 | [diff] [blame] | 45 | #include "util/util.h" |
Arnaldo Carvalho de Melo | fd5cead | 2017-03-14 16:19:30 -0300 | [diff] [blame] | 46 | #include "trace/beauty/beauty.h" |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 47 | #include "trace-event.h" |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 48 | #include "util/parse-events.h" |
Wang Nan | ba50423 | 2016-02-26 09:31:54 +0000 | [diff] [blame] | 49 | #include "util/bpf-loader.h" |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 50 | #include "callchain.h" |
Arnaldo Carvalho de Melo | fea0139 | 2017-04-17 16:23:22 -0300 | [diff] [blame] | 51 | #include "print_binary.h" |
Arnaldo Carvalho de Melo | a067558 | 2017-04-17 16:51:59 -0300 | [diff] [blame] | 52 | #include "string2.h" |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 53 | #include "syscalltbl.h" |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 54 | #include "rb_resort.h" |
Arnaldo Carvalho de Melo | c1a604d | 2019-08-29 15:20:59 -0300 | [diff] [blame] | 55 | #include "../perf.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 56 | |
Arnaldo Carvalho de Melo | a43783a | 2017-04-18 10:46:11 -0300 | [diff] [blame] | 57 | #include <errno.h> |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 58 | #include <inttypes.h> |
Arnaldo Carvalho de Melo | 4208735 | 2017-04-19 19:06:30 -0300 | [diff] [blame] | 59 | #include <poll.h> |
Arnaldo Carvalho de Melo | 9607ad3 | 2017-04-19 15:49:18 -0300 | [diff] [blame] | 60 | #include <signal.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 61 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 62 | #include <string.h> |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 63 | #include <linux/err.h> |
Arnaldo Carvalho de Melo | 997bba8 | 2016-03-30 19:43:32 -0300 | [diff] [blame] | 64 | #include <linux/filter.h> |
Arnaldo Carvalho de Melo | 877a7a1 | 2017-04-17 11:39:06 -0300 | [diff] [blame] | 65 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 66 | #include <linux/random.h> |
Arnaldo Carvalho de Melo | c6d4a49 | 2016-04-14 18:29:08 -0300 | [diff] [blame] | 67 | #include <linux/stringify.h> |
Arnaldo Carvalho de Melo | bd48c63 | 2016-08-05 15:40:30 -0300 | [diff] [blame] | 68 | #include <linux/time64.h> |
Arnaldo Carvalho de Melo | 7f7c536 | 2019-07-04 11:32:27 -0300 | [diff] [blame] | 69 | #include <linux/zalloc.h> |
Arnaldo Carvalho de Melo | bafae98 | 2018-01-22 16:42:16 -0300 | [diff] [blame] | 70 | #include <fcntl.h> |
Arnaldo Carvalho de Melo | 4bcc4cf | 2018-12-27 13:32:59 -0300 | [diff] [blame] | 71 | #include <sys/sysmacros.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 72 | |
Arnaldo Carvalho de Melo | 3052ba5 | 2019-06-25 17:27:31 -0300 | [diff] [blame] | 73 | #include <linux/ctype.h> |
Arnaldo Carvalho de Melo | 3d689ed | 2017-04-17 16:10:49 -0300 | [diff] [blame] | 74 | |
Arnaldo Carvalho de Melo | c188e7a | 2015-05-14 17:39:03 -0300 | [diff] [blame] | 75 | #ifndef O_CLOEXEC |
| 76 | # define O_CLOEXEC 02000000 |
| 77 | #endif |
| 78 | |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 79 | #ifndef F_LINUX_SPECIFIC_BASE |
| 80 | # define F_LINUX_SPECIFIC_BASE 1024 |
| 81 | #endif |
| 82 | |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 83 | struct trace { |
| 84 | struct perf_tool tool; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 85 | struct syscalltbl *sctbl; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 86 | struct { |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 87 | struct syscall *table; |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 88 | struct bpf_map *map; |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 89 | struct { // per syscall BPF_MAP_TYPE_PROG_ARRAY |
| 90 | struct bpf_map *sys_enter, |
| 91 | *sys_exit; |
| 92 | } prog_array; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 93 | struct { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 94 | struct evsel *sys_enter, |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 95 | *sys_exit, |
| 96 | *augmented; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 97 | } events; |
Arnaldo Carvalho de Melo | 5834da7 | 2019-07-15 17:51:43 -0300 | [diff] [blame] | 98 | struct bpf_program *unaugmented_prog; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 99 | } syscalls; |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 100 | struct { |
| 101 | struct bpf_map *map; |
| 102 | } dump; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 103 | struct record_opts opts; |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 104 | struct evlist *evlist; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 105 | struct machine *host; |
| 106 | struct thread *current; |
Arnaldo Carvalho de Melo | c8c8057 | 2019-07-15 16:58:23 -0300 | [diff] [blame] | 107 | struct bpf_object *bpf_obj; |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 108 | struct cgroup *cgroup; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 109 | u64 base_time; |
| 110 | FILE *output; |
| 111 | unsigned long nr_events; |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 112 | unsigned long nr_events_printed; |
| 113 | unsigned long max_events; |
Arnaldo Carvalho de Melo | 22ac431 | 2019-08-15 12:15:39 -0300 | [diff] [blame] | 114 | struct evswitch evswitch; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 115 | struct strlist *ev_qualifier; |
| 116 | struct { |
| 117 | size_t nr; |
| 118 | int *entries; |
| 119 | } ev_qualifier_ids; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 120 | struct { |
| 121 | size_t nr; |
| 122 | pid_t *entries; |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 123 | struct bpf_map *map; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 124 | } filter_pids; |
| 125 | double duration_filter; |
| 126 | double runtime_ms; |
| 127 | struct { |
| 128 | u64 vfs_getname, |
| 129 | proc_getname; |
| 130 | } stats; |
Arnaldo Carvalho de Melo | c6d4a49 | 2016-04-14 18:29:08 -0300 | [diff] [blame] | 131 | unsigned int max_stack; |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 132 | unsigned int min_stack; |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 133 | int raw_augmented_syscalls_args_size; |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 134 | bool raw_augmented_syscalls; |
Arnaldo Carvalho de Melo | 79d725c | 2019-07-16 16:56:49 -0300 | [diff] [blame] | 135 | bool fd_path_disabled; |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 136 | bool sort_events; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 137 | bool not_ev_qualifier; |
| 138 | bool live; |
| 139 | bool full_time; |
| 140 | bool sched; |
| 141 | bool multiple_threads; |
| 142 | bool summary; |
| 143 | bool summary_only; |
Arnaldo Carvalho de Melo | 0a6545b | 2018-03-29 12:22:59 -0300 | [diff] [blame] | 144 | bool failure_only; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 145 | bool show_comm; |
Arnaldo Carvalho de Melo | 591421e | 2018-01-22 11:38:54 -0300 | [diff] [blame] | 146 | bool print_sample; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 147 | bool show_tool_stats; |
| 148 | bool trace_syscalls; |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 149 | bool kernel_syscallchains; |
Arnaldo Carvalho de Melo | 9ed45d5 | 2018-12-14 13:40:49 -0300 | [diff] [blame] | 150 | s16 args_alignment; |
Arnaldo Carvalho de Melo | b036146 | 2018-12-14 11:17:19 -0300 | [diff] [blame] | 151 | bool show_tstamp; |
Arnaldo Carvalho de Melo | 42e4a52 | 2018-12-14 10:22:18 -0300 | [diff] [blame] | 152 | bool show_duration; |
Arnaldo Carvalho de Melo | e7c634f | 2018-12-14 10:12:09 -0300 | [diff] [blame] | 153 | bool show_zeros; |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 154 | bool show_arg_names; |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 155 | bool show_string_prefix; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 156 | bool force; |
| 157 | bool vfs_getname; |
| 158 | int trace_pgfaults; |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 159 | struct { |
| 160 | struct ordered_events data; |
| 161 | u64 last; |
| 162 | } oe; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 163 | }; |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 164 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 165 | struct tp_field { |
| 166 | int offset; |
| 167 | union { |
| 168 | u64 (*integer)(struct tp_field *field, struct perf_sample *sample); |
| 169 | void *(*pointer)(struct tp_field *field, struct perf_sample *sample); |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | #define TP_UINT_FIELD(bits) \ |
| 174 | static u64 tp_field__u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 175 | { \ |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 176 | u##bits value; \ |
| 177 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
| 178 | return value; \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | TP_UINT_FIELD(8); |
| 182 | TP_UINT_FIELD(16); |
| 183 | TP_UINT_FIELD(32); |
| 184 | TP_UINT_FIELD(64); |
| 185 | |
| 186 | #define TP_UINT_FIELD__SWAPPED(bits) \ |
| 187 | static u64 tp_field__swapped_u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 188 | { \ |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 189 | u##bits value; \ |
| 190 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 191 | return bswap_##bits(value);\ |
| 192 | } |
| 193 | |
| 194 | TP_UINT_FIELD__SWAPPED(16); |
| 195 | TP_UINT_FIELD__SWAPPED(32); |
| 196 | TP_UINT_FIELD__SWAPPED(64); |
| 197 | |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 198 | static int __tp_field__init_uint(struct tp_field *field, int size, int offset, bool needs_swap) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 199 | { |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 200 | field->offset = offset; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 201 | |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 202 | switch (size) { |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 203 | case 1: |
| 204 | field->integer = tp_field__u8; |
| 205 | break; |
| 206 | case 2: |
| 207 | field->integer = needs_swap ? tp_field__swapped_u16 : tp_field__u16; |
| 208 | break; |
| 209 | case 4: |
| 210 | field->integer = needs_swap ? tp_field__swapped_u32 : tp_field__u32; |
| 211 | break; |
| 212 | case 8: |
| 213 | field->integer = needs_swap ? tp_field__swapped_u64 : tp_field__u64; |
| 214 | break; |
| 215 | default: |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 222 | static int tp_field__init_uint(struct tp_field *field, struct tep_format_field *format_field, bool needs_swap) |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 223 | { |
| 224 | return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap); |
| 225 | } |
| 226 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 227 | static void *tp_field__ptr(struct tp_field *field, struct perf_sample *sample) |
| 228 | { |
| 229 | return sample->raw_data + field->offset; |
| 230 | } |
| 231 | |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 232 | static int __tp_field__init_ptr(struct tp_field *field, int offset) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 233 | { |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 234 | field->offset = offset; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 235 | field->pointer = tp_field__ptr; |
| 236 | return 0; |
| 237 | } |
| 238 | |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 239 | static int tp_field__init_ptr(struct tp_field *field, struct tep_format_field *format_field) |
Arnaldo Carvalho de Melo | aa823f5 | 2018-08-02 15:03:02 -0300 | [diff] [blame] | 240 | { |
| 241 | return __tp_field__init_ptr(field, format_field->offset); |
| 242 | } |
| 243 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 244 | struct syscall_tp { |
| 245 | struct tp_field id; |
| 246 | union { |
| 247 | struct tp_field args, ret; |
| 248 | }; |
| 249 | }; |
| 250 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 251 | static int perf_evsel__init_tp_uint_field(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 252 | struct tp_field *field, |
| 253 | const char *name) |
| 254 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 255 | struct tep_format_field *format_field = perf_evsel__field(evsel, name); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 256 | |
| 257 | if (format_field == NULL) |
| 258 | return -1; |
| 259 | |
| 260 | return tp_field__init_uint(field, format_field, evsel->needs_swap); |
| 261 | } |
| 262 | |
| 263 | #define perf_evsel__init_sc_tp_uint_field(evsel, name) \ |
| 264 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 265 | perf_evsel__init_tp_uint_field(evsel, &sc->name, #name); }) |
| 266 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 267 | static int perf_evsel__init_tp_ptr_field(struct evsel *evsel, |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 268 | struct tp_field *field, |
| 269 | const char *name) |
| 270 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 271 | struct tep_format_field *format_field = perf_evsel__field(evsel, name); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 272 | |
| 273 | if (format_field == NULL) |
| 274 | return -1; |
| 275 | |
| 276 | return tp_field__init_ptr(field, format_field); |
| 277 | } |
| 278 | |
| 279 | #define perf_evsel__init_sc_tp_ptr_field(evsel, name) \ |
| 280 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 281 | perf_evsel__init_tp_ptr_field(evsel, &sc->name, #name); }) |
| 282 | |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 283 | static void evsel__delete_priv(struct evsel *evsel) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 284 | { |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 285 | zfree(&evsel->priv); |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 286 | evsel__delete(evsel); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 287 | } |
| 288 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 289 | static int perf_evsel__init_syscall_tp(struct evsel *evsel) |
Arnaldo Carvalho de Melo | d32855f | 2018-08-02 15:09:24 -0300 | [diff] [blame] | 290 | { |
| 291 | struct syscall_tp *sc = evsel->priv = malloc(sizeof(struct syscall_tp)); |
| 292 | |
| 293 | if (evsel->priv != NULL) { |
Arnaldo Carvalho de Melo | 42da438 | 2018-12-05 13:08:11 -0300 | [diff] [blame] | 294 | if (perf_evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") && |
| 295 | perf_evsel__init_tp_uint_field(evsel, &sc->id, "nr")) |
Arnaldo Carvalho de Melo | d32855f | 2018-08-02 15:09:24 -0300 | [diff] [blame] | 296 | goto out_delete; |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | return -ENOMEM; |
| 301 | out_delete: |
| 302 | zfree(&evsel->priv); |
| 303 | return -ENOENT; |
| 304 | } |
| 305 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 306 | static int perf_evsel__init_augmented_syscall_tp(struct evsel *evsel, struct evsel *tp) |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 307 | { |
| 308 | struct syscall_tp *sc = evsel->priv = malloc(sizeof(struct syscall_tp)); |
| 309 | |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 310 | if (evsel->priv != NULL) { |
| 311 | struct tep_format_field *syscall_id = perf_evsel__field(tp, "id"); |
| 312 | if (syscall_id == NULL) |
| 313 | syscall_id = perf_evsel__field(tp, "__syscall_nr"); |
| 314 | if (syscall_id == NULL) |
| 315 | goto out_delete; |
| 316 | if (__tp_field__init_uint(&sc->id, syscall_id->size, syscall_id->offset, evsel->needs_swap)) |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 317 | goto out_delete; |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | return -ENOMEM; |
| 323 | out_delete: |
| 324 | zfree(&evsel->priv); |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 328 | static int perf_evsel__init_augmented_syscall_tp_args(struct evsel *evsel) |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 329 | { |
| 330 | struct syscall_tp *sc = evsel->priv; |
| 331 | |
| 332 | return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)); |
| 333 | } |
| 334 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 335 | static int perf_evsel__init_augmented_syscall_tp_ret(struct evsel *evsel) |
Arnaldo Carvalho de Melo | b1a9e25 | 2018-09-03 16:29:39 -0300 | [diff] [blame] | 336 | { |
| 337 | struct syscall_tp *sc = evsel->priv; |
| 338 | |
| 339 | return __tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap); |
| 340 | } |
| 341 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 342 | static int perf_evsel__init_raw_syscall_tp(struct evsel *evsel, void *handler) |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 343 | { |
| 344 | evsel->priv = malloc(sizeof(struct syscall_tp)); |
| 345 | if (evsel->priv != NULL) { |
| 346 | if (perf_evsel__init_sc_tp_uint_field(evsel, id)) |
| 347 | goto out_delete; |
| 348 | |
| 349 | evsel->handler = handler; |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | return -ENOMEM; |
| 354 | |
| 355 | out_delete: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 356 | zfree(&evsel->priv); |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 357 | return -ENOENT; |
| 358 | } |
| 359 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 360 | static struct evsel *perf_evsel__raw_syscall_newtp(const char *direction, void *handler) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 361 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 362 | struct evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 363 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 364 | /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */ |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 365 | if (IS_ERR(evsel)) |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 366 | evsel = perf_evsel__newtp("syscalls", direction); |
| 367 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 368 | if (IS_ERR(evsel)) |
| 369 | return NULL; |
| 370 | |
Arnaldo Carvalho de Melo | 63f11c8 | 2018-08-02 14:27:09 -0300 | [diff] [blame] | 371 | if (perf_evsel__init_raw_syscall_tp(evsel, handler)) |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 372 | goto out_delete; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 373 | |
| 374 | return evsel; |
| 375 | |
| 376 | out_delete: |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 377 | evsel__delete_priv(evsel); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 378 | return NULL; |
| 379 | } |
| 380 | |
| 381 | #define perf_evsel__sc_tp_uint(evsel, name, sample) \ |
| 382 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 383 | fields->name.integer(&fields->name, sample); }) |
| 384 | |
| 385 | #define perf_evsel__sc_tp_ptr(evsel, name, sample) \ |
| 386 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 387 | fields->name.pointer(&fields->name, sample); }) |
| 388 | |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 389 | size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, bool show_prefix, int val) |
Arnaldo Carvalho de Melo | 0ae7963 | 2017-07-17 10:31:42 -0300 | [diff] [blame] | 390 | { |
| 391 | int idx = val - sa->offset; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 392 | |
Arnaldo Carvalho de Melo | 9614b8d | 2018-12-18 10:54:19 -0300 | [diff] [blame] | 393 | if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) { |
| 394 | size_t printed = scnprintf(bf, size, intfmt, val); |
| 395 | if (show_prefix) |
| 396 | printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix); |
| 397 | return printed; |
| 398 | } |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 399 | |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 400 | return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 401 | } |
| 402 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 403 | static size_t __syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 404 | const char *intfmt, |
| 405 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 406 | { |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 407 | return strarray__scnprintf(arg->parm, bf, size, intfmt, arg->show_string_prefix, arg->val); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 408 | } |
| 409 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 410 | static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 411 | struct syscall_arg *arg) |
| 412 | { |
| 413 | return __syscall_arg__scnprintf_strarray(bf, size, "%d", arg); |
| 414 | } |
| 415 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 416 | #define SCA_STRARRAY syscall_arg__scnprintf_strarray |
| 417 | |
Arnaldo Carvalho de Melo | f5b91db | 2019-05-23 18:05:03 -0300 | [diff] [blame] | 418 | size_t syscall_arg__scnprintf_strarray_flags(char *bf, size_t size, struct syscall_arg *arg) |
| 419 | { |
| 420 | return strarray__scnprintf_flags(arg->parm, bf, size, arg->show_string_prefix, arg->val); |
| 421 | } |
| 422 | |
Arnaldo Carvalho de Melo | 1f2d085 | 2018-12-18 10:25:28 -0300 | [diff] [blame] | 423 | size_t strarrays__scnprintf(struct strarrays *sas, char *bf, size_t size, const char *intfmt, bool show_prefix, int val) |
| 424 | { |
Arnaldo Carvalho de Melo | 9614b8d | 2018-12-18 10:54:19 -0300 | [diff] [blame] | 425 | size_t printed; |
Arnaldo Carvalho de Melo | 1f2d085 | 2018-12-18 10:25:28 -0300 | [diff] [blame] | 426 | int i; |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 427 | |
Arnaldo Carvalho de Melo | 1f2d085 | 2018-12-18 10:25:28 -0300 | [diff] [blame] | 428 | for (i = 0; i < sas->nr_entries; ++i) { |
| 429 | struct strarray *sa = sas->entries[i]; |
| 430 | int idx = val - sa->offset; |
| 431 | |
| 432 | if (idx >= 0 && idx < sa->nr_entries) { |
| 433 | if (sa->entries[idx] == NULL) |
| 434 | break; |
| 435 | return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); |
| 436 | } |
| 437 | } |
| 438 | |
Arnaldo Carvalho de Melo | 9614b8d | 2018-12-18 10:54:19 -0300 | [diff] [blame] | 439 | printed = scnprintf(bf, size, intfmt, val); |
| 440 | if (show_prefix) |
| 441 | printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sas->entries[0]->prefix); |
| 442 | return printed; |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 443 | } |
| 444 | |
Arnaldo Carvalho de Melo | 274e86f | 2017-07-14 09:38:38 -0300 | [diff] [blame] | 445 | size_t syscall_arg__scnprintf_strarrays(char *bf, size_t size, |
| 446 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 447 | { |
Arnaldo Carvalho de Melo | 1f2d085 | 2018-12-18 10:25:28 -0300 | [diff] [blame] | 448 | return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix, arg->val); |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 449 | } |
| 450 | |
Arnaldo Carvalho de Melo | 48e1f91 | 2016-07-05 14:43:27 -0300 | [diff] [blame] | 451 | #ifndef AT_FDCWD |
| 452 | #define AT_FDCWD -100 |
| 453 | #endif |
| 454 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 455 | static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size, |
| 456 | struct syscall_arg *arg) |
| 457 | { |
| 458 | int fd = arg->val; |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 459 | const char *prefix = "AT_FD"; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 460 | |
| 461 | if (fd == AT_FDCWD) |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 462 | return scnprintf(bf, size, "%s%s", arg->show_string_prefix ? prefix : "", "CWD"); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 463 | |
| 464 | return syscall_arg__scnprintf_fd(bf, size, arg); |
| 465 | } |
| 466 | |
| 467 | #define SCA_FDAT syscall_arg__scnprintf_fd_at |
| 468 | |
| 469 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 470 | struct syscall_arg *arg); |
| 471 | |
| 472 | #define SCA_CLOSE_FD syscall_arg__scnprintf_close_fd |
| 473 | |
Arnaldo Carvalho de Melo | 2c2b162 | 2017-07-14 10:19:18 -0300 | [diff] [blame] | 474 | size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 475 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 476 | return scnprintf(bf, size, "%#lx", arg->val); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 477 | } |
| 478 | |
Arnaldo Carvalho de Melo | ce05539 | 2018-12-17 12:21:09 -0300 | [diff] [blame] | 479 | size_t syscall_arg__scnprintf_ptr(char *bf, size_t size, struct syscall_arg *arg) |
| 480 | { |
| 481 | if (arg->val == 0) |
| 482 | return scnprintf(bf, size, "NULL"); |
| 483 | return syscall_arg__scnprintf_hex(bf, size, arg); |
| 484 | } |
| 485 | |
Arnaldo Carvalho de Melo | 2c2b162 | 2017-07-14 10:19:18 -0300 | [diff] [blame] | 486 | size_t syscall_arg__scnprintf_int(char *bf, size_t size, struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | a1c2552 | 2015-06-11 22:47:54 -0300 | [diff] [blame] | 487 | { |
| 488 | return scnprintf(bf, size, "%d", arg->val); |
| 489 | } |
| 490 | |
Arnaldo Carvalho de Melo | 5dde91e | 2017-07-14 10:34:16 -0300 | [diff] [blame] | 491 | size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg) |
| 492 | { |
| 493 | return scnprintf(bf, size, "%ld", arg->val); |
| 494 | } |
| 495 | |
Arnaldo Carvalho de Melo | 729a784 | 2015-10-29 11:48:18 -0300 | [diff] [blame] | 496 | static const char *bpf_cmd[] = { |
| 497 | "MAP_CREATE", "MAP_LOOKUP_ELEM", "MAP_UPDATE_ELEM", "MAP_DELETE_ELEM", |
| 498 | "MAP_GET_NEXT_KEY", "PROG_LOAD", |
| 499 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 500 | static DEFINE_STRARRAY(bpf_cmd, "BPF_"); |
Arnaldo Carvalho de Melo | 729a784 | 2015-10-29 11:48:18 -0300 | [diff] [blame] | 501 | |
Arnaldo Carvalho de Melo | f6af095 | 2019-05-21 16:34:03 -0300 | [diff] [blame] | 502 | static const char *fsmount_flags[] = { |
| 503 | [1] = "CLOEXEC", |
| 504 | }; |
| 505 | static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_"); |
| 506 | |
Arnaldo Carvalho de Melo | dcc6fd6 | 2019-05-21 15:36:44 -0300 | [diff] [blame] | 507 | #include "trace/beauty/generated/fsconfig_arrays.c" |
| 508 | |
| 509 | static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_"); |
| 510 | |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 511 | static const char *epoll_ctl_ops[] = { "ADD", "DEL", "MOD", }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 512 | static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, "EPOLL_CTL_", 1); |
Arnaldo Carvalho de Melo | eac032c | 2013-09-20 11:27:32 -0300 | [diff] [blame] | 513 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 514 | static const char *itimers[] = { "REAL", "VIRTUAL", "PROF", }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 515 | static DEFINE_STRARRAY(itimers, "ITIMER_"); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 516 | |
Arnaldo Carvalho de Melo | b62bee1 | 2015-08-11 11:05:36 -0300 | [diff] [blame] | 517 | static const char *keyctl_options[] = { |
| 518 | "GET_KEYRING_ID", "JOIN_SESSION_KEYRING", "UPDATE", "REVOKE", "CHOWN", |
| 519 | "SETPERM", "DESCRIBE", "CLEAR", "LINK", "UNLINK", "SEARCH", "READ", |
| 520 | "INSTANTIATE", "NEGATE", "SET_REQKEY_KEYRING", "SET_TIMEOUT", |
| 521 | "ASSUME_AUTHORITY", "GET_SECURITY", "SESSION_TO_PARENT", "REJECT", |
| 522 | "INSTANTIATE_IOV", "INVALIDATE", "GET_PERSISTENT", |
| 523 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 524 | static DEFINE_STRARRAY(keyctl_options, "KEYCTL_"); |
Arnaldo Carvalho de Melo | b62bee1 | 2015-08-11 11:05:36 -0300 | [diff] [blame] | 525 | |
Arnaldo Carvalho de Melo | efe6b88 | 2013-09-03 16:15:12 -0300 | [diff] [blame] | 526 | static const char *whences[] = { "SET", "CUR", "END", |
| 527 | #ifdef SEEK_DATA |
| 528 | "DATA", |
| 529 | #endif |
| 530 | #ifdef SEEK_HOLE |
| 531 | "HOLE", |
| 532 | #endif |
| 533 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 534 | static DEFINE_STRARRAY(whences, "SEEK_"); |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 535 | |
Arnaldo Carvalho de Melo | 80f587d | 2013-09-03 16:28:58 -0300 | [diff] [blame] | 536 | static const char *fcntl_cmds[] = { |
| 537 | "DUPFD", "GETFD", "SETFD", "GETFL", "SETFL", "GETLK", "SETLK", |
Arnaldo Carvalho de Melo | e000e5e | 2017-07-13 13:07:00 -0300 | [diff] [blame] | 538 | "SETLKW", "SETOWN", "GETOWN", "SETSIG", "GETSIG", "GETLK64", |
| 539 | "SETLK64", "SETLKW64", "SETOWN_EX", "GETOWN_EX", |
| 540 | "GETOWNER_UIDS", |
Arnaldo Carvalho de Melo | 80f587d | 2013-09-03 16:28:58 -0300 | [diff] [blame] | 541 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 542 | static DEFINE_STRARRAY(fcntl_cmds, "F_"); |
Arnaldo Carvalho de Melo | 80f587d | 2013-09-03 16:28:58 -0300 | [diff] [blame] | 543 | |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 544 | static const char *fcntl_linux_specific_cmds[] = { |
| 545 | "SETLEASE", "GETLEASE", "NOTIFY", [5] = "CANCELLK", "DUPFD_CLOEXEC", |
| 546 | "SETPIPE_SZ", "GETPIPE_SZ", "ADD_SEALS", "GET_SEALS", |
Arnaldo Carvalho de Melo | 64e4561 | 2017-07-13 17:34:46 -0300 | [diff] [blame] | 547 | "GET_RW_HINT", "SET_RW_HINT", "GET_FILE_RW_HINT", "SET_FILE_RW_HINT", |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 548 | }; |
| 549 | |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 550 | static DEFINE_STRARRAY_OFFSET(fcntl_linux_specific_cmds, "F_", F_LINUX_SPECIFIC_BASE); |
Arnaldo Carvalho de Melo | 83a5169 | 2017-07-13 17:14:11 -0300 | [diff] [blame] | 551 | |
| 552 | static struct strarray *fcntl_cmds_arrays[] = { |
| 553 | &strarray__fcntl_cmds, |
| 554 | &strarray__fcntl_linux_specific_cmds, |
| 555 | }; |
| 556 | |
| 557 | static DEFINE_STRARRAYS(fcntl_cmds_arrays); |
| 558 | |
Arnaldo Carvalho de Melo | c045bf0 | 2013-09-04 11:52:33 -0300 | [diff] [blame] | 559 | static const char *rlimit_resources[] = { |
| 560 | "CPU", "FSIZE", "DATA", "STACK", "CORE", "RSS", "NPROC", "NOFILE", |
| 561 | "MEMLOCK", "AS", "LOCKS", "SIGPENDING", "MSGQUEUE", "NICE", "RTPRIO", |
| 562 | "RTTIME", |
| 563 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 564 | static DEFINE_STRARRAY(rlimit_resources, "RLIMIT_"); |
Arnaldo Carvalho de Melo | c045bf0 | 2013-09-04 11:52:33 -0300 | [diff] [blame] | 565 | |
Arnaldo Carvalho de Melo | eb5b1b1 | 2013-09-03 16:37:46 -0300 | [diff] [blame] | 566 | static const char *sighow[] = { "BLOCK", "UNBLOCK", "SETMASK", }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 567 | static DEFINE_STRARRAY(sighow, "SIG_"); |
Arnaldo Carvalho de Melo | eb5b1b1 | 2013-09-03 16:37:46 -0300 | [diff] [blame] | 568 | |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 569 | static const char *clockid[] = { |
| 570 | "REALTIME", "MONOTONIC", "PROCESS_CPUTIME_ID", "THREAD_CPUTIME_ID", |
Arnaldo Carvalho de Melo | 28ebb87 | 2015-08-11 10:38:38 -0300 | [diff] [blame] | 571 | "MONOTONIC_RAW", "REALTIME_COARSE", "MONOTONIC_COARSE", "BOOTTIME", |
| 572 | "REALTIME_ALARM", "BOOTTIME_ALARM", "SGI_CYCLE", "TAI" |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 573 | }; |
Arnaldo Carvalho de Melo | 2e3d7fac | 2018-12-14 15:08:40 -0300 | [diff] [blame] | 574 | static DEFINE_STRARRAY(clockid, "CLOCK_"); |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 575 | |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 576 | static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size, |
| 577 | struct syscall_arg *arg) |
| 578 | { |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 579 | bool show_prefix = arg->show_string_prefix; |
| 580 | const char *suffix = "_OK"; |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 581 | size_t printed = 0; |
| 582 | int mode = arg->val; |
| 583 | |
| 584 | if (mode == F_OK) /* 0 */ |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 585 | return scnprintf(bf, size, "F%s", show_prefix ? suffix : ""); |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 586 | #define P_MODE(n) \ |
| 587 | if (mode & n##_OK) { \ |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 588 | printed += scnprintf(bf + printed, size - printed, "%s%s", #n, show_prefix ? suffix : ""); \ |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 589 | mode &= ~n##_OK; \ |
| 590 | } |
| 591 | |
| 592 | P_MODE(R); |
| 593 | P_MODE(W); |
| 594 | P_MODE(X); |
| 595 | #undef P_MODE |
| 596 | |
| 597 | if (mode) |
| 598 | printed += scnprintf(bf + printed, size - printed, "|%#x", mode); |
| 599 | |
| 600 | return printed; |
| 601 | } |
| 602 | |
| 603 | #define SCA_ACCMODE syscall_arg__scnprintf_access_mode |
| 604 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 605 | static size_t syscall_arg__scnprintf_filename(char *bf, size_t size, |
| 606 | struct syscall_arg *arg); |
| 607 | |
| 608 | #define SCA_FILENAME syscall_arg__scnprintf_filename |
| 609 | |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 610 | static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size, |
| 611 | struct syscall_arg *arg) |
| 612 | { |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 613 | bool show_prefix = arg->show_string_prefix; |
| 614 | const char *prefix = "O_"; |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 615 | int printed = 0, flags = arg->val; |
| 616 | |
| 617 | #define P_FLAG(n) \ |
| 618 | if (flags & O_##n) { \ |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 619 | printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 620 | flags &= ~O_##n; \ |
| 621 | } |
| 622 | |
| 623 | P_FLAG(CLOEXEC); |
| 624 | P_FLAG(NONBLOCK); |
| 625 | #undef P_FLAG |
| 626 | |
| 627 | if (flags) |
| 628 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 629 | |
| 630 | return printed; |
| 631 | } |
| 632 | |
| 633 | #define SCA_PIPE_FLAGS syscall_arg__scnprintf_pipe_flags |
| 634 | |
Arnaldo Carvalho de Melo | a355a61 | 2016-04-13 11:55:18 -0300 | [diff] [blame] | 635 | #ifndef GRND_NONBLOCK |
| 636 | #define GRND_NONBLOCK 0x0001 |
| 637 | #endif |
| 638 | #ifndef GRND_RANDOM |
| 639 | #define GRND_RANDOM 0x0002 |
| 640 | #endif |
| 641 | |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 642 | static size_t syscall_arg__scnprintf_getrandom_flags(char *bf, size_t size, |
| 643 | struct syscall_arg *arg) |
| 644 | { |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 645 | bool show_prefix = arg->show_string_prefix; |
| 646 | const char *prefix = "GRND_"; |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 647 | int printed = 0, flags = arg->val; |
| 648 | |
| 649 | #define P_FLAG(n) \ |
| 650 | if (flags & GRND_##n) { \ |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 651 | printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \ |
Arnaldo Carvalho de Melo | 39878d4 | 2016-03-30 20:02:15 -0300 | [diff] [blame] | 652 | flags &= ~GRND_##n; \ |
| 653 | } |
| 654 | |
| 655 | P_FLAG(RANDOM); |
| 656 | P_FLAG(NONBLOCK); |
| 657 | #undef P_FLAG |
| 658 | |
| 659 | if (flags) |
| 660 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 661 | |
| 662 | return printed; |
| 663 | } |
| 664 | |
| 665 | #define SCA_GETRANDOM_FLAGS syscall_arg__scnprintf_getrandom_flags |
| 666 | |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 667 | #define STRARRAY(name, array) \ |
| 668 | { .scnprintf = SCA_STRARRAY, \ |
| 669 | .parm = &strarray__##array, } |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 670 | |
Arnaldo Carvalho de Melo | f6af095 | 2019-05-21 16:34:03 -0300 | [diff] [blame] | 671 | #define STRARRAY_FLAGS(name, array) \ |
| 672 | { .scnprintf = SCA_STRARRAY_FLAGS, \ |
| 673 | .parm = &strarray__##array, } |
| 674 | |
Hendrik Brueckner | 092bd3c | 2018-01-19 09:56:16 +0100 | [diff] [blame] | 675 | #include "trace/beauty/arch_errno_names.c" |
Arnaldo Carvalho de Melo | ea8dc3c | 2016-04-13 12:10:19 -0300 | [diff] [blame] | 676 | #include "trace/beauty/eventfd.c" |
Arnaldo Carvalho de Melo | d5d71e8 | 2016-05-06 12:45:25 -0300 | [diff] [blame] | 677 | #include "trace/beauty/futex_op.c" |
Arnaldo Carvalho de Melo | 3258abe | 2018-01-22 12:56:59 -0300 | [diff] [blame] | 678 | #include "trace/beauty/futex_val3.c" |
Arnaldo Carvalho de Melo | df4cb16 | 2016-04-13 12:05:44 -0300 | [diff] [blame] | 679 | #include "trace/beauty/mmap.c" |
Arnaldo Carvalho de Melo | ba2f22c | 2016-04-07 12:05:51 -0300 | [diff] [blame] | 680 | #include "trace/beauty/mode_t.c" |
Arnaldo Carvalho de Melo | a30e625 | 2016-04-27 19:01:52 -0300 | [diff] [blame] | 681 | #include "trace/beauty/msg_flags.c" |
Arnaldo Carvalho de Melo | 8f48df6 | 2016-05-06 10:02:32 -0300 | [diff] [blame] | 682 | #include "trace/beauty/open_flags.c" |
Arnaldo Carvalho de Melo | 62de344 | 2016-04-26 11:03:03 -0300 | [diff] [blame] | 683 | #include "trace/beauty/perf_event_open.c" |
Arnaldo Carvalho de Melo | d5d71e8 | 2016-05-06 12:45:25 -0300 | [diff] [blame] | 684 | #include "trace/beauty/pid.c" |
Arnaldo Carvalho de Melo | a3bca91 | 2016-04-06 12:51:33 -0300 | [diff] [blame] | 685 | #include "trace/beauty/sched_policy.c" |
Arnaldo Carvalho de Melo | f5cd95e | 2016-05-11 10:32:20 -0300 | [diff] [blame] | 686 | #include "trace/beauty/seccomp.c" |
Arnaldo Carvalho de Melo | 12199d8 | 2016-05-06 09:58:02 -0300 | [diff] [blame] | 687 | #include "trace/beauty/signum.c" |
Arnaldo Carvalho de Melo | bbf86c4 | 2016-04-14 13:53:10 -0300 | [diff] [blame] | 688 | #include "trace/beauty/socket_type.c" |
Arnaldo Carvalho de Melo | 7206b90 | 2016-04-06 14:11:36 -0300 | [diff] [blame] | 689 | #include "trace/beauty/waitid_options.c" |
Arnaldo Carvalho de Melo | a3bca91 | 2016-04-06 12:51:33 -0300 | [diff] [blame] | 690 | |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 691 | struct syscall_arg_fmt { |
| 692 | size_t (*scnprintf)(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | 496fd34 | 2018-10-25 16:09:47 -0300 | [diff] [blame] | 693 | unsigned long (*mask_val)(struct syscall_arg *arg, unsigned long val); |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 694 | void *parm; |
Arnaldo Carvalho de Melo | c51bdfe | 2017-07-19 15:47:30 -0300 | [diff] [blame] | 695 | const char *name; |
Arnaldo Carvalho de Melo | d47737d | 2017-07-17 15:59:03 -0300 | [diff] [blame] | 696 | bool show_zero; |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 697 | }; |
| 698 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 699 | static struct syscall_fmt { |
| 700 | const char *name; |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 701 | const char *alias; |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 702 | struct { |
| 703 | const char *sys_enter, |
| 704 | *sys_exit; |
| 705 | } bpf_prog_name; |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 706 | struct syscall_arg_fmt arg[6]; |
Arnaldo Carvalho de Melo | 332337d | 2017-07-19 15:08:14 -0300 | [diff] [blame] | 707 | u8 nr_args; |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 708 | bool errpid; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 709 | bool timeout; |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 710 | bool hexret; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 711 | } syscall_fmts[] = { |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 712 | { .name = "access", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 713 | .arg = { [1] = { .scnprintf = SCA_ACCMODE, /* mode */ }, }, }, |
Arnaldo Carvalho de Melo | fb7068e | 2018-12-18 11:05:56 -0300 | [diff] [blame] | 714 | { .name = "arch_prctl", |
| 715 | .arg = { [0] = { .scnprintf = SCA_X86_ARCH_PRCTL_CODE, /* code */ }, |
| 716 | [1] = { .scnprintf = SCA_PTR, /* arg2 */ }, }, }, |
Arnaldo Carvalho de Melo | 02ef288 | 2018-08-28 17:03:53 -0300 | [diff] [blame] | 717 | { .name = "bind", |
Arnaldo Carvalho de Melo | ef969ca64 | 2019-07-16 17:21:09 -0300 | [diff] [blame] | 718 | .arg = { [0] = { .scnprintf = SCA_INT, /* fd */ }, |
Arnaldo Carvalho de Melo | 247dd65 | 2019-07-16 17:38:26 -0300 | [diff] [blame] | 719 | [1] = { .scnprintf = SCA_SOCKADDR, /* umyaddr */ }, |
| 720 | [2] = { .scnprintf = SCA_INT, /* addrlen */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 721 | { .name = "bpf", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 722 | .arg = { [0] = STRARRAY(cmd, bpf_cmd), }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 723 | { .name = "brk", .hexret = true, |
Arnaldo Carvalho de Melo | ce05539 | 2018-12-17 12:21:09 -0300 | [diff] [blame] | 724 | .arg = { [0] = { .scnprintf = SCA_PTR, /* brk */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 725 | { .name = "clock_gettime", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 726 | .arg = { [0] = STRARRAY(clk_id, clockid), }, }, |
Arnaldo Carvalho de Melo | 33396a3 | 2017-07-19 16:15:17 -0300 | [diff] [blame] | 727 | { .name = "clone", .errpid = true, .nr_args = 5, |
| 728 | .arg = { [0] = { .name = "flags", .scnprintf = SCA_CLONE_FLAGS, }, |
| 729 | [1] = { .name = "child_stack", .scnprintf = SCA_HEX, }, |
| 730 | [2] = { .name = "parent_tidptr", .scnprintf = SCA_HEX, }, |
| 731 | [3] = { .name = "child_tidptr", .scnprintf = SCA_HEX, }, |
| 732 | [4] = { .name = "tls", .scnprintf = SCA_HEX, }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 733 | { .name = "close", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 734 | .arg = { [0] = { .scnprintf = SCA_CLOSE_FD, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | d5a7e66 | 2018-08-28 16:24:44 -0300 | [diff] [blame] | 735 | { .name = "connect", |
Arnaldo Carvalho de Melo | ef969ca64 | 2019-07-16 17:21:09 -0300 | [diff] [blame] | 736 | .arg = { [0] = { .scnprintf = SCA_INT, /* fd */ }, |
| 737 | [1] = { .scnprintf = SCA_SOCKADDR, /* servaddr */ }, |
Arnaldo Carvalho de Melo | 1d86275 | 2019-07-16 16:34:27 -0300 | [diff] [blame] | 738 | [2] = { .scnprintf = SCA_INT, /* addrlen */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 739 | { .name = "epoll_ctl", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 740 | .arg = { [1] = STRARRAY(op, epoll_ctl_ops), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 741 | { .name = "eventfd2", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 742 | .arg = { [1] = { .scnprintf = SCA_EFD_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 743 | { .name = "fchmodat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 744 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 745 | { .name = "fchownat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 746 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 747 | { .name = "fcntl", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 748 | .arg = { [1] = { .scnprintf = SCA_FCNTL_CMD, /* cmd */ |
Arnaldo Carvalho de Melo | 39cc355 | 2017-07-17 16:02:52 -0300 | [diff] [blame] | 749 | .parm = &strarrays__fcntl_cmds_arrays, |
| 750 | .show_zero = true, }, |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 751 | [2] = { .scnprintf = SCA_FCNTL_ARG, /* arg */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 752 | { .name = "flock", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 753 | .arg = { [1] = { .scnprintf = SCA_FLOCK, /* cmd */ }, }, }, |
Arnaldo Carvalho de Melo | dcc6fd6 | 2019-05-21 15:36:44 -0300 | [diff] [blame] | 754 | { .name = "fsconfig", |
| 755 | .arg = { [1] = STRARRAY(cmd, fsconfig_cmds), }, }, |
Arnaldo Carvalho de Melo | f6af095 | 2019-05-21 16:34:03 -0300 | [diff] [blame] | 756 | { .name = "fsmount", |
| 757 | .arg = { [1] = STRARRAY_FLAGS(flags, fsmount_flags), |
| 758 | [2] = { .scnprintf = SCA_FSMOUNT_ATTR_FLAGS, /* attr_flags */ }, }, }, |
Arnaldo Carvalho de Melo | 693bd39 | 2019-05-20 16:24:15 -0300 | [diff] [blame] | 759 | { .name = "fspick", |
| 760 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, |
| 761 | [1] = { .scnprintf = SCA_FILENAME, /* path */ }, |
| 762 | [2] = { .scnprintf = SCA_FSPICK_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 763 | { .name = "fstat", .alias = "newfstat", }, |
| 764 | { .name = "fstatat", .alias = "newfstatat", }, |
| 765 | { .name = "futex", |
Arnaldo Carvalho de Melo | 3258abe | 2018-01-22 12:56:59 -0300 | [diff] [blame] | 766 | .arg = { [1] = { .scnprintf = SCA_FUTEX_OP, /* op */ }, |
| 767 | [5] = { .scnprintf = SCA_FUTEX_VAL3, /* val3 */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 768 | { .name = "futimesat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 769 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 770 | { .name = "getitimer", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 771 | .arg = { [0] = STRARRAY(which, itimers), }, }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 772 | { .name = "getpid", .errpid = true, }, |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 773 | { .name = "getpgid", .errpid = true, }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 774 | { .name = "getppid", .errpid = true, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 775 | { .name = "getrandom", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 776 | .arg = { [2] = { .scnprintf = SCA_GETRANDOM_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 777 | { .name = "getrlimit", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 778 | .arg = { [0] = STRARRAY(resource, rlimit_resources), }, }, |
Arnaldo Carvalho de Melo | 2d1073d | 2018-01-09 12:03:47 -0300 | [diff] [blame] | 779 | { .name = "gettid", .errpid = true, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 780 | { .name = "ioctl", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 781 | .arg = { |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 782 | #if defined(__i386__) || defined(__x86_64__) |
| 783 | /* |
| 784 | * FIXME: Make this available to all arches. |
| 785 | */ |
Arnaldo Carvalho de Melo | 1cc47f2d | 2017-07-31 13:20:14 -0300 | [diff] [blame] | 786 | [1] = { .scnprintf = SCA_IOCTL_CMD, /* cmd */ }, |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 787 | [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, }, |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 788 | #else |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 789 | [2] = { .scnprintf = SCA_HEX, /* arg */ }, }, }, |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 790 | #endif |
Arnaldo Carvalho de Melo | 1de3038 | 2017-10-31 11:32:23 -0300 | [diff] [blame] | 791 | { .name = "kcmp", .nr_args = 5, |
| 792 | .arg = { [0] = { .name = "pid1", .scnprintf = SCA_PID, }, |
| 793 | [1] = { .name = "pid2", .scnprintf = SCA_PID, }, |
| 794 | [2] = { .name = "type", .scnprintf = SCA_KCMP_TYPE, }, |
| 795 | [3] = { .name = "idx1", .scnprintf = SCA_KCMP_IDX, }, |
| 796 | [4] = { .name = "idx2", .scnprintf = SCA_KCMP_IDX, }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 797 | { .name = "keyctl", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 798 | .arg = { [0] = STRARRAY(option, keyctl_options), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 799 | { .name = "kill", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 800 | .arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 801 | { .name = "linkat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 802 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 803 | { .name = "lseek", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 804 | .arg = { [2] = STRARRAY(whence, whences), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 805 | { .name = "lstat", .alias = "newlstat", }, |
| 806 | { .name = "madvise", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 807 | .arg = { [0] = { .scnprintf = SCA_HEX, /* start */ }, |
| 808 | [2] = { .scnprintf = SCA_MADV_BHV, /* behavior */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 809 | { .name = "mkdirat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 810 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 811 | { .name = "mknodat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 812 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fd */ }, }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 813 | { .name = "mmap", .hexret = true, |
Jiri Olsa | 5426566 | 2017-05-31 13:35:57 +0200 | [diff] [blame] | 814 | /* The standard mmap maps to old_mmap on s390x */ |
| 815 | #if defined(__s390x__) |
| 816 | .alias = "old_mmap", |
| 817 | #endif |
Arnaldo Carvalho de Melo | ce05539 | 2018-12-17 12:21:09 -0300 | [diff] [blame] | 818 | .arg = { [2] = { .scnprintf = SCA_MMAP_PROT, /* prot */ }, |
Arnaldo Carvalho de Melo | a663134 | 2018-12-18 11:25:08 -0300 | [diff] [blame] | 819 | [3] = { .scnprintf = SCA_MMAP_FLAGS, /* flags */ }, |
| 820 | [5] = { .scnprintf = SCA_HEX, /* offset */ }, }, }, |
Arnaldo Carvalho de Melo | 73d141a | 2018-10-25 15:18:06 -0300 | [diff] [blame] | 821 | { .name = "mount", |
Arnaldo Carvalho de Melo | 23c07a2 | 2018-10-26 13:51:45 -0300 | [diff] [blame] | 822 | .arg = { [0] = { .scnprintf = SCA_FILENAME, /* dev_name */ }, |
| 823 | [3] = { .scnprintf = SCA_MOUNT_FLAGS, /* flags */ |
Arnaldo Carvalho de Melo | 73d141a | 2018-10-25 15:18:06 -0300 | [diff] [blame] | 824 | .mask_val = SCAMV_MOUNT_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 566e302 | 2019-05-20 14:58:03 -0300 | [diff] [blame] | 825 | { .name = "move_mount", |
| 826 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* from_dfd */ }, |
| 827 | [1] = { .scnprintf = SCA_FILENAME, /* from_pathname */ }, |
| 828 | [2] = { .scnprintf = SCA_FDAT, /* to_dfd */ }, |
| 829 | [3] = { .scnprintf = SCA_FILENAME, /* to_pathname */ }, |
| 830 | [4] = { .scnprintf = SCA_MOVE_MOUNT_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 831 | { .name = "mprotect", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 832 | .arg = { [0] = { .scnprintf = SCA_HEX, /* start */ }, |
| 833 | [2] = { .scnprintf = SCA_MMAP_PROT, /* prot */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 834 | { .name = "mq_unlink", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 835 | .arg = { [0] = { .scnprintf = SCA_FILENAME, /* u_name */ }, }, }, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 836 | { .name = "mremap", .hexret = true, |
Arnaldo Carvalho de Melo | ce05539 | 2018-12-17 12:21:09 -0300 | [diff] [blame] | 837 | .arg = { [3] = { .scnprintf = SCA_MREMAP_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 838 | { .name = "name_to_handle_at", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 839 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 840 | { .name = "newfstatat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 841 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 842 | { .name = "open", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 843 | .arg = { [1] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 844 | { .name = "open_by_handle_at", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 845 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, |
| 846 | [2] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 847 | { .name = "openat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 848 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, |
| 849 | [2] = { .scnprintf = SCA_OPEN_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 850 | { .name = "perf_event_open", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 851 | .arg = { [2] = { .scnprintf = SCA_INT, /* cpu */ }, |
| 852 | [3] = { .scnprintf = SCA_FD, /* group_fd */ }, |
| 853 | [4] = { .scnprintf = SCA_PERF_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 854 | { .name = "pipe2", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 855 | .arg = { [1] = { .scnprintf = SCA_PIPE_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 83bc9c37 | 2017-08-28 11:47:11 -0300 | [diff] [blame] | 856 | { .name = "pkey_alloc", |
| 857 | .arg = { [1] = { .scnprintf = SCA_PKEY_ALLOC_ACCESS_RIGHTS, /* access_rights */ }, }, }, |
| 858 | { .name = "pkey_free", |
| 859 | .arg = { [0] = { .scnprintf = SCA_INT, /* key */ }, }, }, |
| 860 | { .name = "pkey_mprotect", |
| 861 | .arg = { [0] = { .scnprintf = SCA_HEX, /* start */ }, |
| 862 | [2] = { .scnprintf = SCA_MMAP_PROT, /* prot */ }, |
| 863 | [3] = { .scnprintf = SCA_INT, /* pkey */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 864 | { .name = "poll", .timeout = true, }, |
| 865 | { .name = "ppoll", .timeout = true, }, |
Arnaldo Carvalho de Melo | fb7068e | 2018-12-18 11:05:56 -0300 | [diff] [blame] | 866 | { .name = "prctl", |
Arnaldo Carvalho de Melo | d688d03 | 2017-10-26 15:19:35 -0300 | [diff] [blame] | 867 | .arg = { [0] = { .scnprintf = SCA_PRCTL_OPTION, /* option */ }, |
| 868 | [1] = { .scnprintf = SCA_PRCTL_ARG2, /* arg2 */ }, |
| 869 | [2] = { .scnprintf = SCA_PRCTL_ARG3, /* arg3 */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 870 | { .name = "pread", .alias = "pread64", }, |
| 871 | { .name = "preadv", .alias = "pread", }, |
| 872 | { .name = "prlimit64", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 873 | .arg = { [1] = STRARRAY(resource, rlimit_resources), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 874 | { .name = "pwrite", .alias = "pwrite64", }, |
| 875 | { .name = "readlinkat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 876 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 877 | { .name = "recvfrom", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 878 | .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 879 | { .name = "recvmmsg", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 880 | .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 881 | { .name = "recvmsg", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 882 | .arg = { [2] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 883 | { .name = "renameat", |
Arnaldo Carvalho de Melo | 436651c | 2018-12-11 11:19:23 -0300 | [diff] [blame] | 884 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* olddirfd */ }, |
| 885 | [2] = { .scnprintf = SCA_FDAT, /* newdirfd */ }, }, }, |
Arnaldo Carvalho de Melo | 84a8354 | 2018-12-11 09:53:21 -0300 | [diff] [blame] | 886 | { .name = "renameat2", |
| 887 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* olddirfd */ }, |
Arnaldo Carvalho de Melo | ca7ff2c | 2018-12-11 10:39:30 -0300 | [diff] [blame] | 888 | [2] = { .scnprintf = SCA_FDAT, /* newdirfd */ }, |
| 889 | [4] = { .scnprintf = SCA_RENAMEAT2_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 890 | { .name = "rt_sigaction", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 891 | .arg = { [0] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 892 | { .name = "rt_sigprocmask", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 893 | .arg = { [0] = STRARRAY(how, sighow), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 894 | { .name = "rt_sigqueueinfo", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 895 | .arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 896 | { .name = "rt_tgsigqueueinfo", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 897 | .arg = { [2] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 898 | { .name = "sched_setscheduler", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 899 | .arg = { [1] = { .scnprintf = SCA_SCHED_POLICY, /* policy */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 900 | { .name = "seccomp", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 901 | .arg = { [0] = { .scnprintf = SCA_SECCOMP_OP, /* op */ }, |
| 902 | [1] = { .scnprintf = SCA_SECCOMP_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 903 | { .name = "select", .timeout = true, }, |
Arnaldo Carvalho de Melo | e4b00e9 | 2019-07-17 20:32:13 -0300 | [diff] [blame] | 904 | { .name = "sendfile", .alias = "sendfile64", }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 905 | { .name = "sendmmsg", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 906 | .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 907 | { .name = "sendmsg", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 908 | .arg = { [2] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 909 | { .name = "sendto", |
Arnaldo Carvalho de Melo | 6ebb686 | 2018-08-29 08:47:08 -0300 | [diff] [blame] | 910 | .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, |
| 911 | [4] = { .scnprintf = SCA_SOCKADDR, /* addr */ }, }, }, |
Arnaldo Carvalho de Melo | c65f107 | 2016-04-06 14:55:18 -0300 | [diff] [blame] | 912 | { .name = "set_tid_address", .errpid = true, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 913 | { .name = "setitimer", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 914 | .arg = { [0] = STRARRAY(which, itimers), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 915 | { .name = "setrlimit", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 916 | .arg = { [0] = STRARRAY(resource, rlimit_resources), }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 917 | { .name = "socket", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 918 | .arg = { [0] = STRARRAY(family, socket_families), |
Arnaldo Carvalho de Melo | 162d3ed | 2018-07-26 09:26:13 -0300 | [diff] [blame] | 919 | [1] = { .scnprintf = SCA_SK_TYPE, /* type */ }, |
| 920 | [2] = { .scnprintf = SCA_SK_PROTO, /* protocol */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 921 | { .name = "socketpair", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 922 | .arg = { [0] = STRARRAY(family, socket_families), |
Arnaldo Carvalho de Melo | 162d3ed | 2018-07-26 09:26:13 -0300 | [diff] [blame] | 923 | [1] = { .scnprintf = SCA_SK_TYPE, /* type */ }, |
| 924 | [2] = { .scnprintf = SCA_SK_PROTO, /* protocol */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 925 | { .name = "stat", .alias = "newstat", }, |
| 926 | { .name = "statx", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 927 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* fdat */ }, |
| 928 | [2] = { .scnprintf = SCA_STATX_FLAGS, /* flags */ } , |
| 929 | [3] = { .scnprintf = SCA_STATX_MASK, /* mask */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 930 | { .name = "swapoff", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 931 | .arg = { [0] = { .scnprintf = SCA_FILENAME, /* specialfile */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 932 | { .name = "swapon", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 933 | .arg = { [0] = { .scnprintf = SCA_FILENAME, /* specialfile */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 934 | { .name = "symlinkat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 935 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, |
Arnaldo Carvalho de Melo | a9a187a | 2019-05-21 21:47:07 -0300 | [diff] [blame] | 936 | { .name = "sync_file_range", |
| 937 | .arg = { [3] = { .scnprintf = SCA_SYNC_FILE_RANGE_FLAGS, /* flags */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 938 | { .name = "tgkill", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 939 | .arg = { [2] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 940 | { .name = "tkill", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 941 | .arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, |
Arnaldo Carvalho de Melo | 476c92ca | 2018-10-26 13:23:25 -0300 | [diff] [blame] | 942 | { .name = "umount2", .alias = "umount", |
| 943 | .arg = { [0] = { .scnprintf = SCA_FILENAME, /* name */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 944 | { .name = "uname", .alias = "newuname", }, |
| 945 | { .name = "unlinkat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 946 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 947 | { .name = "utimensat", |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 948 | .arg = { [0] = { .scnprintf = SCA_FDAT, /* dirfd */ }, }, }, |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 949 | { .name = "wait4", .errpid = true, |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 950 | .arg = { [2] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, }, |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 951 | { .name = "waitid", .errpid = true, |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 952 | .arg = { [3] = { .scnprintf = SCA_WAITID_OPTIONS, /* options */ }, }, }, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 953 | }; |
| 954 | |
| 955 | static int syscall_fmt__cmp(const void *name, const void *fmtp) |
| 956 | { |
| 957 | const struct syscall_fmt *fmt = fmtp; |
| 958 | return strcmp(name, fmt->name); |
| 959 | } |
| 960 | |
| 961 | static struct syscall_fmt *syscall_fmt__find(const char *name) |
| 962 | { |
| 963 | const int nmemb = ARRAY_SIZE(syscall_fmts); |
| 964 | return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); |
| 965 | } |
| 966 | |
Arnaldo Carvalho de Melo | f932184 | 2018-10-25 17:24:45 -0300 | [diff] [blame] | 967 | static struct syscall_fmt *syscall_fmt__find_by_alias(const char *alias) |
| 968 | { |
| 969 | int i, nmemb = ARRAY_SIZE(syscall_fmts); |
| 970 | |
| 971 | for (i = 0; i < nmemb; ++i) { |
| 972 | if (syscall_fmts[i].alias && strcmp(syscall_fmts[i].alias, alias) == 0) |
| 973 | return &syscall_fmts[i]; |
| 974 | } |
| 975 | |
| 976 | return NULL; |
| 977 | } |
| 978 | |
Arnaldo Carvalho de Melo | 6a648b5 | 2018-08-02 10:30:08 -0300 | [diff] [blame] | 979 | /* |
| 980 | * is_exit: is this "exit" or "exit_group"? |
| 981 | * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter. |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 982 | * args_size: sum of the sizes of the syscall arguments, anything after that is augmented stuff: pathname for openat, etc. |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 983 | * nonexistent: Just a hole in the syscall table, syscall id not allocated |
Arnaldo Carvalho de Melo | 6a648b5 | 2018-08-02 10:30:08 -0300 | [diff] [blame] | 984 | */ |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 985 | struct syscall { |
Tzvetomir Stoyanov | 97fbf3f | 2018-11-30 10:44:07 -0500 | [diff] [blame] | 986 | struct tep_event *tp_format; |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 987 | int nr_args; |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 988 | int args_size; |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 989 | struct { |
| 990 | struct bpf_program *sys_enter, |
| 991 | *sys_exit; |
| 992 | } bpf_prog; |
Arnaldo Carvalho de Melo | 6a648b5 | 2018-08-02 10:30:08 -0300 | [diff] [blame] | 993 | bool is_exit; |
| 994 | bool is_open; |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 995 | bool nonexistent; |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 996 | struct tep_format_field *args; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 997 | const char *name; |
| 998 | struct syscall_fmt *fmt; |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 999 | struct syscall_arg_fmt *arg_fmt; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1000 | }; |
| 1001 | |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 1002 | /* |
| 1003 | * Must match what is in the BPF program: |
| 1004 | * |
| 1005 | * tools/perf/examples/bpf/augmented_raw_syscalls.c |
| 1006 | */ |
Arnaldo Carvalho de Melo | bbab50d | 2018-12-12 16:54:09 -0300 | [diff] [blame] | 1007 | struct bpf_map_syscall_entry { |
| 1008 | bool enabled; |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 1009 | u16 string_args_len[6]; |
Arnaldo Carvalho de Melo | bbab50d | 2018-12-12 16:54:09 -0300 | [diff] [blame] | 1010 | }; |
| 1011 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1012 | /* |
| 1013 | * We need to have this 'calculated' boolean because in some cases we really |
| 1014 | * don't know what is the duration of a syscall, for instance, when we start |
| 1015 | * a session and some threads are waiting for a syscall to finish, say 'poll', |
| 1016 | * in which case all we can do is to print "( ? ) for duration and for the |
| 1017 | * start timestamp. |
| 1018 | */ |
| 1019 | static size_t fprintf_duration(unsigned long t, bool calculated, FILE *fp) |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1020 | { |
| 1021 | double duration = (double)t / NSEC_PER_MSEC; |
| 1022 | size_t printed = fprintf(fp, "("); |
| 1023 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1024 | if (!calculated) |
Arnaldo Carvalho de Melo | 522283f | 2018-01-22 11:42:11 -0300 | [diff] [blame] | 1025 | printed += fprintf(fp, " "); |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1026 | else if (duration >= 1.0) |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1027 | printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); |
| 1028 | else if (duration >= 0.01) |
| 1029 | printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); |
| 1030 | else |
| 1031 | 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] | 1032 | return printed + fprintf(fp, "): "); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1033 | } |
| 1034 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1035 | /** |
| 1036 | * filename.ptr: The filename char pointer that will be vfs_getname'd |
| 1037 | * filename.entry_str_pos: Where to insert the string translated from |
| 1038 | * filename.ptr by the vfs_getname tracepoint/kprobe. |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 1039 | * ret_scnprintf: syscall args may set this to a different syscall return |
| 1040 | * formatter, for instance, fcntl may return fds, file flags, etc. |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1041 | */ |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1042 | struct thread_trace { |
| 1043 | u64 entry_time; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1044 | bool entry_pending; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1045 | unsigned long nr_events; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 1046 | unsigned long pfmaj, pfmin; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1047 | char *entry_str; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1048 | double runtime_ms; |
Arnaldo Carvalho de Melo | 7ee5743 | 2017-07-14 15:16:54 -0300 | [diff] [blame] | 1049 | size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1050 | struct { |
| 1051 | unsigned long ptr; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 1052 | short int entry_str_pos; |
| 1053 | bool pending_open; |
| 1054 | unsigned int namelen; |
| 1055 | char *name; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1056 | } filename; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1057 | struct { |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1058 | int max; |
| 1059 | struct file *table; |
| 1060 | } files; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1061 | |
| 1062 | struct intlist *syscall_stats; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1063 | }; |
| 1064 | |
| 1065 | static struct thread_trace *thread_trace__new(void) |
| 1066 | { |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1067 | struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); |
| 1068 | |
Leo Yan | 7a6d49d | 2019-07-02 18:34:14 +0800 | [diff] [blame] | 1069 | if (ttrace) { |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1070 | ttrace->files.max = -1; |
Leo Yan | 7a6d49d | 2019-07-02 18:34:14 +0800 | [diff] [blame] | 1071 | ttrace->syscall_stats = intlist__new(NULL); |
| 1072 | } |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1073 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1074 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1075 | } |
| 1076 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1077 | 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] | 1078 | { |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1079 | struct thread_trace *ttrace; |
| 1080 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1081 | if (thread == NULL) |
| 1082 | goto fail; |
| 1083 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1084 | if (thread__priv(thread) == NULL) |
| 1085 | thread__set_priv(thread, thread_trace__new()); |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1086 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1087 | if (thread__priv(thread) == NULL) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1088 | goto fail; |
| 1089 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1090 | ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1091 | ++ttrace->nr_events; |
| 1092 | |
| 1093 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1094 | fail: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1095 | color_fprintf(fp, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1096 | "WARNING: not enough memory, dropping samples!\n"); |
| 1097 | return NULL; |
| 1098 | } |
| 1099 | |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 1100 | |
| 1101 | void syscall_arg__set_ret_scnprintf(struct syscall_arg *arg, |
Arnaldo Carvalho de Melo | 7ee5743 | 2017-07-14 15:16:54 -0300 | [diff] [blame] | 1102 | size_t (*ret_scnprintf)(char *bf, size_t size, struct syscall_arg *arg)) |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 1103 | { |
| 1104 | struct thread_trace *ttrace = thread__priv(arg->thread); |
| 1105 | |
| 1106 | ttrace->ret_scnprintf = ret_scnprintf; |
| 1107 | } |
| 1108 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1109 | #define TRACE_PFMAJ (1 << 0) |
| 1110 | #define TRACE_PFMIN (1 << 1) |
| 1111 | |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 1112 | static const size_t trace__entry_str_size = 2048; |
| 1113 | |
Arnaldo Carvalho de Melo | d7e1348 | 2018-12-27 11:05:18 -0300 | [diff] [blame] | 1114 | static struct file *thread_trace__files_entry(struct thread_trace *ttrace, int fd) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1115 | { |
Arnaldo Carvalho de Melo | 0510748 | 2019-02-12 10:18:36 -0300 | [diff] [blame] | 1116 | if (fd < 0) |
| 1117 | return NULL; |
| 1118 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1119 | if (fd > ttrace->files.max) { |
| 1120 | struct file *nfiles = realloc(ttrace->files.table, (fd + 1) * sizeof(struct file)); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1121 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1122 | if (nfiles == NULL) |
Arnaldo Carvalho de Melo | d7e1348 | 2018-12-27 11:05:18 -0300 | [diff] [blame] | 1123 | return NULL; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1124 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1125 | if (ttrace->files.max != -1) { |
| 1126 | memset(nfiles + ttrace->files.max + 1, 0, |
| 1127 | (fd - ttrace->files.max) * sizeof(struct file)); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1128 | } else { |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1129 | memset(nfiles, 0, (fd + 1) * sizeof(struct file)); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1130 | } |
| 1131 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1132 | ttrace->files.table = nfiles; |
| 1133 | ttrace->files.max = fd; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1134 | } |
| 1135 | |
Arnaldo Carvalho de Melo | d7e1348 | 2018-12-27 11:05:18 -0300 | [diff] [blame] | 1136 | return ttrace->files.table + fd; |
| 1137 | } |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1138 | |
Arnaldo Carvalho de Melo | 2d47338 | 2018-12-27 16:19:33 -0300 | [diff] [blame] | 1139 | struct file *thread__files_entry(struct thread *thread, int fd) |
| 1140 | { |
| 1141 | return thread_trace__files_entry(thread__priv(thread), fd); |
| 1142 | } |
| 1143 | |
Arnaldo Carvalho de Melo | d7e1348 | 2018-12-27 11:05:18 -0300 | [diff] [blame] | 1144 | static int trace__set_fd_pathname(struct thread *thread, int fd, const char *pathname) |
| 1145 | { |
| 1146 | struct thread_trace *ttrace = thread__priv(thread); |
| 1147 | struct file *file = thread_trace__files_entry(ttrace, fd); |
| 1148 | |
| 1149 | if (file != NULL) { |
Arnaldo Carvalho de Melo | 4bcc4cf | 2018-12-27 13:32:59 -0300 | [diff] [blame] | 1150 | struct stat st; |
| 1151 | if (stat(pathname, &st) == 0) |
| 1152 | file->dev_maj = major(st.st_rdev); |
Arnaldo Carvalho de Melo | d7e1348 | 2018-12-27 11:05:18 -0300 | [diff] [blame] | 1153 | file->pathname = strdup(pathname); |
| 1154 | if (file->pathname) |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | return -1; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1159 | } |
| 1160 | |
Arnaldo Carvalho de Melo | 97119f3 | 2013-09-27 17:34:10 -0300 | [diff] [blame] | 1161 | static int thread__read_fd_path(struct thread *thread, int fd) |
| 1162 | { |
| 1163 | char linkname[PATH_MAX], pathname[PATH_MAX]; |
| 1164 | struct stat st; |
| 1165 | int ret; |
| 1166 | |
| 1167 | if (thread->pid_ == thread->tid) { |
| 1168 | scnprintf(linkname, sizeof(linkname), |
| 1169 | "/proc/%d/fd/%d", thread->pid_, fd); |
| 1170 | } else { |
| 1171 | scnprintf(linkname, sizeof(linkname), |
| 1172 | "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd); |
| 1173 | } |
| 1174 | |
| 1175 | if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname)) |
| 1176 | return -1; |
| 1177 | |
| 1178 | ret = readlink(linkname, pathname, sizeof(pathname)); |
| 1179 | |
| 1180 | if (ret < 0 || ret > st.st_size) |
| 1181 | return -1; |
| 1182 | |
| 1183 | pathname[ret] = '\0'; |
| 1184 | return trace__set_fd_pathname(thread, fd, pathname); |
| 1185 | } |
| 1186 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1187 | static const char *thread__fd_path(struct thread *thread, int fd, |
| 1188 | struct trace *trace) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1189 | { |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1190 | struct thread_trace *ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1191 | |
Arnaldo Carvalho de Melo | 79d725c | 2019-07-16 16:56:49 -0300 | [diff] [blame] | 1192 | if (ttrace == NULL || trace->fd_path_disabled) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1193 | return NULL; |
| 1194 | |
| 1195 | if (fd < 0) |
| 1196 | return NULL; |
| 1197 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1198 | if ((fd > ttrace->files.max || ttrace->files.table[fd].pathname == NULL)) { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1199 | if (!trace->live) |
| 1200 | return NULL; |
| 1201 | ++trace->stats.proc_getname; |
Arnaldo Carvalho de Melo | cdcd1e6 | 2014-06-10 16:00:18 -0300 | [diff] [blame] | 1202 | if (thread__read_fd_path(thread, fd)) |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1203 | return NULL; |
| 1204 | } |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1205 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1206 | return ttrace->files.table[fd].pathname; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1207 | } |
| 1208 | |
Arnaldo Carvalho de Melo | fc65eb8 | 2017-07-14 15:21:40 -0300 | [diff] [blame] | 1209 | size_t syscall_arg__scnprintf_fd(char *bf, size_t size, struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1210 | { |
| 1211 | int fd = arg->val; |
| 1212 | size_t printed = scnprintf(bf, size, "%d", fd); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1213 | 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] | 1214 | |
| 1215 | if (path) |
| 1216 | printed += scnprintf(bf + printed, size - printed, "<%s>", path); |
| 1217 | |
| 1218 | return printed; |
| 1219 | } |
| 1220 | |
Arnaldo Carvalho de Melo | 0a2f7540 | 2017-10-31 11:30:09 -0300 | [diff] [blame] | 1221 | size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size) |
| 1222 | { |
| 1223 | size_t printed = scnprintf(bf, size, "%d", fd); |
| 1224 | struct thread *thread = machine__find_thread(trace->host, pid, pid); |
| 1225 | |
| 1226 | if (thread) { |
| 1227 | const char *path = thread__fd_path(thread, fd, trace); |
| 1228 | |
| 1229 | if (path) |
| 1230 | printed += scnprintf(bf + printed, size - printed, "<%s>", path); |
| 1231 | |
| 1232 | thread__put(thread); |
| 1233 | } |
| 1234 | |
| 1235 | return printed; |
| 1236 | } |
| 1237 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1238 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 1239 | struct syscall_arg *arg) |
| 1240 | { |
| 1241 | int fd = arg->val; |
| 1242 | size_t printed = syscall_arg__scnprintf_fd(bf, size, arg); |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1243 | struct thread_trace *ttrace = thread__priv(arg->thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1244 | |
Arnaldo Carvalho de Melo | f4a74fc | 2018-12-27 10:56:12 -0300 | [diff] [blame] | 1245 | if (ttrace && fd >= 0 && fd <= ttrace->files.max) |
| 1246 | zfree(&ttrace->files.table[fd].pathname); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1247 | |
| 1248 | return printed; |
| 1249 | } |
| 1250 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1251 | static void thread__set_filename_pos(struct thread *thread, const char *bf, |
| 1252 | unsigned long ptr) |
| 1253 | { |
| 1254 | struct thread_trace *ttrace = thread__priv(thread); |
| 1255 | |
| 1256 | ttrace->filename.ptr = ptr; |
| 1257 | ttrace->filename.entry_str_pos = bf - ttrace->entry_str; |
| 1258 | } |
| 1259 | |
Arnaldo Carvalho de Melo | 75d1e30 | 2018-08-21 12:00:39 -0300 | [diff] [blame] | 1260 | static size_t syscall_arg__scnprintf_augmented_string(struct syscall_arg *arg, char *bf, size_t size) |
| 1261 | { |
| 1262 | struct augmented_arg *augmented_arg = arg->augmented.args; |
Arnaldo Carvalho de Melo | 8195168 | 2019-06-05 10:34:47 -0300 | [diff] [blame] | 1263 | size_t printed = scnprintf(bf, size, "\"%.*s\"", augmented_arg->size, augmented_arg->value); |
| 1264 | /* |
| 1265 | * So that the next arg with a payload can consume its augmented arg, i.e. for rename* syscalls |
| 1266 | * we would have two strings, each prefixed by its size. |
| 1267 | */ |
| 1268 | int consumed = sizeof(*augmented_arg) + augmented_arg->size; |
Arnaldo Carvalho de Melo | 75d1e30 | 2018-08-21 12:00:39 -0300 | [diff] [blame] | 1269 | |
Arnaldo Carvalho de Melo | 016f327 | 2019-06-14 16:50:19 -0300 | [diff] [blame] | 1270 | arg->augmented.args = ((void *)arg->augmented.args) + consumed; |
Arnaldo Carvalho de Melo | 8195168 | 2019-06-05 10:34:47 -0300 | [diff] [blame] | 1271 | arg->augmented.size -= consumed; |
| 1272 | |
| 1273 | return printed; |
Arnaldo Carvalho de Melo | 75d1e30 | 2018-08-21 12:00:39 -0300 | [diff] [blame] | 1274 | } |
| 1275 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1276 | static size_t syscall_arg__scnprintf_filename(char *bf, size_t size, |
| 1277 | struct syscall_arg *arg) |
| 1278 | { |
| 1279 | unsigned long ptr = arg->val; |
| 1280 | |
Arnaldo Carvalho de Melo | 75d1e30 | 2018-08-21 12:00:39 -0300 | [diff] [blame] | 1281 | if (arg->augmented.args) |
| 1282 | return syscall_arg__scnprintf_augmented_string(arg, bf, size); |
| 1283 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 1284 | if (!arg->trace->vfs_getname) |
| 1285 | return scnprintf(bf, size, "%#x", ptr); |
| 1286 | |
| 1287 | thread__set_filename_pos(arg->thread, bf, ptr); |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1291 | static bool trace__filter_duration(struct trace *trace, double t) |
| 1292 | { |
| 1293 | return t < (trace->duration_filter * NSEC_PER_MSEC); |
| 1294 | } |
| 1295 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1296 | static size_t __trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1297 | { |
| 1298 | double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; |
| 1299 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1300 | return fprintf(fp, "%10.3f ", ts); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1301 | } |
| 1302 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1303 | /* |
| 1304 | * We're handling tstamp=0 as an undefined tstamp, i.e. like when we are |
| 1305 | * using ttrace->entry_time for a thread that receives a sys_exit without |
| 1306 | * first having received a sys_enter ("poll" issued before tracing session |
| 1307 | * starts, lost sys_enter exit due to ring buffer overflow). |
| 1308 | */ |
| 1309 | static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
| 1310 | { |
| 1311 | if (tstamp > 0) |
| 1312 | return __trace__fprintf_tstamp(trace, tstamp, fp); |
| 1313 | |
| 1314 | return fprintf(fp, " ? "); |
| 1315 | } |
| 1316 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1317 | static bool done = false; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1318 | static bool interrupted = false; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1319 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1320 | static void sig_handler(int sig) |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1321 | { |
| 1322 | done = true; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1323 | interrupted = sig == SIGINT; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1324 | } |
| 1325 | |
Arnaldo Carvalho de Melo | 6dcbd21 | 2018-08-21 11:40:09 -0300 | [diff] [blame] | 1326 | static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1327 | { |
Arnaldo Carvalho de Melo | 6dcbd21 | 2018-08-21 11:40:09 -0300 | [diff] [blame] | 1328 | size_t printed = 0; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1329 | |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1330 | if (trace->multiple_threads) { |
| 1331 | if (trace->show_comm) |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 1332 | printed += fprintf(fp, "%.14s/", thread__comm_str(thread)); |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1333 | printed += fprintf(fp, "%d ", thread->tid); |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1334 | } |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1335 | |
| 1336 | return printed; |
| 1337 | } |
| 1338 | |
Arnaldo Carvalho de Melo | 6dcbd21 | 2018-08-21 11:40:09 -0300 | [diff] [blame] | 1339 | static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, |
| 1340 | u64 duration, bool duration_calculated, u64 tstamp, FILE *fp) |
| 1341 | { |
Arnaldo Carvalho de Melo | b036146 | 2018-12-14 11:17:19 -0300 | [diff] [blame] | 1342 | size_t printed = 0; |
| 1343 | |
| 1344 | if (trace->show_tstamp) |
| 1345 | printed = trace__fprintf_tstamp(trace, tstamp, fp); |
Arnaldo Carvalho de Melo | 42e4a52 | 2018-12-14 10:22:18 -0300 | [diff] [blame] | 1346 | if (trace->show_duration) |
| 1347 | printed += fprintf_duration(duration, duration_calculated, fp); |
Arnaldo Carvalho de Melo | 6dcbd21 | 2018-08-21 11:40:09 -0300 | [diff] [blame] | 1348 | return printed + trace__fprintf_comm_tid(trace, thread, fp); |
| 1349 | } |
| 1350 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1351 | static int trace__process_event(struct trace *trace, struct machine *machine, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1352 | union perf_event *event, struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1353 | { |
| 1354 | int ret = 0; |
| 1355 | |
| 1356 | switch (event->header.type) { |
| 1357 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1358 | color_fprintf(trace->output, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1359 | "LOST %" PRIu64 " events!\n", event->lost.lost); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1360 | ret = machine__process_lost_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 3ed5ca2 | 2016-03-30 16:51:17 -0300 | [diff] [blame] | 1361 | break; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1362 | default: |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1363 | ret = machine__process_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1364 | break; |
| 1365 | } |
| 1366 | |
| 1367 | return ret; |
| 1368 | } |
| 1369 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1370 | static int trace__tool_process(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1371 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1372 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1373 | struct machine *machine) |
| 1374 | { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1375 | struct trace *trace = container_of(tool, struct trace, tool); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1376 | return trace__process_event(trace, machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1377 | } |
| 1378 | |
Arnaldo Carvalho de Melo | caf8a0d | 2016-05-17 11:56:24 -0300 | [diff] [blame] | 1379 | static char *trace__machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp) |
| 1380 | { |
| 1381 | struct machine *machine = vmachine; |
| 1382 | |
| 1383 | if (machine->kptr_restrict_warned) |
| 1384 | return NULL; |
| 1385 | |
| 1386 | if (symbol_conf.kptr_restrict) { |
| 1387 | pr_warning("Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n" |
Igor Lubashev | d06e5fa | 2019-08-26 21:39:16 -0400 | [diff] [blame] | 1388 | "Check /proc/sys/kernel/kptr_restrict and /proc/sys/kernel/perf_event_paranoid.\n\n" |
Arnaldo Carvalho de Melo | caf8a0d | 2016-05-17 11:56:24 -0300 | [diff] [blame] | 1389 | "Kernel samples will not be resolved.\n"); |
| 1390 | machine->kptr_restrict_warned = true; |
| 1391 | return NULL; |
| 1392 | } |
| 1393 | |
| 1394 | return machine__resolve_kernel_addr(vmachine, addrp, modp); |
| 1395 | } |
| 1396 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 1397 | static int trace__symbols_init(struct trace *trace, struct evlist *evlist) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1398 | { |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1399 | int err = symbol__init(NULL); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1400 | |
| 1401 | if (err) |
| 1402 | return err; |
| 1403 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1404 | trace->host = machine__new_host(); |
| 1405 | if (trace->host == NULL) |
| 1406 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1407 | |
Andrei Vagin | cbd5c17 | 2017-11-07 16:22:46 -0800 | [diff] [blame] | 1408 | err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); |
| 1409 | if (err < 0) |
| 1410 | goto out; |
Arnaldo Carvalho de Melo | 706c3da | 2015-07-22 16:16:16 -0300 | [diff] [blame] | 1411 | |
Arnaldo Carvalho de Melo | a33fbd5 | 2013-11-11 11:36:12 -0300 | [diff] [blame] | 1412 | err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, |
Jiri Olsa | 03617c2 | 2019-07-21 13:24:42 +0200 | [diff] [blame] | 1413 | evlist->core.threads, trace__tool_process, false, |
Mark Drayton | 3fcb10e | 2018-12-04 12:34:20 -0800 | [diff] [blame] | 1414 | 1); |
Andrei Vagin | cbd5c17 | 2017-11-07 16:22:46 -0800 | [diff] [blame] | 1415 | out: |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1416 | if (err) |
| 1417 | symbol__exit(); |
| 1418 | |
| 1419 | return err; |
| 1420 | } |
| 1421 | |
Andrei Vagin | 33974a4 | 2017-11-07 16:22:45 -0800 | [diff] [blame] | 1422 | static void trace__symbols__exit(struct trace *trace) |
| 1423 | { |
| 1424 | machine__exit(trace->host); |
| 1425 | trace->host = NULL; |
| 1426 | |
| 1427 | symbol__exit(); |
| 1428 | } |
| 1429 | |
Arnaldo Carvalho de Melo | 5e58fcf | 2017-07-19 14:32:11 -0300 | [diff] [blame] | 1430 | static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args) |
| 1431 | { |
| 1432 | int idx; |
| 1433 | |
Arnaldo Carvalho de Melo | 332337d | 2017-07-19 15:08:14 -0300 | [diff] [blame] | 1434 | if (nr_args == 6 && sc->fmt && sc->fmt->nr_args != 0) |
| 1435 | nr_args = sc->fmt->nr_args; |
| 1436 | |
Arnaldo Carvalho de Melo | 5e58fcf | 2017-07-19 14:32:11 -0300 | [diff] [blame] | 1437 | sc->arg_fmt = calloc(nr_args, sizeof(*sc->arg_fmt)); |
| 1438 | if (sc->arg_fmt == NULL) |
| 1439 | return -1; |
| 1440 | |
| 1441 | for (idx = 0; idx < nr_args; ++idx) { |
| 1442 | if (sc->fmt) |
| 1443 | sc->arg_fmt[idx] = sc->fmt->arg[idx]; |
| 1444 | } |
| 1445 | |
| 1446 | sc->nr_args = nr_args; |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1450 | static int syscall__set_arg_fmts(struct syscall *sc) |
| 1451 | { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1452 | struct tep_format_field *field, *last_field = NULL; |
Arnaldo Carvalho de Melo | b6565c9 | 2016-05-23 12:59:53 -0300 | [diff] [blame] | 1453 | int idx = 0, len; |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1454 | |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1455 | for (field = sc->args; field; field = field->next, ++idx) { |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 1456 | last_field = field; |
| 1457 | |
Arnaldo Carvalho de Melo | 5e58fcf | 2017-07-19 14:32:11 -0300 | [diff] [blame] | 1458 | if (sc->fmt && sc->fmt->arg[idx].scnprintf) |
| 1459 | continue; |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1460 | |
Arnaldo Carvalho de Melo | dea87bf | 2019-06-05 10:53:06 -0300 | [diff] [blame] | 1461 | len = strlen(field->name); |
| 1462 | |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1463 | if (strcmp(field->type, "const char *") == 0 && |
Arnaldo Carvalho de Melo | dea87bf | 2019-06-05 10:53:06 -0300 | [diff] [blame] | 1464 | ((len >= 4 && strcmp(field->name + len - 4, "name") == 0) || |
| 1465 | strstr(field->name, "path") != NULL)) |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1466 | sc->arg_fmt[idx].scnprintf = SCA_FILENAME; |
Arnaldo Carvalho de Melo | ce05539 | 2018-12-17 12:21:09 -0300 | [diff] [blame] | 1467 | else if ((field->flags & TEP_FIELD_IS_POINTER) || strstr(field->name, "addr")) |
| 1468 | sc->arg_fmt[idx].scnprintf = SCA_PTR; |
Arnaldo Carvalho de Melo | d1d438a | 2016-04-06 18:02:41 -0300 | [diff] [blame] | 1469 | else if (strcmp(field->type, "pid_t") == 0) |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1470 | sc->arg_fmt[idx].scnprintf = SCA_PID; |
Arnaldo Carvalho de Melo | ba2f22c | 2016-04-07 12:05:51 -0300 | [diff] [blame] | 1471 | else if (strcmp(field->type, "umode_t") == 0) |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1472 | sc->arg_fmt[idx].scnprintf = SCA_MODE_T; |
Arnaldo Carvalho de Melo | b6565c9 | 2016-05-23 12:59:53 -0300 | [diff] [blame] | 1473 | else if ((strcmp(field->type, "int") == 0 || |
| 1474 | strcmp(field->type, "unsigned int") == 0 || |
| 1475 | strcmp(field->type, "long") == 0) && |
Arnaldo Carvalho de Melo | dea87bf | 2019-06-05 10:53:06 -0300 | [diff] [blame] | 1476 | len >= 2 && strcmp(field->name + len - 2, "fd") == 0) { |
Arnaldo Carvalho de Melo | b6565c9 | 2016-05-23 12:59:53 -0300 | [diff] [blame] | 1477 | /* |
| 1478 | * /sys/kernel/tracing/events/syscalls/sys_enter* |
| 1479 | * egrep 'field:.*fd;' .../format|sed -r 's/.*field:([a-z ]+) [a-z_]*fd.+/\1/g'|sort|uniq -c |
| 1480 | * 65 int |
| 1481 | * 23 unsigned int |
| 1482 | * 7 unsigned long |
| 1483 | */ |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1484 | sc->arg_fmt[idx].scnprintf = SCA_FD; |
Arnaldo Carvalho de Melo | b6565c9 | 2016-05-23 12:59:53 -0300 | [diff] [blame] | 1485 | } |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1486 | } |
| 1487 | |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 1488 | if (last_field) |
| 1489 | sc->args_size = last_field->offset + last_field->size; |
| 1490 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1491 | return 0; |
| 1492 | } |
| 1493 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1494 | static int trace__read_syscall_info(struct trace *trace, int id) |
| 1495 | { |
| 1496 | char tp_name[128]; |
| 1497 | struct syscall *sc; |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 1498 | const char *name = syscalltbl__name(trace->sctbl, id); |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1499 | |
Arnaldo Carvalho de Melo | 30a910d | 2019-07-18 20:19:30 -0300 | [diff] [blame] | 1500 | if (trace->syscalls.table == NULL) { |
Leo Yan | 3e70008 | 2019-08-09 18:47:52 +0800 | [diff] [blame] | 1501 | trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); |
Arnaldo Carvalho de Melo | 30a910d | 2019-07-18 20:19:30 -0300 | [diff] [blame] | 1502 | if (trace->syscalls.table == NULL) |
Arnaldo Carvalho de Melo | 5d2bd889 | 2019-07-17 19:53:51 -0300 | [diff] [blame] | 1503 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | sc = trace->syscalls.table + id; |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 1507 | if (sc->nonexistent) |
| 1508 | return 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1509 | |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 1510 | if (name == NULL) { |
| 1511 | sc->nonexistent = true; |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
| 1515 | sc->name = name; |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1516 | sc->fmt = syscall_fmt__find(sc->name); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1517 | |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1518 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1519 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1520 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 1521 | 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] | 1522 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1523 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1524 | } |
| 1525 | |
Arnaldo Carvalho de Melo | 5e58fcf | 2017-07-19 14:32:11 -0300 | [diff] [blame] | 1526 | if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? 6 : sc->tp_format->format.nr_fields)) |
Arnaldo Carvalho de Melo | 5d2bd889 | 2019-07-17 19:53:51 -0300 | [diff] [blame] | 1527 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 5e58fcf | 2017-07-19 14:32:11 -0300 | [diff] [blame] | 1528 | |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 1529 | if (IS_ERR(sc->tp_format)) |
Arnaldo Carvalho de Melo | 5d2bd889 | 2019-07-17 19:53:51 -0300 | [diff] [blame] | 1530 | return PTR_ERR(sc->tp_format); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1531 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1532 | sc->args = sc->tp_format->format.fields; |
Taeung Song | c42de70 | 2016-02-26 22:14:25 +0900 | [diff] [blame] | 1533 | /* |
| 1534 | * We need to check and discard the first variable '__syscall_nr' |
| 1535 | * or 'nr' that mean the syscall number. It is needless here. |
| 1536 | * So drop '__syscall_nr' or 'nr' field but does not exist on older kernels. |
| 1537 | */ |
| 1538 | 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] | 1539 | sc->args = sc->args->next; |
| 1540 | --sc->nr_args; |
| 1541 | } |
| 1542 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1543 | sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); |
Arnaldo Carvalho de Melo | 6a648b5 | 2018-08-02 10:30:08 -0300 | [diff] [blame] | 1544 | sc->is_open = !strcmp(name, "open") || !strcmp(name, "openat"); |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1545 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1546 | return syscall__set_arg_fmts(sc); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1547 | } |
| 1548 | |
Arnaldo Carvalho de Melo | 83e69b9 | 2019-07-15 17:28:25 -0300 | [diff] [blame] | 1549 | static int intcmp(const void *a, const void *b) |
| 1550 | { |
| 1551 | const int *one = a, *another = b; |
| 1552 | |
| 1553 | return *one - *another; |
| 1554 | } |
| 1555 | |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1556 | static int trace__validate_ev_qualifier(struct trace *trace) |
| 1557 | { |
Arnaldo Carvalho de Melo | a4066d6 | 2019-06-13 17:35:09 -0300 | [diff] [blame] | 1558 | int err = 0; |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1559 | bool printed_invalid_prefix = false; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1560 | struct str_node *pos; |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1561 | size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1562 | |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1563 | trace->ev_qualifier_ids.entries = malloc(nr_allocated * |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1564 | sizeof(trace->ev_qualifier_ids.entries[0])); |
| 1565 | |
| 1566 | if (trace->ev_qualifier_ids.entries == NULL) { |
| 1567 | fputs("Error:\tNot enough memory for allocating events qualifier ids\n", |
| 1568 | trace->output); |
| 1569 | err = -EINVAL; |
| 1570 | goto out; |
| 1571 | } |
| 1572 | |
Arnaldo Carvalho de Melo | 602a1f4 | 2016-06-23 11:31:20 -0300 | [diff] [blame] | 1573 | strlist__for_each_entry(pos, trace->ev_qualifier) { |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1574 | const char *sc = pos->s; |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1575 | int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1576 | |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1577 | if (id < 0) { |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1578 | id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); |
| 1579 | if (id >= 0) |
| 1580 | goto matches; |
| 1581 | |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1582 | if (!printed_invalid_prefix) { |
| 1583 | pr_debug("Skipping unknown syscalls: "); |
| 1584 | printed_invalid_prefix = true; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1585 | } else { |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1586 | pr_debug(", "); |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1587 | } |
| 1588 | |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1589 | pr_debug("%s", sc); |
| 1590 | continue; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1591 | } |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1592 | matches: |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1593 | trace->ev_qualifier_ids.entries[nr_used++] = id; |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1594 | if (match_next == -1) |
| 1595 | continue; |
| 1596 | |
| 1597 | while (1) { |
| 1598 | id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); |
| 1599 | if (id < 0) |
| 1600 | break; |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1601 | if (nr_allocated == nr_used) { |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1602 | void *entries; |
| 1603 | |
| 1604 | nr_allocated += 8; |
| 1605 | entries = realloc(trace->ev_qualifier_ids.entries, |
| 1606 | nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); |
| 1607 | if (entries == NULL) { |
| 1608 | err = -ENOMEM; |
| 1609 | fputs("\nError:\t Not enough memory for parsing\n", trace->output); |
| 1610 | goto out_free; |
| 1611 | } |
| 1612 | trace->ev_qualifier_ids.entries = entries; |
| 1613 | } |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1614 | trace->ev_qualifier_ids.entries[nr_used++] = id; |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 1615 | } |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1616 | } |
| 1617 | |
Arnaldo Carvalho de Melo | 99f26f8 | 2019-06-13 18:17:41 -0300 | [diff] [blame] | 1618 | trace->ev_qualifier_ids.nr = nr_used; |
Arnaldo Carvalho de Melo | 83e69b9 | 2019-07-15 17:28:25 -0300 | [diff] [blame] | 1619 | qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 1620 | out: |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1621 | if (printed_invalid_prefix) |
| 1622 | pr_debug("\n"); |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1623 | return err; |
Arnaldo Carvalho de Melo | 04c41bc | 2019-06-10 15:37:45 -0300 | [diff] [blame] | 1624 | out_free: |
| 1625 | zfree(&trace->ev_qualifier_ids.entries); |
| 1626 | trace->ev_qualifier_ids.nr = 0; |
| 1627 | goto out; |
Arnaldo Carvalho de Melo | d0cc439 | 2015-06-25 19:32:33 -0300 | [diff] [blame] | 1628 | } |
| 1629 | |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 1630 | static __maybe_unused bool trace__syscall_enabled(struct trace *trace, int id) |
| 1631 | { |
| 1632 | bool in_ev_qualifier; |
| 1633 | |
| 1634 | if (trace->ev_qualifier_ids.nr == 0) |
| 1635 | return true; |
| 1636 | |
| 1637 | in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, |
| 1638 | trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; |
| 1639 | |
| 1640 | if (in_ev_qualifier) |
| 1641 | return !trace->not_ev_qualifier; |
| 1642 | |
| 1643 | return trace->not_ev_qualifier; |
| 1644 | } |
| 1645 | |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1646 | /* |
| 1647 | * args is to be interpreted as a series of longs but we need to handle |
| 1648 | * 8-byte unaligned accesses. args points to raw_data within the event |
| 1649 | * and raw_data is guaranteed to be 8-byte unaligned because it is |
| 1650 | * preceded by raw_size which is a u32. So we need to copy args to a temp |
| 1651 | * variable to read it. Most notably this avoids extended load instructions |
| 1652 | * on unaligned addresses |
| 1653 | */ |
Arnaldo Carvalho de Melo | 325f509 | 2017-07-19 15:02:43 -0300 | [diff] [blame] | 1654 | unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx) |
Arnaldo Carvalho de Melo | f9f83b3 | 2017-07-14 10:13:56 -0300 | [diff] [blame] | 1655 | { |
| 1656 | unsigned long val; |
Arnaldo Carvalho de Melo | 325f509 | 2017-07-19 15:02:43 -0300 | [diff] [blame] | 1657 | unsigned char *p = arg->args + sizeof(unsigned long) * idx; |
Arnaldo Carvalho de Melo | f9f83b3 | 2017-07-14 10:13:56 -0300 | [diff] [blame] | 1658 | |
| 1659 | memcpy(&val, p, sizeof(val)); |
| 1660 | return val; |
| 1661 | } |
| 1662 | |
Arnaldo Carvalho de Melo | c51bdfe | 2017-07-19 15:47:30 -0300 | [diff] [blame] | 1663 | static size_t syscall__scnprintf_name(struct syscall *sc, char *bf, size_t size, |
| 1664 | struct syscall_arg *arg) |
| 1665 | { |
| 1666 | if (sc->arg_fmt && sc->arg_fmt[arg->idx].name) |
| 1667 | return scnprintf(bf, size, "%s: ", sc->arg_fmt[arg->idx].name); |
| 1668 | |
| 1669 | return scnprintf(bf, size, "arg%d: ", arg->idx); |
| 1670 | } |
| 1671 | |
Arnaldo Carvalho de Melo | 496fd34 | 2018-10-25 16:09:47 -0300 | [diff] [blame] | 1672 | /* |
| 1673 | * Check if the value is in fact zero, i.e. mask whatever needs masking, such |
| 1674 | * as mount 'flags' argument that needs ignoring some magic flag, see comment |
| 1675 | * in tools/perf/trace/beauty/mount_flags.c |
| 1676 | */ |
| 1677 | static unsigned long syscall__mask_val(struct syscall *sc, struct syscall_arg *arg, unsigned long val) |
| 1678 | { |
| 1679 | if (sc->arg_fmt && sc->arg_fmt[arg->idx].mask_val) |
| 1680 | return sc->arg_fmt[arg->idx].mask_val(arg, val); |
| 1681 | |
| 1682 | return val; |
| 1683 | } |
| 1684 | |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1685 | static size_t syscall__scnprintf_val(struct syscall *sc, char *bf, size_t size, |
| 1686 | struct syscall_arg *arg, unsigned long val) |
| 1687 | { |
| 1688 | if (sc->arg_fmt && sc->arg_fmt[arg->idx].scnprintf) { |
| 1689 | arg->val = val; |
| 1690 | if (sc->arg_fmt[arg->idx].parm) |
| 1691 | arg->parm = sc->arg_fmt[arg->idx].parm; |
| 1692 | return sc->arg_fmt[arg->idx].scnprintf(bf, size, arg); |
| 1693 | } |
| 1694 | return scnprintf(bf, size, "%ld", val); |
| 1695 | } |
| 1696 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1697 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 1698 | unsigned char *args, void *augmented_args, int augmented_args_size, |
| 1699 | struct trace *trace, struct thread *thread) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1700 | { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1701 | size_t printed = 0; |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1702 | unsigned long val; |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1703 | u8 bit = 1; |
| 1704 | struct syscall_arg arg = { |
| 1705 | .args = args, |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 1706 | .augmented = { |
| 1707 | .size = augmented_args_size, |
| 1708 | .args = augmented_args, |
| 1709 | }, |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1710 | .idx = 0, |
| 1711 | .mask = 0, |
| 1712 | .trace = trace, |
| 1713 | .thread = thread, |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 1714 | .show_string_prefix = trace->show_string_prefix, |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1715 | }; |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 1716 | struct thread_trace *ttrace = thread__priv(thread); |
| 1717 | |
| 1718 | /* |
| 1719 | * Things like fcntl will set this in its 'cmd' formatter to pick the |
| 1720 | * right formatter for the return value (an fd? file flags?), which is |
| 1721 | * not needed for syscalls that always return a given type, say an fd. |
| 1722 | */ |
| 1723 | ttrace->ret_scnprintf = NULL; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1724 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1725 | if (sc->args != NULL) { |
Tzvetomir Stoyanov (VMware) | 2c92f98 | 2018-09-19 14:56:45 -0400 | [diff] [blame] | 1726 | struct tep_format_field *field; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1727 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1728 | for (field = sc->args; field; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1729 | field = field->next, ++arg.idx, bit <<= 1) { |
| 1730 | if (arg.mask & bit) |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1731 | continue; |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1732 | |
Arnaldo Carvalho de Melo | f9f83b3 | 2017-07-14 10:13:56 -0300 | [diff] [blame] | 1733 | val = syscall_arg__val(&arg, arg.idx); |
Arnaldo Carvalho de Melo | 496fd34 | 2018-10-25 16:09:47 -0300 | [diff] [blame] | 1734 | /* |
| 1735 | * Some syscall args need some mask, most don't and |
| 1736 | * return val untouched. |
| 1737 | */ |
| 1738 | val = syscall__mask_val(sc, &arg, val); |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1739 | |
Arnaldo Carvalho de Melo | 4aa5823 | 2013-09-20 12:19:41 -0300 | [diff] [blame] | 1740 | /* |
| 1741 | * Suppress this argument if its value is zero and |
| 1742 | * and we don't have a string associated in an |
| 1743 | * strarray for it. |
| 1744 | */ |
David Ahern | 55d43bca | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1745 | if (val == 0 && |
Arnaldo Carvalho de Melo | e7c634f | 2018-12-14 10:12:09 -0300 | [diff] [blame] | 1746 | !trace->show_zeros && |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1747 | !(sc->arg_fmt && |
Arnaldo Carvalho de Melo | d47737d | 2017-07-17 15:59:03 -0300 | [diff] [blame] | 1748 | (sc->arg_fmt[arg.idx].show_zero || |
| 1749 | sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAY || |
Arnaldo Carvalho de Melo | 82d4a11 | 2017-07-17 15:22:47 -0300 | [diff] [blame] | 1750 | sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAYS) && |
| 1751 | sc->arg_fmt[arg.idx].parm)) |
Arnaldo Carvalho de Melo | 22ae5cf1 | 2013-09-12 11:27:34 -0300 | [diff] [blame] | 1752 | continue; |
| 1753 | |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 1754 | printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : ""); |
| 1755 | |
| 1756 | if (trace->show_arg_names) |
| 1757 | printed += scnprintf(bf + printed, size - printed, "%s: ", field->name); |
| 1758 | |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1759 | printed += syscall__scnprintf_val(sc, bf + printed, size - printed, &arg, val); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1760 | } |
Arnaldo Carvalho de Melo | 4c4d6e5 | 2016-05-05 23:38:05 -0300 | [diff] [blame] | 1761 | } else if (IS_ERR(sc->tp_format)) { |
| 1762 | /* |
| 1763 | * If we managed to read the tracepoint /format file, then we |
| 1764 | * may end up not having any args, like with gettid(), so only |
| 1765 | * print the raw args when we didn't manage to read it. |
| 1766 | */ |
Arnaldo Carvalho de Melo | 332337d | 2017-07-19 15:08:14 -0300 | [diff] [blame] | 1767 | while (arg.idx < sc->nr_args) { |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1768 | if (arg.mask & bit) |
| 1769 | goto next_arg; |
| 1770 | val = syscall_arg__val(&arg, arg.idx); |
Arnaldo Carvalho de Melo | c51bdfe | 2017-07-19 15:47:30 -0300 | [diff] [blame] | 1771 | if (printed) |
| 1772 | printed += scnprintf(bf + printed, size - printed, ", "); |
| 1773 | printed += syscall__scnprintf_name(sc, bf + printed, size - printed, &arg); |
Arnaldo Carvalho de Melo | d032d79 | 2017-07-19 14:36:13 -0300 | [diff] [blame] | 1774 | printed += syscall__scnprintf_val(sc, bf + printed, size - printed, &arg, val); |
| 1775 | next_arg: |
| 1776 | ++arg.idx; |
| 1777 | bit <<= 1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | return printed; |
| 1782 | } |
| 1783 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1784 | typedef int (*tracepoint_handler)(struct trace *trace, struct evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1785 | union perf_event *event, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1786 | struct perf_sample *sample); |
| 1787 | |
| 1788 | static struct syscall *trace__syscall_info(struct trace *trace, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1789 | struct evsel *evsel, int id) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1790 | { |
Arnaldo Carvalho de Melo | 5d2bd889 | 2019-07-17 19:53:51 -0300 | [diff] [blame] | 1791 | int err = 0; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1792 | |
| 1793 | if (id < 0) { |
Arnaldo Carvalho de Melo | adaa18b | 2013-08-22 17:55:25 -0300 | [diff] [blame] | 1794 | |
| 1795 | /* |
| 1796 | * XXX: Noticed on x86_64, reproduced as far back as 3.0.36, haven't tried |
| 1797 | * before that, leaving at a higher verbosity level till that is |
| 1798 | * explained. Reproduced with plain ftrace with: |
| 1799 | * |
| 1800 | * echo 1 > /t/events/raw_syscalls/sys_exit/enable |
| 1801 | * grep "NR -1 " /t/trace_pipe |
| 1802 | * |
| 1803 | * After generating some load on the machine. |
| 1804 | */ |
| 1805 | if (verbose > 1) { |
| 1806 | static u64 n; |
| 1807 | fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", |
| 1808 | id, perf_evsel__name(evsel), ++n); |
| 1809 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1810 | return NULL; |
| 1811 | } |
| 1812 | |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 1813 | err = -EINVAL; |
| 1814 | |
Arnaldo Carvalho de Melo | 30a910d | 2019-07-18 20:19:30 -0300 | [diff] [blame] | 1815 | if (id > trace->sctbl->syscalls.max_id) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1816 | goto out_cant_read; |
| 1817 | |
Arnaldo Carvalho de Melo | 30a910d | 2019-07-18 20:19:30 -0300 | [diff] [blame] | 1818 | if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) && |
| 1819 | (err = trace__read_syscall_info(trace, id)) != 0) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1820 | goto out_cant_read; |
| 1821 | |
Arnaldo Carvalho de Melo | b8b1033 | 2019-07-17 20:21:37 -0300 | [diff] [blame] | 1822 | if (trace->syscalls.table[id].name == NULL) { |
| 1823 | if (trace->syscalls.table[id].nonexistent) |
| 1824 | return NULL; |
| 1825 | goto out_cant_read; |
| 1826 | } |
| 1827 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1828 | return &trace->syscalls.table[id]; |
| 1829 | |
| 1830 | out_cant_read: |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 1831 | if (verbose > 0) { |
Arnaldo Carvalho de Melo | 5d2bd889 | 2019-07-17 19:53:51 -0300 | [diff] [blame] | 1832 | char sbuf[STRERR_BUFSIZE]; |
| 1833 | fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, sizeof(sbuf))); |
Arnaldo Carvalho de Melo | 30a910d | 2019-07-18 20:19:30 -0300 | [diff] [blame] | 1834 | if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL) |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 1835 | fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); |
| 1836 | fputs(" information\n", trace->output); |
| 1837 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1838 | return NULL; |
| 1839 | } |
| 1840 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1841 | static void thread__update_stats(struct thread_trace *ttrace, |
| 1842 | int id, struct perf_sample *sample) |
| 1843 | { |
| 1844 | struct int_node *inode; |
| 1845 | struct stats *stats; |
| 1846 | u64 duration = 0; |
| 1847 | |
| 1848 | inode = intlist__findnew(ttrace->syscall_stats, id); |
| 1849 | if (inode == NULL) |
| 1850 | return; |
| 1851 | |
| 1852 | stats = inode->priv; |
| 1853 | if (stats == NULL) { |
| 1854 | stats = malloc(sizeof(struct stats)); |
| 1855 | if (stats == NULL) |
| 1856 | return; |
| 1857 | init_stats(stats); |
| 1858 | inode->priv = stats; |
| 1859 | } |
| 1860 | |
| 1861 | if (ttrace->entry_time && sample->time > ttrace->entry_time) |
| 1862 | duration = sample->time - ttrace->entry_time; |
| 1863 | |
| 1864 | update_stats(stats, duration); |
| 1865 | } |
| 1866 | |
Arnaldo Carvalho de Melo | 522283f | 2018-01-22 11:42:11 -0300 | [diff] [blame] | 1867 | static int trace__printf_interrupted_entry(struct trace *trace) |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1868 | { |
| 1869 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1870 | size_t printed; |
Arnaldo Carvalho de Melo | 172bf02 | 2019-01-07 16:24:27 -0300 | [diff] [blame] | 1871 | int len; |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1872 | |
Arnaldo Carvalho de Melo | 0a6545b | 2018-03-29 12:22:59 -0300 | [diff] [blame] | 1873 | if (trace->failure_only || trace->current == NULL) |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1874 | return 0; |
| 1875 | |
| 1876 | ttrace = thread__priv(trace->current); |
| 1877 | |
| 1878 | if (!ttrace->entry_pending) |
| 1879 | return 0; |
| 1880 | |
Arnaldo Carvalho de Melo | 522283f | 2018-01-22 11:42:11 -0300 | [diff] [blame] | 1881 | printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->output); |
Arnaldo Carvalho de Melo | 172bf02 | 2019-01-07 16:24:27 -0300 | [diff] [blame] | 1882 | printed += len = fprintf(trace->output, "%s)", ttrace->entry_str); |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1883 | |
Arnaldo Carvalho de Melo | 172bf02 | 2019-01-07 16:24:27 -0300 | [diff] [blame] | 1884 | if (len < trace->args_alignment - 4) |
| 1885 | printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " "); |
| 1886 | |
| 1887 | printed += fprintf(trace->output, " ...\n"); |
| 1888 | |
| 1889 | ttrace->entry_pending = false; |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 1890 | ++trace->nr_events_printed; |
| 1891 | |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1892 | return printed; |
| 1893 | } |
| 1894 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1895 | static int trace__fprintf_sample(struct trace *trace, struct evsel *evsel, |
Arnaldo Carvalho de Melo | 591421e | 2018-01-22 11:38:54 -0300 | [diff] [blame] | 1896 | struct perf_sample *sample, struct thread *thread) |
| 1897 | { |
| 1898 | int printed = 0; |
| 1899 | |
| 1900 | if (trace->print_sample) { |
| 1901 | double ts = (double)sample->time / NSEC_PER_MSEC; |
| 1902 | |
| 1903 | printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n", |
| 1904 | perf_evsel__name(evsel), ts, |
| 1905 | thread__comm_str(thread), |
| 1906 | sample->pid, sample->tid, sample->cpu); |
| 1907 | } |
| 1908 | |
| 1909 | return printed; |
| 1910 | } |
| 1911 | |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 1912 | static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sample, int *augmented_args_size, int raw_augmented_args_size) |
Arnaldo Carvalho de Melo | 8a041f8 | 2018-09-03 16:07:53 -0300 | [diff] [blame] | 1913 | { |
| 1914 | void *augmented_args = NULL; |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 1915 | /* |
| 1916 | * For now with BPF raw_augmented we hook into raw_syscalls:sys_enter |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 1917 | * and there we get all 6 syscall args plus the tracepoint common fields |
| 1918 | * that gets calculated at the start and the syscall_nr (another long). |
| 1919 | * So we check if that is the case and if so don't look after the |
| 1920 | * sc->args_size but always after the full raw_syscalls:sys_enter payload, |
| 1921 | * which is fixed. |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 1922 | * |
| 1923 | * We'll revisit this later to pass s->args_size to the BPF augmenter |
| 1924 | * (now tools/perf/examples/bpf/augmented_raw_syscalls.c, so that it |
| 1925 | * copies only what we need for each syscall, like what happens when we |
| 1926 | * use syscalls:sys_enter_NAME, so that we reduce the kernel/userspace |
| 1927 | * traffic to just what is needed for each syscall. |
| 1928 | */ |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 1929 | int args_size = raw_augmented_args_size ?: sc->args_size; |
Arnaldo Carvalho de Melo | 8a041f8 | 2018-09-03 16:07:53 -0300 | [diff] [blame] | 1930 | |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 1931 | *augmented_args_size = sample->raw_size - args_size; |
Arnaldo Carvalho de Melo | 8a041f8 | 2018-09-03 16:07:53 -0300 | [diff] [blame] | 1932 | if (*augmented_args_size > 0) |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 1933 | augmented_args = sample->raw_data + args_size; |
Arnaldo Carvalho de Melo | 8a041f8 | 2018-09-03 16:07:53 -0300 | [diff] [blame] | 1934 | |
| 1935 | return augmented_args; |
| 1936 | } |
| 1937 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 1938 | static int trace__sys_enter(struct trace *trace, struct evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1939 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1940 | struct perf_sample *sample) |
| 1941 | { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1942 | char *msg; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1943 | void *args; |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 1944 | int printed = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1945 | struct thread *thread; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 1946 | int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; |
Arnaldo Carvalho de Melo | db2da3f | 2018-09-03 16:24:09 -0300 | [diff] [blame] | 1947 | int augmented_args_size = 0; |
| 1948 | void *augmented_args = NULL; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1949 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1950 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1951 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1952 | if (sc == NULL) |
| 1953 | return -1; |
| 1954 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1955 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1956 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1957 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 1958 | goto out_put; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1959 | |
Arnaldo Carvalho de Melo | 591421e | 2018-01-22 11:38:54 -0300 | [diff] [blame] | 1960 | trace__fprintf_sample(trace, evsel, sample, thread); |
| 1961 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 1962 | args = perf_evsel__sc_tp_ptr(evsel, args, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1963 | |
| 1964 | if (ttrace->entry_str == NULL) { |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 1965 | ttrace->entry_str = malloc(trace__entry_str_size); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1966 | if (!ttrace->entry_str) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 1967 | goto out_put; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1968 | } |
| 1969 | |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 1970 | if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) |
Arnaldo Carvalho de Melo | 522283f | 2018-01-22 11:42:11 -0300 | [diff] [blame] | 1971 | trace__printf_interrupted_entry(trace); |
Arnaldo Carvalho de Melo | db2da3f | 2018-09-03 16:24:09 -0300 | [diff] [blame] | 1972 | /* |
| 1973 | * If this is raw_syscalls.sys_enter, then it always comes with the 6 possible |
| 1974 | * arguments, even if the syscall being handled, say "openat", uses only 4 arguments |
| 1975 | * this breaks syscall__augmented_args() check for augmented args, as we calculate |
| 1976 | * syscall->args_size using each syscalls:sys_enter_NAME tracefs format file, |
| 1977 | * so when handling, say the openat syscall, we end up getting 6 args for the |
| 1978 | * raw_syscalls:sys_enter event, when we expected just 4, we end up mistakenly |
| 1979 | * thinking that the extra 2 u64 args are the augmented filename, so just check |
| 1980 | * here and avoid using augmented syscalls when the evsel is the raw_syscalls one. |
| 1981 | */ |
| 1982 | if (evsel != trace->syscalls.events.sys_enter) |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 1983 | augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1984 | ttrace->entry_time = sample->time; |
| 1985 | msg = ttrace->entry_str; |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 1986 | 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] | 1987 | |
Arnaldo Carvalho de Melo | e4d44e8 | 2015-08-04 22:17:29 -0300 | [diff] [blame] | 1988 | printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed, |
Arnaldo Carvalho de Melo | db2da3f | 2018-09-03 16:24:09 -0300 | [diff] [blame] | 1989 | args, augmented_args, augmented_args_size, trace, thread); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1990 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1991 | if (sc->is_exit) { |
Arnaldo Carvalho de Melo | 0a6545b | 2018-03-29 12:22:59 -0300 | [diff] [blame] | 1992 | if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 1993 | int alignment = 0; |
| 1994 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 1995 | trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output); |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 1996 | printed = fprintf(trace->output, "%s)", ttrace->entry_str); |
| 1997 | if (trace->args_alignment > printed) |
| 1998 | alignment = trace->args_alignment - printed; |
| 1999 | fprintf(trace->output, "%*s= ?\n", alignment, " "); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2000 | } |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2001 | } else { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2002 | ttrace->entry_pending = true; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2003 | /* See trace__vfs_getname & trace__sys_exit */ |
| 2004 | ttrace->filename.pending_open = false; |
| 2005 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2006 | |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 2007 | if (trace->current != thread) { |
| 2008 | thread__put(trace->current); |
| 2009 | trace->current = thread__get(thread); |
| 2010 | } |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2011 | err = 0; |
| 2012 | out_put: |
| 2013 | thread__put(thread); |
| 2014 | return err; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2015 | } |
| 2016 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2017 | static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2018 | struct perf_sample *sample) |
| 2019 | { |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2020 | struct thread_trace *ttrace; |
| 2021 | struct thread *thread; |
Arnaldo Carvalho de Melo | f3acd88 | 2018-08-02 15:11:58 -0300 | [diff] [blame] | 2022 | int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; |
| 2023 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2024 | char msg[1024]; |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 2025 | void *args, *augmented_args = NULL; |
| 2026 | int augmented_args_size; |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2027 | |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2028 | if (sc == NULL) |
| 2029 | return -1; |
| 2030 | |
| 2031 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
| 2032 | ttrace = thread__trace(thread, trace->output); |
| 2033 | /* |
| 2034 | * We need to get ttrace just to make sure it is there when syscall__scnprintf_args() |
| 2035 | * and the rest of the beautifiers accessing it via struct syscall_arg touches it. |
| 2036 | */ |
| 2037 | if (ttrace == NULL) |
| 2038 | goto out_put; |
| 2039 | |
Arnaldo Carvalho de Melo | f3acd88 | 2018-08-02 15:11:58 -0300 | [diff] [blame] | 2040 | args = perf_evsel__sc_tp_ptr(evsel, args, sample); |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 2041 | augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); |
Arnaldo Carvalho de Melo | 7a983a0 | 2018-08-20 17:58:17 -0300 | [diff] [blame] | 2042 | syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2043 | fprintf(trace->output, "%s", msg); |
| 2044 | err = 0; |
| 2045 | out_put: |
| 2046 | thread__put(thread); |
| 2047 | return err; |
| 2048 | } |
| 2049 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2050 | static int trace__resolve_callchain(struct trace *trace, struct evsel *evsel, |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2051 | struct perf_sample *sample, |
| 2052 | struct callchain_cursor *cursor) |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2053 | { |
| 2054 | struct addr_location al; |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2055 | int max_stack = evsel->core.attr.sample_max_stack ? |
| 2056 | evsel->core.attr.sample_max_stack : |
Ravi Bangoria | 3a9e9a4 | 2018-01-30 11:00:53 +0530 | [diff] [blame] | 2057 | trace->max_stack; |
Arnaldo Carvalho de Melo | 4291bf5 | 2018-10-20 09:18:50 -0300 | [diff] [blame] | 2058 | int err; |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2059 | |
Arnaldo Carvalho de Melo | 4291bf5 | 2018-10-20 09:18:50 -0300 | [diff] [blame] | 2060 | if (machine__resolve(trace->host, &al, sample) < 0) |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2061 | return -1; |
| 2062 | |
Arnaldo Carvalho de Melo | 4291bf5 | 2018-10-20 09:18:50 -0300 | [diff] [blame] | 2063 | err = thread__resolve_callchain(al.thread, cursor, evsel, sample, NULL, NULL, max_stack); |
| 2064 | addr_location__put(&al); |
| 2065 | return err; |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sample) |
| 2069 | { |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2070 | /* TODO: user-configurable print_opts */ |
Arnaldo Carvalho de Melo | e20ab86 | 2016-04-12 15:16:15 -0300 | [diff] [blame] | 2071 | const unsigned int print_opts = EVSEL__PRINT_SYM | |
| 2072 | EVSEL__PRINT_DSO | |
| 2073 | EVSEL__PRINT_UNKNOWN_AS_ADDR; |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2074 | |
Arnaldo Carvalho de Melo | d327e60 | 2016-04-14 17:53:49 -0300 | [diff] [blame] | 2075 | return sample__fprintf_callchain(sample, 38, print_opts, &callchain_cursor, trace->output); |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2076 | } |
| 2077 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2078 | static const char *errno_to_name(struct evsel *evsel, int err) |
Hendrik Brueckner | 092bd3c | 2018-01-19 09:56:16 +0100 | [diff] [blame] | 2079 | { |
| 2080 | struct perf_env *env = perf_evsel__env(evsel); |
| 2081 | const char *arch_name = perf_env__arch(env); |
| 2082 | |
| 2083 | return arch_syscalls__strerrno(arch_name, err); |
| 2084 | } |
| 2085 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2086 | static int trace__sys_exit(struct trace *trace, struct evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2087 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2088 | struct perf_sample *sample) |
| 2089 | { |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 2090 | long ret; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2091 | u64 duration = 0; |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 2092 | bool duration_calculated = false; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2093 | struct thread *thread; |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2094 | int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0; |
| 2095 | int alignment = trace->args_alignment; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2096 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2097 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2098 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2099 | if (sc == NULL) |
| 2100 | return -1; |
| 2101 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2102 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2103 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2104 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2105 | goto out_put; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2106 | |
Arnaldo Carvalho de Melo | 591421e | 2018-01-22 11:38:54 -0300 | [diff] [blame] | 2107 | trace__fprintf_sample(trace, evsel, sample, thread); |
| 2108 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2109 | if (trace->summary) |
| 2110 | thread__update_stats(ttrace, id, sample); |
| 2111 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 2112 | ret = perf_evsel__sc_tp_uint(evsel, ret, sample); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2113 | |
Arnaldo Carvalho de Melo | 79d725c | 2019-07-16 16:56:49 -0300 | [diff] [blame] | 2114 | if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) { |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2115 | trace__set_fd_pathname(thread, ret, ttrace->filename.name); |
| 2116 | ttrace->filename.pending_open = false; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2117 | ++trace->stats.vfs_getname; |
| 2118 | } |
| 2119 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2120 | if (ttrace->entry_time) { |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2121 | duration = sample->time - ttrace->entry_time; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2122 | if (trace__filter_duration(trace, duration)) |
| 2123 | goto out; |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 2124 | duration_calculated = true; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2125 | } else if (trace->duration_filter) |
| 2126 | goto out; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 2127 | |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2128 | if (sample->callchain) { |
| 2129 | callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); |
| 2130 | if (callchain_ret == 0) { |
| 2131 | if (callchain_cursor.nr < trace->min_stack) |
| 2132 | goto out; |
| 2133 | callchain_ret = 1; |
| 2134 | } |
| 2135 | } |
| 2136 | |
Arnaldo Carvalho de Melo | 0a6545b | 2018-03-29 12:22:59 -0300 | [diff] [blame] | 2137 | if (trace->summary_only || (ret >= 0 && trace->failure_only)) |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 2138 | goto out; |
| 2139 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 2140 | trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace->output); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2141 | |
| 2142 | if (ttrace->entry_pending) { |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2143 | printed = fprintf(trace->output, "%s", ttrace->entry_str); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2144 | } else { |
Arnaldo Carvalho de Melo | ac6e022 | 2019-01-07 16:54:38 -0300 | [diff] [blame] | 2145 | printed += fprintf(trace->output, " ... ["); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2146 | color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); |
Arnaldo Carvalho de Melo | ac6e022 | 2019-01-07 16:54:38 -0300 | [diff] [blame] | 2147 | printed += 9; |
| 2148 | printed += fprintf(trace->output, "]: %s()", sc->name); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2149 | } |
| 2150 | |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2151 | printed++; /* the closing ')' */ |
| 2152 | |
| 2153 | if (alignment > printed) |
| 2154 | alignment -= printed; |
| 2155 | else |
| 2156 | alignment = 0; |
| 2157 | |
| 2158 | fprintf(trace->output, ")%*s= ", alignment, " "); |
| 2159 | |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2160 | if (sc->fmt == NULL) { |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 2161 | if (ret < 0) |
| 2162 | goto errno_print; |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2163 | signed_print: |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2164 | fprintf(trace->output, "%ld", ret); |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 2165 | } else if (ret < 0) { |
| 2166 | errno_print: { |
Masami Hiramatsu | 942a91e | 2014-08-14 02:22:41 +0000 | [diff] [blame] | 2167 | char bf[STRERR_BUFSIZE]; |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 2168 | const char *emsg = str_error_r(-ret, bf, sizeof(bf)), |
Hendrik Brueckner | 092bd3c | 2018-01-19 09:56:16 +0100 | [diff] [blame] | 2169 | *e = errno_to_name(evsel, -ret); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2170 | |
Arnaldo Carvalho de Melo | 2c83dfa | 2018-12-17 12:06:34 -0300 | [diff] [blame] | 2171 | fprintf(trace->output, "-1 %s (%s)", e, emsg); |
Arnaldo Carvalho de Melo | 1f63139 | 2017-07-18 12:45:57 -0300 | [diff] [blame] | 2172 | } |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2173 | } else if (ret == 0 && sc->fmt->timeout) |
Arnaldo Carvalho de Melo | 2c83dfa | 2018-12-17 12:06:34 -0300 | [diff] [blame] | 2174 | fprintf(trace->output, "0 (Timeout)"); |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 2175 | else if (ttrace->ret_scnprintf) { |
| 2176 | char bf[1024]; |
Arnaldo Carvalho de Melo | 7ee5743 | 2017-07-14 15:16:54 -0300 | [diff] [blame] | 2177 | struct syscall_arg arg = { |
| 2178 | .val = ret, |
| 2179 | .thread = thread, |
| 2180 | .trace = trace, |
| 2181 | }; |
| 2182 | ttrace->ret_scnprintf(bf, sizeof(bf), &arg); |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 2183 | ttrace->ret_scnprintf = NULL; |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2184 | fprintf(trace->output, "%s", bf); |
Arnaldo Carvalho de Melo | 84486ca | 2017-07-14 11:35:03 -0300 | [diff] [blame] | 2185 | } else if (sc->fmt->hexret) |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2186 | fprintf(trace->output, "%#lx", ret); |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 2187 | else if (sc->fmt->errpid) { |
| 2188 | struct thread *child = machine__find_thread(trace->host, ret, ret); |
| 2189 | |
| 2190 | if (child != NULL) { |
Arnaldo Carvalho de Melo | 4b8a240 | 2018-12-17 11:48:46 -0300 | [diff] [blame] | 2191 | fprintf(trace->output, "%ld", ret); |
Arnaldo Carvalho de Melo | 11c8e39 | 2016-04-06 14:33:07 -0300 | [diff] [blame] | 2192 | if (child->comm_set) |
| 2193 | fprintf(trace->output, " (%s)", thread__comm_str(child)); |
| 2194 | thread__put(child); |
| 2195 | } |
| 2196 | } else |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 2197 | goto signed_print; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2198 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2199 | fputc('\n', trace->output); |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 2200 | |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 2201 | /* |
| 2202 | * We only consider an 'event' for the sake of --max-events a non-filtered |
| 2203 | * sys_enter + sys_exit and other tracepoint events. |
| 2204 | */ |
| 2205 | if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX) |
| 2206 | interrupted = true; |
| 2207 | |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 2208 | if (callchain_ret > 0) |
| 2209 | trace__fprintf_callchain(trace, sample); |
| 2210 | else if (callchain_ret < 0) |
| 2211 | pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel)); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2212 | out: |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2213 | ttrace->entry_pending = false; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2214 | err = 0; |
| 2215 | out_put: |
| 2216 | thread__put(thread); |
| 2217 | return err; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 2218 | } |
| 2219 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2220 | static int trace__vfs_getname(struct trace *trace, struct evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2221 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2222 | struct perf_sample *sample) |
| 2223 | { |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2224 | struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
| 2225 | struct thread_trace *ttrace; |
| 2226 | size_t filename_len, entry_str_len, to_move; |
| 2227 | ssize_t remaining_space; |
| 2228 | char *pos; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2229 | const char *filename = perf_evsel__rawptr(evsel, sample, "pathname"); |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2230 | |
| 2231 | if (!thread) |
| 2232 | goto out; |
| 2233 | |
| 2234 | ttrace = thread__priv(thread); |
| 2235 | if (!ttrace) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2236 | goto out_put; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2237 | |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2238 | filename_len = strlen(filename); |
Arnaldo Carvalho de Melo | 39f0e7a | 2017-03-24 14:51:28 -0300 | [diff] [blame] | 2239 | if (filename_len == 0) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2240 | goto out_put; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2241 | |
| 2242 | if (ttrace->filename.namelen < filename_len) { |
| 2243 | char *f = realloc(ttrace->filename.name, filename_len + 1); |
| 2244 | |
| 2245 | if (f == NULL) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2246 | goto out_put; |
Arnaldo Carvalho de Melo | 7f4f800 | 2015-08-14 13:16:27 -0300 | [diff] [blame] | 2247 | |
| 2248 | ttrace->filename.namelen = filename_len; |
| 2249 | ttrace->filename.name = f; |
| 2250 | } |
| 2251 | |
| 2252 | strcpy(ttrace->filename.name, filename); |
| 2253 | ttrace->filename.pending_open = true; |
| 2254 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2255 | if (!ttrace->filename.ptr) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2256 | goto out_put; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2257 | |
| 2258 | entry_str_len = strlen(ttrace->entry_str); |
| 2259 | remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */ |
| 2260 | if (remaining_space <= 0) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2261 | goto out_put; |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2262 | |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2263 | if (filename_len > (size_t)remaining_space) { |
| 2264 | filename += filename_len - remaining_space; |
| 2265 | filename_len = remaining_space; |
| 2266 | } |
| 2267 | |
| 2268 | to_move = entry_str_len - ttrace->filename.entry_str_pos + 1; /* \0 */ |
| 2269 | pos = ttrace->entry_str + ttrace->filename.entry_str_pos; |
| 2270 | memmove(pos + filename_len, pos, to_move); |
| 2271 | memcpy(pos, filename, filename_len); |
| 2272 | |
| 2273 | ttrace->filename.ptr = 0; |
| 2274 | ttrace->filename.entry_str_pos = 0; |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2275 | out_put: |
| 2276 | thread__put(thread); |
Arnaldo Carvalho de Melo | f994592 | 2015-08-04 22:30:09 -0300 | [diff] [blame] | 2277 | out: |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2278 | return 0; |
| 2279 | } |
| 2280 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2281 | static int trace__sched_stat_runtime(struct trace *trace, struct evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2282 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2283 | struct perf_sample *sample) |
| 2284 | { |
| 2285 | u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); |
| 2286 | double runtime_ms = (double)runtime / NSEC_PER_MSEC; |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2287 | struct thread *thread = machine__findnew_thread(trace->host, |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 2288 | sample->pid, |
| 2289 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2290 | struct thread_trace *ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2291 | |
| 2292 | if (ttrace == NULL) |
| 2293 | goto out_dump; |
| 2294 | |
| 2295 | ttrace->runtime_ms += runtime_ms; |
| 2296 | trace->runtime_ms += runtime_ms; |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2297 | out_put: |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2298 | thread__put(thread); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2299 | return 0; |
| 2300 | |
| 2301 | out_dump: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2302 | 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] | 2303 | evsel->name, |
| 2304 | perf_evsel__strval(evsel, sample, "comm"), |
| 2305 | (pid_t)perf_evsel__intval(evsel, sample, "pid"), |
| 2306 | runtime, |
| 2307 | perf_evsel__intval(evsel, sample, "vruntime")); |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2308 | goto out_put; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2309 | } |
| 2310 | |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 2311 | static int bpf_output__printer(enum binary_printer_ops op, |
| 2312 | unsigned int val, void *extra __maybe_unused, FILE *fp) |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2313 | { |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2314 | unsigned char ch = (unsigned char)val; |
| 2315 | |
| 2316 | switch (op) { |
| 2317 | case BINARY_PRINT_CHAR_DATA: |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 2318 | return fprintf(fp, "%c", isprint(ch) ? ch : '.'); |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2319 | case BINARY_PRINT_DATA_BEGIN: |
| 2320 | case BINARY_PRINT_LINE_BEGIN: |
| 2321 | case BINARY_PRINT_ADDR: |
| 2322 | case BINARY_PRINT_NUM_DATA: |
| 2323 | case BINARY_PRINT_NUM_PAD: |
| 2324 | case BINARY_PRINT_SEP: |
| 2325 | case BINARY_PRINT_CHAR_PAD: |
| 2326 | case BINARY_PRINT_LINE_END: |
| 2327 | case BINARY_PRINT_DATA_END: |
| 2328 | default: |
| 2329 | break; |
| 2330 | } |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 2331 | |
| 2332 | return 0; |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static void bpf_output__fprintf(struct trace *trace, |
| 2336 | struct perf_sample *sample) |
| 2337 | { |
Arnaldo Carvalho de Melo | 923d0c9 | 2017-10-17 10:35:00 -0300 | [diff] [blame] | 2338 | binary__fprintf(sample->raw_data, sample->raw_size, 8, |
| 2339 | bpf_output__printer, NULL, trace->output); |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 2340 | ++trace->nr_events_printed; |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2343 | static int trace__event_handler(struct trace *trace, struct evsel *evsel, |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2344 | union perf_event *event __maybe_unused, |
| 2345 | struct perf_sample *sample) |
| 2346 | { |
Arnaldo Carvalho de Melo | a9c5e6c | 2018-10-22 14:14:16 -0300 | [diff] [blame] | 2347 | struct thread *thread; |
Arnaldo Carvalho de Melo | 7ad3561 | 2016-04-20 19:55:48 -0300 | [diff] [blame] | 2348 | int callchain_ret = 0; |
Arnaldo Carvalho de Melo | a9c5e6c | 2018-10-22 14:14:16 -0300 | [diff] [blame] | 2349 | /* |
| 2350 | * Check if we called perf_evsel__disable(evsel) due to, for instance, |
| 2351 | * this event's max_events having been hit and this is an entry coming |
| 2352 | * from the ring buffer that we should discard, since the max events |
| 2353 | * have already been considered/printed. |
| 2354 | */ |
| 2355 | if (evsel->disabled) |
| 2356 | return 0; |
| 2357 | |
| 2358 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | 7ad3561 | 2016-04-20 19:55:48 -0300 | [diff] [blame] | 2359 | |
| 2360 | if (sample->callchain) { |
| 2361 | callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); |
| 2362 | if (callchain_ret == 0) { |
| 2363 | if (callchain_cursor.nr < trace->min_stack) |
| 2364 | goto out; |
| 2365 | callchain_ret = 1; |
| 2366 | } |
| 2367 | } |
| 2368 | |
Arnaldo Carvalho de Melo | 522283f | 2018-01-22 11:42:11 -0300 | [diff] [blame] | 2369 | trace__printf_interrupted_entry(trace); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2370 | trace__fprintf_tstamp(trace, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 0808921 | 2015-02-19 21:51:50 -0800 | [diff] [blame] | 2371 | |
Arnaldo Carvalho de Melo | 42e4a52 | 2018-12-14 10:22:18 -0300 | [diff] [blame] | 2372 | if (trace->trace_syscalls && trace->show_duration) |
Arnaldo Carvalho de Melo | 0808921 | 2015-02-19 21:51:50 -0800 | [diff] [blame] | 2373 | fprintf(trace->output, "( ): "); |
| 2374 | |
Arnaldo Carvalho de Melo | c4191e5 | 2018-08-30 13:37:28 -0300 | [diff] [blame] | 2375 | if (thread) |
| 2376 | trace__fprintf_comm_tid(trace, thread, trace->output); |
| 2377 | |
Arnaldo Carvalho de Melo | 1cdf618 | 2018-08-21 11:44:23 -0300 | [diff] [blame] | 2378 | if (evsel == trace->syscalls.events.augmented) { |
| 2379 | int id = perf_evsel__sc_tp_uint(evsel, id, sample); |
| 2380 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
| 2381 | |
| 2382 | if (sc) { |
Arnaldo Carvalho de Melo | c4191e5 | 2018-08-30 13:37:28 -0300 | [diff] [blame] | 2383 | fprintf(trace->output, "%s(", sc->name); |
| 2384 | trace__fprintf_sys_enter(trace, evsel, sample); |
| 2385 | fputc(')', trace->output); |
| 2386 | goto newline; |
Arnaldo Carvalho de Melo | 1cdf618 | 2018-08-21 11:44:23 -0300 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | /* |
| 2390 | * XXX: Not having the associated syscall info or not finding/adding |
| 2391 | * the thread should never happen, but if it does... |
| 2392 | * fall thru and print it as a bpf_output event. |
| 2393 | */ |
| 2394 | } |
| 2395 | |
Arnaldo Carvalho de Melo | 0808921 | 2015-02-19 21:51:50 -0800 | [diff] [blame] | 2396 | fprintf(trace->output, "%s:", evsel->name); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2397 | |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2398 | if (perf_evsel__is_bpf_output(evsel)) { |
Arnaldo Carvalho de Melo | 1cdf618 | 2018-08-21 11:44:23 -0300 | [diff] [blame] | 2399 | bpf_output__fprintf(trace, sample); |
Wang Nan | 1d6c940 | 2016-02-26 09:31:55 +0000 | [diff] [blame] | 2400 | } else if (evsel->tp_format) { |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2401 | if (strncmp(evsel->tp_format->name, "sys_enter_", 10) || |
| 2402 | trace__fprintf_sys_enter(trace, evsel, sample)) { |
| 2403 | event_format__fprintf(evsel->tp_format, sample->cpu, |
| 2404 | sample->raw_data, sample->raw_size, |
| 2405 | trace->output); |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 2406 | ++trace->nr_events_printed; |
Arnaldo Carvalho de Melo | a9c5e6c | 2018-10-22 14:14:16 -0300 | [diff] [blame] | 2407 | |
| 2408 | if (evsel->max_events != ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) { |
Jiri Olsa | 9a10bb2 | 2019-07-21 13:24:03 +0200 | [diff] [blame] | 2409 | evsel__disable(evsel); |
Jiri Olsa | 88761fa | 2019-07-21 13:24:50 +0200 | [diff] [blame] | 2410 | evsel__close(evsel); |
Arnaldo Carvalho de Melo | a9c5e6c | 2018-10-22 14:14:16 -0300 | [diff] [blame] | 2411 | } |
Arnaldo Carvalho de Melo | a98392b | 2018-08-02 14:05:09 -0300 | [diff] [blame] | 2412 | } |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2413 | } |
| 2414 | |
Arnaldo Carvalho de Melo | 1cdf618 | 2018-08-21 11:44:23 -0300 | [diff] [blame] | 2415 | newline: |
Changbin Du | 51125a2 | 2018-03-13 18:40:01 +0800 | [diff] [blame] | 2416 | fprintf(trace->output, "\n"); |
Arnaldo Carvalho de Melo | 202ff96 | 2016-04-12 10:11:07 -0300 | [diff] [blame] | 2417 | |
Arnaldo Carvalho de Melo | 7ad3561 | 2016-04-20 19:55:48 -0300 | [diff] [blame] | 2418 | if (callchain_ret > 0) |
| 2419 | trace__fprintf_callchain(trace, sample); |
| 2420 | else if (callchain_ret < 0) |
| 2421 | pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel)); |
| 2422 | out: |
Arnaldo Carvalho de Melo | a937c66 | 2018-10-20 09:27:52 -0300 | [diff] [blame] | 2423 | thread__put(thread); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2424 | return 0; |
| 2425 | } |
| 2426 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2427 | static void print_location(FILE *f, struct perf_sample *sample, |
| 2428 | struct addr_location *al, |
| 2429 | bool print_dso, bool print_sym) |
| 2430 | { |
| 2431 | |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 2432 | if ((verbose > 0 || print_dso) && al->map) |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2433 | fprintf(f, "%s@", al->map->dso->long_name); |
| 2434 | |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 2435 | if ((verbose > 0 || print_sym) && al->sym) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2436 | fprintf(f, "%s+0x%" PRIx64, al->sym->name, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2437 | al->addr - al->sym->start); |
| 2438 | else if (al->map) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2439 | fprintf(f, "0x%" PRIx64, al->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2440 | else |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 2441 | fprintf(f, "0x%" PRIx64, sample->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | static int trace__pgfault(struct trace *trace, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2445 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | 473398a | 2016-03-22 18:23:43 -0300 | [diff] [blame] | 2446 | union perf_event *event __maybe_unused, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2447 | struct perf_sample *sample) |
| 2448 | { |
| 2449 | struct thread *thread; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2450 | struct addr_location al; |
| 2451 | char map_type = 'd'; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2452 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2453 | int err = -1; |
Arnaldo Carvalho de Melo | 1df5429 | 2016-04-20 20:06:02 -0300 | [diff] [blame] | 2454 | int callchain_ret = 0; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2455 | |
| 2456 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | 1df5429 | 2016-04-20 20:06:02 -0300 | [diff] [blame] | 2457 | |
| 2458 | if (sample->callchain) { |
| 2459 | callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor); |
| 2460 | if (callchain_ret == 0) { |
| 2461 | if (callchain_cursor.nr < trace->min_stack) |
| 2462 | goto out_put; |
| 2463 | callchain_ret = 1; |
| 2464 | } |
| 2465 | } |
| 2466 | |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2467 | ttrace = thread__trace(thread, trace->output); |
| 2468 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2469 | goto out_put; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2470 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2471 | if (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ) |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2472 | ttrace->pfmaj++; |
| 2473 | else |
| 2474 | ttrace->pfmin++; |
| 2475 | |
| 2476 | if (trace->summary_only) |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2477 | goto out; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2478 | |
Arnaldo Carvalho de Melo | 4546263 | 2018-04-24 11:24:49 -0300 | [diff] [blame] | 2479 | thread__find_symbol(thread, sample->cpumode, sample->ip, &al); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2480 | |
Arnaldo Carvalho de Melo | fd2b297 | 2017-03-29 16:37:51 -0300 | [diff] [blame] | 2481 | trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2482 | |
| 2483 | fprintf(trace->output, "%sfault [", |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2484 | evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2485 | "maj" : "min"); |
| 2486 | |
| 2487 | print_location(trace->output, sample, &al, false, true); |
| 2488 | |
| 2489 | fprintf(trace->output, "] => "); |
| 2490 | |
Arnaldo Carvalho de Melo | 117d3c2 | 2018-04-25 18:16:53 -0300 | [diff] [blame] | 2491 | thread__find_symbol(thread, sample->cpumode, sample->addr, &al); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2492 | |
| 2493 | if (!al.map) { |
Arnaldo Carvalho de Melo | 4546263 | 2018-04-24 11:24:49 -0300 | [diff] [blame] | 2494 | thread__find_symbol(thread, sample->cpumode, sample->addr, &al); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2495 | |
| 2496 | if (al.map) |
| 2497 | map_type = 'x'; |
| 2498 | else |
| 2499 | map_type = '?'; |
| 2500 | } |
| 2501 | |
| 2502 | print_location(trace->output, sample, &al, true, false); |
| 2503 | |
| 2504 | fprintf(trace->output, " (%c%c)\n", map_type, al.level); |
Arnaldo Carvalho de Melo | 0c3a6ef | 2016-04-19 16:31:12 -0300 | [diff] [blame] | 2505 | |
Arnaldo Carvalho de Melo | 1df5429 | 2016-04-20 20:06:02 -0300 | [diff] [blame] | 2506 | if (callchain_ret > 0) |
| 2507 | trace__fprintf_callchain(trace, sample); |
| 2508 | else if (callchain_ret < 0) |
| 2509 | pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel)); |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 2510 | |
| 2511 | ++trace->nr_events_printed; |
Arnaldo Carvalho de Melo | b91fc39 | 2015-04-06 20:43:22 -0300 | [diff] [blame] | 2512 | out: |
| 2513 | err = 0; |
| 2514 | out_put: |
| 2515 | thread__put(thread); |
| 2516 | return err; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2517 | } |
| 2518 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2519 | static void trace__set_base_time(struct trace *trace, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2520 | struct evsel *evsel, |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2521 | struct perf_sample *sample) |
| 2522 | { |
Arnaldo Carvalho de Melo | 8a07a80 | 2016-03-31 15:19:39 -0300 | [diff] [blame] | 2523 | /* |
| 2524 | * BPF events were not setting PERF_SAMPLE_TIME, so be more robust |
| 2525 | * and don't use sample->time unconditionally, we may end up having |
| 2526 | * some other event in the future without PERF_SAMPLE_TIME for good |
| 2527 | * reason, i.e. we may not be interested in its timestamps, just in |
| 2528 | * it taking place, picking some piece of information when it |
| 2529 | * appears in our event stream (vfs_getname comes to mind). |
| 2530 | */ |
| 2531 | if (trace->base_time == 0 && !trace->full_time && |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2532 | (evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2533 | trace->base_time = sample->time; |
| 2534 | } |
| 2535 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2536 | static int trace__process_sample(struct perf_tool *tool, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2537 | union perf_event *event, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2538 | struct perf_sample *sample, |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2539 | struct evsel *evsel, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2540 | struct machine *machine __maybe_unused) |
| 2541 | { |
| 2542 | struct trace *trace = container_of(tool, struct trace, tool); |
David Ahern | aa07df6 | 2016-11-25 09:29:52 -0700 | [diff] [blame] | 2543 | struct thread *thread; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2544 | int err = 0; |
| 2545 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2546 | tracepoint_handler handler = evsel->handler; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2547 | |
David Ahern | aa07df6 | 2016-11-25 09:29:52 -0700 | [diff] [blame] | 2548 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
| 2549 | if (thread && thread__is_filtered(thread)) |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2550 | goto out; |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2551 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2552 | trace__set_base_time(trace, evsel, sample); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2553 | |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2554 | if (handler) { |
| 2555 | ++trace->nr_events; |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2556 | handler(trace, evsel, event, sample); |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2557 | } |
Arnaldo Carvalho de Melo | ef65e96 | 2017-03-24 15:03:19 -0300 | [diff] [blame] | 2558 | out: |
| 2559 | thread__put(thread); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2560 | return err; |
| 2561 | } |
| 2562 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2563 | static int trace__record(struct trace *trace, int argc, const char **argv) |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2564 | { |
| 2565 | unsigned int rec_argc, i, j; |
| 2566 | const char **rec_argv; |
| 2567 | const char * const record_args[] = { |
| 2568 | "record", |
| 2569 | "-R", |
| 2570 | "-m", "1024", |
| 2571 | "-c", "1", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2572 | }; |
| 2573 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2574 | const char * const sc_args[] = { "-e", }; |
| 2575 | unsigned int sc_args_nr = ARRAY_SIZE(sc_args); |
| 2576 | const char * const majpf_args[] = { "-e", "major-faults" }; |
| 2577 | unsigned int majpf_args_nr = ARRAY_SIZE(majpf_args); |
| 2578 | const char * const minpf_args[] = { "-e", "minor-faults" }; |
| 2579 | unsigned int minpf_args_nr = ARRAY_SIZE(minpf_args); |
| 2580 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2581 | /* +1 is for the event string below */ |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2582 | rec_argc = ARRAY_SIZE(record_args) + sc_args_nr + 1 + |
| 2583 | majpf_args_nr + minpf_args_nr + argc; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2584 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 2585 | |
| 2586 | if (rec_argv == NULL) |
| 2587 | return -ENOMEM; |
| 2588 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2589 | j = 0; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2590 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2591 | rec_argv[j++] = record_args[i]; |
| 2592 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2593 | if (trace->trace_syscalls) { |
| 2594 | for (i = 0; i < sc_args_nr; i++) |
| 2595 | rec_argv[j++] = sc_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2596 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2597 | /* event string may be different for older kernels - e.g., RHEL6 */ |
| 2598 | if (is_valid_tracepoint("raw_syscalls:sys_enter")) |
| 2599 | rec_argv[j++] = "raw_syscalls:sys_enter,raw_syscalls:sys_exit"; |
| 2600 | else if (is_valid_tracepoint("syscalls:sys_enter")) |
| 2601 | rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit"; |
| 2602 | else { |
| 2603 | pr_err("Neither raw_syscalls nor syscalls events exist.\n"); |
Martin Kepplinger | c896f85 | 2017-09-13 21:14:19 +0200 | [diff] [blame] | 2604 | free(rec_argv); |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2605 | return -1; |
| 2606 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2607 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2608 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2609 | if (trace->trace_pgfaults & TRACE_PFMAJ) |
| 2610 | for (i = 0; i < majpf_args_nr; i++) |
| 2611 | rec_argv[j++] = majpf_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2612 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2613 | if (trace->trace_pgfaults & TRACE_PFMIN) |
| 2614 | for (i = 0; i < minpf_args_nr; i++) |
| 2615 | rec_argv[j++] = minpf_args[i]; |
| 2616 | |
| 2617 | for (i = 0; i < (unsigned int)argc; i++) |
| 2618 | rec_argv[j++] = argv[i]; |
| 2619 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 2620 | return cmd_record(j, rec_argv); |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2621 | } |
| 2622 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2623 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); |
| 2624 | |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 2625 | static bool evlist__add_vfs_getname(struct evlist *evlist) |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2626 | { |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2627 | bool found = false; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2628 | struct evsel *evsel, *tmp; |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2629 | struct parse_events_error err = { .idx = 0, }; |
| 2630 | int ret = parse_events(evlist, "probe:vfs_getname*", &err); |
Jiri Olsa | 8dd2a13 | 2015-09-07 10:38:06 +0200 | [diff] [blame] | 2631 | |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2632 | if (ret) |
Arnaldo Carvalho de Melo | 08c9877 | 2015-08-04 17:01:04 -0300 | [diff] [blame] | 2633 | return false; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2634 | |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2635 | evlist__for_each_entry_safe(evlist, evsel, tmp) { |
| 2636 | if (!strstarts(perf_evsel__name(evsel), "probe:vfs_getname")) |
| 2637 | continue; |
| 2638 | |
| 2639 | if (perf_evsel__field(evsel, "pathname")) { |
| 2640 | evsel->handler = trace__vfs_getname; |
| 2641 | found = true; |
| 2642 | continue; |
| 2643 | } |
| 2644 | |
Jiri Olsa | b27c4ec | 2019-07-21 13:24:22 +0200 | [diff] [blame] | 2645 | list_del_init(&evsel->core.node); |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2646 | evsel->evlist = NULL; |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 2647 | evsel__delete(evsel); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2648 | } |
| 2649 | |
Arnaldo Carvalho de Melo | 6ab3bc2 | 2019-01-29 15:12:34 +0100 | [diff] [blame] | 2650 | return found; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2651 | } |
| 2652 | |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2653 | static struct evsel *perf_evsel__new_pgfault(u64 config) |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2654 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2655 | struct evsel *evsel; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2656 | struct perf_event_attr attr = { |
| 2657 | .type = PERF_TYPE_SOFTWARE, |
| 2658 | .mmap_data = 1, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2659 | }; |
| 2660 | |
| 2661 | attr.config = config; |
Arnaldo Carvalho de Melo | 0524798 | 2014-07-23 18:15:09 -0300 | [diff] [blame] | 2662 | attr.sample_period = 1; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2663 | |
| 2664 | event_attr_init(&attr); |
| 2665 | |
Jiri Olsa | 365c3ae | 2019-07-21 13:23:58 +0200 | [diff] [blame] | 2666 | evsel = evsel__new(&attr); |
Arnaldo Carvalho de Melo | 0ae537c | 2016-04-19 16:00:01 -0300 | [diff] [blame] | 2667 | if (evsel) |
| 2668 | evsel->handler = trace__pgfault; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2669 | |
Arnaldo Carvalho de Melo | 0ae537c | 2016-04-19 16:00:01 -0300 | [diff] [blame] | 2670 | return evsel; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2671 | } |
| 2672 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2673 | static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) |
| 2674 | { |
| 2675 | const u32 type = event->header.type; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2676 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2677 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2678 | if (type != PERF_RECORD_SAMPLE) { |
| 2679 | trace__process_event(trace, trace->host, event, sample); |
| 2680 | return; |
| 2681 | } |
| 2682 | |
| 2683 | evsel = perf_evlist__id2evsel(trace->evlist, sample->id); |
| 2684 | if (evsel == NULL) { |
| 2685 | fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); |
| 2686 | return; |
| 2687 | } |
| 2688 | |
Arnaldo Carvalho de Melo | 22ac431 | 2019-08-15 12:15:39 -0300 | [diff] [blame] | 2689 | if (evswitch__discard(&trace->evswitch, evsel)) |
| 2690 | return; |
| 2691 | |
Arnaldo Carvalho de Melo | e600198 | 2016-03-31 15:16:28 -0300 | [diff] [blame] | 2692 | trace__set_base_time(trace, evsel, sample); |
| 2693 | |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2694 | if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT && |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2695 | sample->raw_data == NULL) { |
| 2696 | fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", |
| 2697 | perf_evsel__name(evsel), sample->tid, |
| 2698 | sample->cpu, sample->raw_size); |
| 2699 | } else { |
| 2700 | tracepoint_handler handler = evsel->handler; |
| 2701 | handler(trace, evsel, event, sample); |
| 2702 | } |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 2703 | |
| 2704 | if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX) |
| 2705 | interrupted = true; |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2708 | static int trace__add_syscall_newtp(struct trace *trace) |
| 2709 | { |
| 2710 | int ret = -1; |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 2711 | struct evlist *evlist = trace->evlist; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2712 | struct evsel *sys_enter, *sys_exit; |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2713 | |
Arnaldo Carvalho de Melo | 63f11c8 | 2018-08-02 14:27:09 -0300 | [diff] [blame] | 2714 | sys_enter = perf_evsel__raw_syscall_newtp("sys_enter", trace__sys_enter); |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2715 | if (sys_enter == NULL) |
| 2716 | goto out; |
| 2717 | |
| 2718 | if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) |
| 2719 | goto out_delete_sys_enter; |
| 2720 | |
Arnaldo Carvalho de Melo | 63f11c8 | 2018-08-02 14:27:09 -0300 | [diff] [blame] | 2721 | sys_exit = perf_evsel__raw_syscall_newtp("sys_exit", trace__sys_exit); |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2722 | if (sys_exit == NULL) |
| 2723 | goto out_delete_sys_enter; |
| 2724 | |
| 2725 | if (perf_evsel__init_sc_tp_uint_field(sys_exit, ret)) |
| 2726 | goto out_delete_sys_exit; |
| 2727 | |
Arnaldo Carvalho de Melo | 08e2639 | 2018-01-12 13:29:05 -0300 | [diff] [blame] | 2728 | perf_evsel__config_callchain(sys_enter, &trace->opts, &callchain_param); |
| 2729 | perf_evsel__config_callchain(sys_exit, &trace->opts, &callchain_param); |
| 2730 | |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 2731 | evlist__add(evlist, sys_enter); |
| 2732 | evlist__add(evlist, sys_exit); |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2733 | |
Arnaldo Carvalho de Melo | 2ddd5c0 | 2016-04-18 12:09:08 -0300 | [diff] [blame] | 2734 | if (callchain_param.enabled && !trace->kernel_syscallchains) { |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 2735 | /* |
| 2736 | * We're interested only in the user space callchain |
| 2737 | * leading to the syscall, allow overriding that for |
| 2738 | * debugging reasons using --kernel_syscall_callchains |
| 2739 | */ |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 2740 | sys_exit->core.attr.exclude_callchain_kernel = 1; |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 2741 | } |
| 2742 | |
Arnaldo Carvalho de Melo | 8b3ce75 | 2015-07-02 18:28:11 -0300 | [diff] [blame] | 2743 | trace->syscalls.events.sys_enter = sys_enter; |
| 2744 | trace->syscalls.events.sys_exit = sys_exit; |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2745 | |
| 2746 | ret = 0; |
| 2747 | out: |
| 2748 | return ret; |
| 2749 | |
| 2750 | out_delete_sys_exit: |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 2751 | evsel__delete_priv(sys_exit); |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2752 | out_delete_sys_enter: |
Jiri Olsa | 5eb2dd2 | 2019-07-21 13:23:57 +0200 | [diff] [blame] | 2753 | evsel__delete_priv(sys_enter); |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2754 | goto out; |
| 2755 | } |
| 2756 | |
Arnaldo Carvalho de Melo | 246fbe0 | 2018-12-12 11:06:53 -0300 | [diff] [blame] | 2757 | static int trace__set_ev_qualifier_tp_filter(struct trace *trace) |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2758 | { |
| 2759 | int err = -1; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 2760 | struct evsel *sys_exit; |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2761 | char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, |
| 2762 | trace->ev_qualifier_ids.nr, |
| 2763 | trace->ev_qualifier_ids.entries); |
| 2764 | |
| 2765 | if (filter == NULL) |
| 2766 | goto out_enomem; |
| 2767 | |
Mathieu Poirier | 3541c03 | 2016-09-16 08:44:04 -0600 | [diff] [blame] | 2768 | if (!perf_evsel__append_tp_filter(trace->syscalls.events.sys_enter, |
| 2769 | filter)) { |
Mathieu Poirier | b15d0a4 | 2016-09-16 08:44:03 -0600 | [diff] [blame] | 2770 | sys_exit = trace->syscalls.events.sys_exit; |
Mathieu Poirier | 3541c03 | 2016-09-16 08:44:04 -0600 | [diff] [blame] | 2771 | err = perf_evsel__append_tp_filter(sys_exit, filter); |
Mathieu Poirier | b15d0a4 | 2016-09-16 08:44:03 -0600 | [diff] [blame] | 2772 | } |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 2773 | |
| 2774 | free(filter); |
| 2775 | out: |
| 2776 | return err; |
| 2777 | out_enomem: |
| 2778 | errno = ENOMEM; |
| 2779 | goto out; |
| 2780 | } |
Arnaldo Carvalho de Melo | c27366f | 2015-07-02 18:24:51 -0300 | [diff] [blame] | 2781 | |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2782 | #ifdef HAVE_LIBBPF_SUPPORT |
Arnaldo Carvalho de Melo | 5834da7 | 2019-07-15 17:51:43 -0300 | [diff] [blame] | 2783 | static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name) |
| 2784 | { |
| 2785 | if (trace->bpf_obj == NULL) |
| 2786 | return NULL; |
| 2787 | |
| 2788 | return bpf_object__find_program_by_title(trace->bpf_obj, name); |
| 2789 | } |
| 2790 | |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2791 | static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, struct syscall *sc, |
| 2792 | const char *prog_name, const char *type) |
| 2793 | { |
| 2794 | struct bpf_program *prog; |
| 2795 | |
Arnaldo Carvalho de Melo | 8b8044e | 2019-07-16 15:24:58 -0300 | [diff] [blame] | 2796 | if (prog_name == NULL) { |
| 2797 | char default_prog_name[256]; |
| 2798 | scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name); |
| 2799 | prog = trace__find_bpf_program_by_title(trace, default_prog_name); |
| 2800 | if (prog != NULL) |
| 2801 | goto out_found; |
| 2802 | if (sc->fmt && sc->fmt->alias) { |
| 2803 | scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alias); |
| 2804 | prog = trace__find_bpf_program_by_title(trace, default_prog_name); |
| 2805 | if (prog != NULL) |
| 2806 | goto out_found; |
| 2807 | } |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2808 | goto out_unaugmented; |
Arnaldo Carvalho de Melo | 8b8044e | 2019-07-16 15:24:58 -0300 | [diff] [blame] | 2809 | } |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2810 | |
| 2811 | prog = trace__find_bpf_program_by_title(trace, prog_name); |
Arnaldo Carvalho de Melo | 8b8044e | 2019-07-16 15:24:58 -0300 | [diff] [blame] | 2812 | |
| 2813 | if (prog != NULL) { |
| 2814 | out_found: |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2815 | return prog; |
Arnaldo Carvalho de Melo | 8b8044e | 2019-07-16 15:24:58 -0300 | [diff] [blame] | 2816 | } |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2817 | |
| 2818 | pr_debug("Couldn't find BPF prog \"%s\" to associate with syscalls:sys_%s_%s, not augmenting it\n", |
| 2819 | prog_name, type, sc->name); |
| 2820 | out_unaugmented: |
| 2821 | return trace->syscalls.unaugmented_prog; |
| 2822 | } |
| 2823 | |
| 2824 | static void trace__init_syscall_bpf_progs(struct trace *trace, int id) |
| 2825 | { |
| 2826 | struct syscall *sc = trace__syscall_info(trace, NULL, id); |
| 2827 | |
| 2828 | if (sc == NULL) |
| 2829 | return; |
| 2830 | |
Arnaldo Carvalho de Melo | 8b8044e | 2019-07-16 15:24:58 -0300 | [diff] [blame] | 2831 | sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.sys_enter : NULL, "enter"); |
| 2832 | sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.sys_exit : NULL, "exit"); |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2833 | } |
| 2834 | |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 2835 | static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id) |
| 2836 | { |
| 2837 | struct syscall *sc = trace__syscall_info(trace, NULL, id); |
| 2838 | return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_prog); |
| 2839 | } |
| 2840 | |
| 2841 | static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id) |
| 2842 | { |
| 2843 | struct syscall *sc = trace__syscall_info(trace, NULL, id); |
| 2844 | return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_prog); |
| 2845 | } |
| 2846 | |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 2847 | static void trace__init_bpf_map_syscall_args(struct trace *trace, int id, struct bpf_map_syscall_entry *entry) |
| 2848 | { |
| 2849 | struct syscall *sc = trace__syscall_info(trace, NULL, id); |
| 2850 | int arg = 0; |
| 2851 | |
| 2852 | if (sc == NULL) |
| 2853 | goto out; |
| 2854 | |
| 2855 | for (; arg < sc->nr_args; ++arg) { |
| 2856 | entry->string_args_len[arg] = 0; |
| 2857 | if (sc->arg_fmt[arg].scnprintf == SCA_FILENAME) { |
| 2858 | /* Should be set like strace -s strsize */ |
| 2859 | entry->string_args_len[arg] = PATH_MAX; |
| 2860 | } |
| 2861 | } |
| 2862 | out: |
| 2863 | for (; arg < 6; ++arg) |
| 2864 | entry->string_args_len[arg] = 0; |
| 2865 | } |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2866 | static int trace__set_ev_qualifier_bpf_filter(struct trace *trace) |
| 2867 | { |
| 2868 | int fd = bpf_map__fd(trace->syscalls.map); |
Arnaldo Carvalho de Melo | bbab50d | 2018-12-12 16:54:09 -0300 | [diff] [blame] | 2869 | struct bpf_map_syscall_entry value = { |
| 2870 | .enabled = !trace->not_ev_qualifier, |
| 2871 | }; |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2872 | int err = 0; |
| 2873 | size_t i; |
| 2874 | |
| 2875 | for (i = 0; i < trace->ev_qualifier_ids.nr; ++i) { |
| 2876 | int key = trace->ev_qualifier_ids.entries[i]; |
| 2877 | |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2878 | if (value.enabled) { |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 2879 | trace__init_bpf_map_syscall_args(trace, key, &value); |
Arnaldo Carvalho de Melo | 6ff8fff | 2019-07-16 10:59:19 -0300 | [diff] [blame] | 2880 | trace__init_syscall_bpf_progs(trace, key); |
| 2881 | } |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 2882 | |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2883 | err = bpf_map_update_elem(fd, &key, &value, BPF_EXIST); |
| 2884 | if (err) |
| 2885 | break; |
| 2886 | } |
| 2887 | |
| 2888 | return err; |
| 2889 | } |
| 2890 | |
| 2891 | static int __trace__init_syscalls_bpf_map(struct trace *trace, bool enabled) |
| 2892 | { |
| 2893 | int fd = bpf_map__fd(trace->syscalls.map); |
Arnaldo Carvalho de Melo | bbab50d | 2018-12-12 16:54:09 -0300 | [diff] [blame] | 2894 | struct bpf_map_syscall_entry value = { |
| 2895 | .enabled = enabled, |
| 2896 | }; |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2897 | int err = 0, key; |
| 2898 | |
| 2899 | for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) { |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 2900 | if (enabled) |
Arnaldo Carvalho de Melo | 4cae8675 | 2019-06-03 16:52:46 -0300 | [diff] [blame] | 2901 | trace__init_bpf_map_syscall_args(trace, key, &value); |
| 2902 | |
Arnaldo Carvalho de Melo | bbab50d | 2018-12-12 16:54:09 -0300 | [diff] [blame] | 2903 | err = bpf_map_update_elem(fd, &key, &value, BPF_ANY); |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 2904 | if (err) |
| 2905 | break; |
| 2906 | } |
| 2907 | |
| 2908 | return err; |
| 2909 | } |
| 2910 | |
| 2911 | static int trace__init_syscalls_bpf_map(struct trace *trace) |
| 2912 | { |
| 2913 | bool enabled = true; |
| 2914 | |
| 2915 | if (trace->ev_qualifier_ids.nr) |
| 2916 | enabled = trace->not_ev_qualifier; |
| 2917 | |
| 2918 | return __trace__init_syscalls_bpf_map(trace, enabled); |
| 2919 | } |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 2920 | |
Arnaldo Carvalho de Melo | ad4153f | 2019-07-17 18:27:33 -0300 | [diff] [blame] | 2921 | static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *sc) |
| 2922 | { |
| 2923 | struct tep_format_field *field, *candidate_field; |
| 2924 | int id; |
| 2925 | |
| 2926 | /* |
| 2927 | * We're only interested in syscalls that have a pointer: |
| 2928 | */ |
| 2929 | for (field = sc->args; field; field = field->next) { |
| 2930 | if (field->flags & TEP_FIELD_IS_POINTER) |
| 2931 | goto try_to_find_pair; |
| 2932 | } |
| 2933 | |
| 2934 | return NULL; |
| 2935 | |
| 2936 | try_to_find_pair: |
| 2937 | for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) { |
| 2938 | struct syscall *pair = trace__syscall_info(trace, NULL, id); |
| 2939 | struct bpf_program *pair_prog; |
| 2940 | bool is_candidate = false; |
| 2941 | |
| 2942 | if (pair == NULL || pair == sc || |
| 2943 | pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog) |
| 2944 | continue; |
| 2945 | |
| 2946 | for (field = sc->args, candidate_field = pair->args; |
| 2947 | field && candidate_field; field = field->next, candidate_field = candidate_field->next) { |
| 2948 | bool is_pointer = field->flags & TEP_FIELD_IS_POINTER, |
| 2949 | candidate_is_pointer = candidate_field->flags & TEP_FIELD_IS_POINTER; |
| 2950 | |
| 2951 | if (is_pointer) { |
| 2952 | if (!candidate_is_pointer) { |
| 2953 | // The candidate just doesn't copies our pointer arg, might copy other pointers we want. |
| 2954 | continue; |
| 2955 | } |
| 2956 | } else { |
| 2957 | if (candidate_is_pointer) { |
| 2958 | // The candidate might copy a pointer we don't have, skip it. |
| 2959 | goto next_candidate; |
| 2960 | } |
| 2961 | continue; |
| 2962 | } |
| 2963 | |
| 2964 | if (strcmp(field->type, candidate_field->type)) |
| 2965 | goto next_candidate; |
| 2966 | |
| 2967 | is_candidate = true; |
| 2968 | } |
| 2969 | |
| 2970 | if (!is_candidate) |
| 2971 | goto next_candidate; |
| 2972 | |
| 2973 | /* |
| 2974 | * Check if the tentative pair syscall augmenter has more pointers, if it has, |
| 2975 | * then it may be collecting that and we then can't use it, as it would collect |
| 2976 | * more than what is common to the two syscalls. |
| 2977 | */ |
| 2978 | if (candidate_field) { |
| 2979 | for (candidate_field = candidate_field->next; candidate_field; candidate_field = candidate_field->next) |
| 2980 | if (candidate_field->flags & TEP_FIELD_IS_POINTER) |
| 2981 | goto next_candidate; |
| 2982 | } |
| 2983 | |
| 2984 | pair_prog = pair->bpf_prog.sys_enter; |
| 2985 | /* |
| 2986 | * If the pair isn't enabled, then its bpf_prog.sys_enter will not |
| 2987 | * have been searched for, so search it here and if it returns the |
| 2988 | * unaugmented one, then ignore it, otherwise we'll reuse that BPF |
| 2989 | * program for a filtered syscall on a non-filtered one. |
| 2990 | * |
| 2991 | * For instance, we have "!syscalls:sys_enter_renameat" and that is |
| 2992 | * useful for "renameat2". |
| 2993 | */ |
| 2994 | if (pair_prog == NULL) { |
| 2995 | pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_enter : NULL, "enter"); |
| 2996 | if (pair_prog == trace->syscalls.unaugmented_prog) |
| 2997 | goto next_candidate; |
| 2998 | } |
| 2999 | |
| 3000 | pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->name, sc->name); |
| 3001 | return pair_prog; |
| 3002 | next_candidate: |
| 3003 | continue; |
| 3004 | } |
| 3005 | |
| 3006 | return NULL; |
| 3007 | } |
| 3008 | |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 3009 | static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace) |
| 3010 | { |
| 3011 | int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter), |
| 3012 | map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit); |
| 3013 | int err = 0, key; |
| 3014 | |
| 3015 | for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) { |
| 3016 | int prog_fd; |
| 3017 | |
| 3018 | if (!trace__syscall_enabled(trace, key)) |
| 3019 | continue; |
| 3020 | |
| 3021 | trace__init_syscall_bpf_progs(trace, key); |
| 3022 | |
| 3023 | // It'll get at least the "!raw_syscalls:unaugmented" |
| 3024 | prog_fd = trace__bpf_prog_sys_enter_fd(trace, key); |
| 3025 | err = bpf_map_update_elem(map_enter_fd, &key, &prog_fd, BPF_ANY); |
| 3026 | if (err) |
| 3027 | break; |
| 3028 | prog_fd = trace__bpf_prog_sys_exit_fd(trace, key); |
| 3029 | err = bpf_map_update_elem(map_exit_fd, &key, &prog_fd, BPF_ANY); |
| 3030 | if (err) |
| 3031 | break; |
| 3032 | } |
| 3033 | |
Arnaldo Carvalho de Melo | ad4153f | 2019-07-17 18:27:33 -0300 | [diff] [blame] | 3034 | /* |
| 3035 | * Now lets do a second pass looking for enabled syscalls without |
| 3036 | * an augmenter that have a signature that is a superset of another |
| 3037 | * syscall with an augmenter so that we can auto-reuse it. |
| 3038 | * |
| 3039 | * I.e. if we have an augmenter for the "open" syscall that has |
| 3040 | * this signature: |
| 3041 | * |
| 3042 | * int open(const char *pathname, int flags, mode_t mode); |
| 3043 | * |
| 3044 | * I.e. that will collect just the first string argument, then we |
| 3045 | * can reuse it for the 'creat' syscall, that has this signature: |
| 3046 | * |
| 3047 | * int creat(const char *pathname, mode_t mode); |
| 3048 | * |
| 3049 | * and for: |
| 3050 | * |
| 3051 | * int stat(const char *pathname, struct stat *statbuf); |
| 3052 | * int lstat(const char *pathname, struct stat *statbuf); |
| 3053 | * |
| 3054 | * Because the 'open' augmenter will collect the first arg as a string, |
| 3055 | * and leave alone all the other args, which already helps with |
| 3056 | * beautifying 'stat' and 'lstat''s pathname arg. |
| 3057 | * |
| 3058 | * Then, in time, when 'stat' gets an augmenter that collects both |
| 3059 | * first and second arg (this one on the raw_syscalls:sys_exit prog |
| 3060 | * array tail call, then that one will be used. |
| 3061 | */ |
| 3062 | for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) { |
| 3063 | struct syscall *sc = trace__syscall_info(trace, NULL, key); |
| 3064 | struct bpf_program *pair_prog; |
| 3065 | int prog_fd; |
| 3066 | |
| 3067 | if (sc == NULL || sc->bpf_prog.sys_enter == NULL) |
| 3068 | continue; |
| 3069 | |
| 3070 | /* |
| 3071 | * For now we're just reusing the sys_enter prog, and if it |
| 3072 | * already has an augmenter, we don't need to find one. |
| 3073 | */ |
| 3074 | if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog) |
| 3075 | continue; |
| 3076 | |
| 3077 | /* |
| 3078 | * Look at all the other syscalls for one that has a signature |
| 3079 | * that is close enough that we can share: |
| 3080 | */ |
| 3081 | pair_prog = trace__find_usable_bpf_prog_entry(trace, sc); |
| 3082 | if (pair_prog == NULL) |
| 3083 | continue; |
| 3084 | |
| 3085 | sc->bpf_prog.sys_enter = pair_prog; |
| 3086 | |
| 3087 | /* |
| 3088 | * Update the BPF_MAP_TYPE_PROG_SHARED for raw_syscalls:sys_enter |
| 3089 | * with the fd for the program we're reusing: |
| 3090 | */ |
| 3091 | prog_fd = bpf_program__fd(sc->bpf_prog.sys_enter); |
| 3092 | err = bpf_map_update_elem(map_enter_fd, &key, &prog_fd, BPF_ANY); |
| 3093 | if (err) |
| 3094 | break; |
| 3095 | } |
| 3096 | |
| 3097 | |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 3098 | return err; |
| 3099 | } |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 3100 | #else |
| 3101 | static int trace__set_ev_qualifier_bpf_filter(struct trace *trace __maybe_unused) |
| 3102 | { |
| 3103 | return 0; |
| 3104 | } |
| 3105 | |
| 3106 | static int trace__init_syscalls_bpf_map(struct trace *trace __maybe_unused) |
| 3107 | { |
| 3108 | return 0; |
| 3109 | } |
Arnaldo Carvalho de Melo | 5834da7 | 2019-07-15 17:51:43 -0300 | [diff] [blame] | 3110 | |
| 3111 | static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace __maybe_unused, |
| 3112 | const char *name __maybe_unused) |
| 3113 | { |
| 3114 | return NULL; |
| 3115 | } |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 3116 | |
| 3117 | static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused) |
| 3118 | { |
| 3119 | return 0; |
| 3120 | } |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 3121 | #endif // HAVE_LIBBPF_SUPPORT |
| 3122 | |
Arnaldo Carvalho de Melo | 246fbe0 | 2018-12-12 11:06:53 -0300 | [diff] [blame] | 3123 | static int trace__set_ev_qualifier_filter(struct trace *trace) |
| 3124 | { |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 3125 | if (trace->syscalls.map) |
| 3126 | return trace__set_ev_qualifier_bpf_filter(trace); |
Arnaldo Carvalho de Melo | f76214f | 2018-12-19 10:01:20 -0300 | [diff] [blame] | 3127 | if (trace->syscalls.events.sys_enter) |
| 3128 | return trace__set_ev_qualifier_tp_filter(trace); |
| 3129 | return 0; |
Arnaldo Carvalho de Melo | 246fbe0 | 2018-12-12 11:06:53 -0300 | [diff] [blame] | 3130 | } |
| 3131 | |
Arnaldo Carvalho de Melo | a9964c4 | 2018-11-07 10:08:00 -0300 | [diff] [blame] | 3132 | static int bpf_map__set_filter_pids(struct bpf_map *map __maybe_unused, |
| 3133 | size_t npids __maybe_unused, pid_t *pids __maybe_unused) |
| 3134 | { |
| 3135 | int err = 0; |
| 3136 | #ifdef HAVE_LIBBPF_SUPPORT |
| 3137 | bool value = true; |
| 3138 | int map_fd = bpf_map__fd(map); |
| 3139 | size_t i; |
| 3140 | |
| 3141 | for (i = 0; i < npids; ++i) { |
| 3142 | err = bpf_map_update_elem(map_fd, &pids[i], &value, BPF_ANY); |
| 3143 | if (err) |
| 3144 | break; |
| 3145 | } |
| 3146 | #endif |
| 3147 | return err; |
| 3148 | } |
| 3149 | |
Arnaldo Carvalho de Melo | dd1a503 | 2017-07-20 11:17:51 -0300 | [diff] [blame] | 3150 | static int trace__set_filter_loop_pids(struct trace *trace) |
| 3151 | { |
Arnaldo Carvalho de Melo | a9964c4 | 2018-11-07 10:08:00 -0300 | [diff] [blame] | 3152 | unsigned int nr = 1, err; |
Arnaldo Carvalho de Melo | dd1a503 | 2017-07-20 11:17:51 -0300 | [diff] [blame] | 3153 | pid_t pids[32] = { |
| 3154 | getpid(), |
| 3155 | }; |
Arnaldo Carvalho de Melo | 082ab9a | 2017-07-20 11:32:05 -0300 | [diff] [blame] | 3156 | struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); |
| 3157 | |
| 3158 | while (thread && nr < ARRAY_SIZE(pids)) { |
| 3159 | struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid); |
| 3160 | |
| 3161 | if (parent == NULL) |
| 3162 | break; |
| 3163 | |
Arnaldo Carvalho de Melo | ca2da70 | 2019-02-12 13:51:49 -0300 | [diff] [blame] | 3164 | if (!strcmp(thread__comm_str(parent), "sshd") || |
| 3165 | strstarts(thread__comm_str(parent), "gnome-terminal")) { |
Arnaldo Carvalho de Melo | 082ab9a | 2017-07-20 11:32:05 -0300 | [diff] [blame] | 3166 | pids[nr++] = parent->tid; |
| 3167 | break; |
| 3168 | } |
| 3169 | thread = parent; |
| 3170 | } |
Arnaldo Carvalho de Melo | dd1a503 | 2017-07-20 11:17:51 -0300 | [diff] [blame] | 3171 | |
Arnaldo Carvalho de Melo | a9964c4 | 2018-11-07 10:08:00 -0300 | [diff] [blame] | 3172 | err = perf_evlist__set_tp_filter_pids(trace->evlist, nr, pids); |
| 3173 | if (!err && trace->filter_pids.map) |
| 3174 | err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids); |
| 3175 | |
| 3176 | return err; |
| 3177 | } |
| 3178 | |
| 3179 | static int trace__set_filter_pids(struct trace *trace) |
| 3180 | { |
| 3181 | int err = 0; |
| 3182 | /* |
| 3183 | * Better not use !target__has_task() here because we need to cover the |
| 3184 | * case where no threads were specified in the command line, but a |
| 3185 | * workload was, and in that case we will fill in the thread_map when |
| 3186 | * we fork the workload in perf_evlist__prepare_workload. |
| 3187 | */ |
| 3188 | if (trace->filter_pids.nr > 0) { |
| 3189 | err = perf_evlist__set_tp_filter_pids(trace->evlist, trace->filter_pids.nr, |
| 3190 | trace->filter_pids.entries); |
| 3191 | if (!err && trace->filter_pids.map) { |
| 3192 | err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr, |
| 3193 | trace->filter_pids.entries); |
| 3194 | } |
Jiri Olsa | a2f354e | 2019-08-22 13:11:41 +0200 | [diff] [blame] | 3195 | } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) { |
Arnaldo Carvalho de Melo | a9964c4 | 2018-11-07 10:08:00 -0300 | [diff] [blame] | 3196 | err = trace__set_filter_loop_pids(trace); |
| 3197 | } |
| 3198 | |
| 3199 | return err; |
Arnaldo Carvalho de Melo | dd1a503 | 2017-07-20 11:17:51 -0300 | [diff] [blame] | 3200 | } |
| 3201 | |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3202 | static int __trace__deliver_event(struct trace *trace, union perf_event *event) |
Jiri Olsa | 1f44b3e | 2018-12-05 17:05:08 +0100 | [diff] [blame] | 3203 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3204 | struct evlist *evlist = trace->evlist; |
Jiri Olsa | 1f44b3e | 2018-12-05 17:05:08 +0100 | [diff] [blame] | 3205 | struct perf_sample sample; |
| 3206 | int err; |
| 3207 | |
| 3208 | err = perf_evlist__parse_sample(evlist, event, &sample); |
| 3209 | if (err) |
| 3210 | fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); |
| 3211 | else |
| 3212 | trace__handle_event(trace, event, &sample); |
| 3213 | |
| 3214 | return 0; |
| 3215 | } |
| 3216 | |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 3217 | static int __trace__flush_events(struct trace *trace) |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3218 | { |
| 3219 | u64 first = ordered_events__first_time(&trace->oe.data); |
| 3220 | u64 flush = trace->oe.last - NSEC_PER_SEC; |
| 3221 | |
| 3222 | /* Is there some thing to flush.. */ |
| 3223 | if (first && first < flush) |
| 3224 | return ordered_events__flush_time(&trace->oe.data, flush); |
| 3225 | |
| 3226 | return 0; |
| 3227 | } |
| 3228 | |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 3229 | static int trace__flush_events(struct trace *trace) |
| 3230 | { |
| 3231 | return !trace->sort_events ? 0 : __trace__flush_events(trace); |
| 3232 | } |
| 3233 | |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3234 | static int trace__deliver_event(struct trace *trace, union perf_event *event) |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3235 | { |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3236 | int err; |
| 3237 | |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 3238 | if (!trace->sort_events) |
| 3239 | return __trace__deliver_event(trace, event); |
| 3240 | |
| 3241 | err = perf_evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last); |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3242 | if (err && err != -1) |
| 3243 | return err; |
| 3244 | |
| 3245 | err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0); |
| 3246 | if (err) |
| 3247 | return err; |
| 3248 | |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3249 | return trace__flush_events(trace); |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | static int ordered_events__deliver_event(struct ordered_events *oe, |
| 3253 | struct ordered_event *event) |
| 3254 | { |
| 3255 | struct trace *trace = container_of(oe, struct trace, oe.data); |
| 3256 | |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3257 | return __trace__deliver_event(trace, event->event); |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3258 | } |
| 3259 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3260 | 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] | 3261 | { |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3262 | struct evlist *evlist = trace->evlist; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3263 | struct evsel *evsel, *pgfault_maj = NULL, *pgfault_min = NULL; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 3264 | int err = -1, i; |
| 3265 | unsigned long before; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3266 | const bool forks = argc > 0; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 3267 | bool draining = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3268 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 3269 | trace->live = true; |
| 3270 | |
Arnaldo Carvalho de Melo | 0df50e0 | 2018-12-12 13:47:40 -0300 | [diff] [blame] | 3271 | if (!trace->raw_augmented_syscalls) { |
| 3272 | if (trace->trace_syscalls && trace__add_syscall_newtp(trace)) |
| 3273 | goto out_error_raw_syscalls; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3274 | |
Arnaldo Carvalho de Melo | 0df50e0 | 2018-12-12 13:47:40 -0300 | [diff] [blame] | 3275 | if (trace->trace_syscalls) |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 3276 | trace->vfs_getname = evlist__add_vfs_getname(evlist); |
Arnaldo Carvalho de Melo | 0df50e0 | 2018-12-12 13:47:40 -0300 | [diff] [blame] | 3277 | } |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 3278 | |
Arnaldo Carvalho de Melo | 0ae537c | 2016-04-19 16:00:01 -0300 | [diff] [blame] | 3279 | if ((trace->trace_pgfaults & TRACE_PFMAJ)) { |
| 3280 | pgfault_maj = perf_evsel__new_pgfault(PERF_COUNT_SW_PAGE_FAULTS_MAJ); |
| 3281 | if (pgfault_maj == NULL) |
| 3282 | goto out_error_mem; |
Arnaldo Carvalho de Melo | 08e2639 | 2018-01-12 13:29:05 -0300 | [diff] [blame] | 3283 | perf_evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param); |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 3284 | evlist__add(evlist, pgfault_maj); |
Arnaldo Carvalho de Melo | e2726d9 | 2015-01-22 10:34:22 -0300 | [diff] [blame] | 3285 | } |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3286 | |
Arnaldo Carvalho de Melo | 0ae537c | 2016-04-19 16:00:01 -0300 | [diff] [blame] | 3287 | if ((trace->trace_pgfaults & TRACE_PFMIN)) { |
| 3288 | pgfault_min = perf_evsel__new_pgfault(PERF_COUNT_SW_PAGE_FAULTS_MIN); |
| 3289 | if (pgfault_min == NULL) |
| 3290 | goto out_error_mem; |
Arnaldo Carvalho de Melo | 08e2639 | 2018-01-12 13:29:05 -0300 | [diff] [blame] | 3291 | perf_evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param); |
Jiri Olsa | a1cf3a7 | 2019-07-21 13:23:59 +0200 | [diff] [blame] | 3292 | evlist__add(evlist, pgfault_min); |
Arnaldo Carvalho de Melo | 0ae537c | 2016-04-19 16:00:01 -0300 | [diff] [blame] | 3293 | } |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3294 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3295 | if (trace->sched && |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 3296 | perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime", |
| 3297 | trace__sched_stat_runtime)) |
| 3298 | goto out_error_sched_stat_runtime; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3299 | |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 3300 | /* |
| 3301 | * If a global cgroup was set, apply it to all the events without an |
| 3302 | * explicit cgroup. I.e.: |
| 3303 | * |
| 3304 | * trace -G A -e sched:*switch |
| 3305 | * |
| 3306 | * Will set all raw_syscalls:sys_{enter,exit}, pgfault, vfs_getname, etc |
| 3307 | * _and_ sched:sched_switch to the 'A' cgroup, while: |
| 3308 | * |
| 3309 | * trace -e sched:*switch -G A |
| 3310 | * |
| 3311 | * will only set the sched:sched_switch event to the 'A' cgroup, all the |
| 3312 | * other events (raw_syscalls:sys_{enter,exit}, etc are left "without" |
| 3313 | * a cgroup (on the root cgroup, sys wide, etc). |
| 3314 | * |
| 3315 | * Multiple cgroups: |
| 3316 | * |
| 3317 | * trace -G A -e sched:*switch -G B |
| 3318 | * |
| 3319 | * the syscall ones go to the 'A' cgroup, the sched:sched_switch goes |
| 3320 | * to the 'B' cgroup. |
| 3321 | * |
| 3322 | * evlist__set_default_cgroup() grabs a reference of the passed cgroup |
| 3323 | * only for the evsels still without a cgroup, i.e. evsel->cgroup == NULL. |
| 3324 | */ |
| 3325 | if (trace->cgroup) |
| 3326 | evlist__set_default_cgroup(trace->evlist, trace->cgroup); |
| 3327 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3328 | err = perf_evlist__create_maps(evlist, &trace->opts.target); |
| 3329 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3330 | 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] | 3331 | goto out_delete_evlist; |
| 3332 | } |
| 3333 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 3334 | err = trace__symbols_init(trace, evlist); |
| 3335 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3336 | fprintf(trace->output, "Problems initializing symbol libraries!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 3337 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 3338 | } |
| 3339 | |
Arnaldo Carvalho de Melo | 75d5011 | 2018-01-15 10:39:55 -0300 | [diff] [blame] | 3340 | perf_evlist__config(evlist, &trace->opts, &callchain_param); |
Arnaldo Carvalho de Melo | fde54b7 | 2016-04-11 18:42:37 -0300 | [diff] [blame] | 3341 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3342 | signal(SIGCHLD, sig_handler); |
| 3343 | signal(SIGINT, sig_handler); |
| 3344 | |
| 3345 | if (forks) { |
Namhyung Kim | 6ef73ec | 2013-03-11 16:43:15 +0900 | [diff] [blame] | 3346 | err = perf_evlist__prepare_workload(evlist, &trace->opts.target, |
Arnaldo Carvalho de Melo | 735f7e0 | 2014-01-03 14:56:49 -0300 | [diff] [blame] | 3347 | argv, false, NULL); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3348 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3349 | fprintf(trace->output, "Couldn't run the workload!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 3350 | goto out_delete_evlist; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3351 | } |
| 3352 | } |
| 3353 | |
Jiri Olsa | 474ddc4 | 2019-07-21 13:24:06 +0200 | [diff] [blame] | 3354 | err = evlist__open(evlist); |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 3355 | if (err < 0) |
| 3356 | goto out_error_open; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3357 | |
Wang Nan | ba50423 | 2016-02-26 09:31:54 +0000 | [diff] [blame] | 3358 | err = bpf__apply_obj_config(); |
| 3359 | if (err) { |
| 3360 | char errbuf[BUFSIZ]; |
| 3361 | |
| 3362 | bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf)); |
| 3363 | pr_err("ERROR: Apply config to BPF failed: %s\n", |
| 3364 | errbuf); |
| 3365 | goto out_error_open; |
| 3366 | } |
| 3367 | |
Arnaldo Carvalho de Melo | a9964c4 | 2018-11-07 10:08:00 -0300 | [diff] [blame] | 3368 | err = trace__set_filter_pids(trace); |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 3369 | if (err < 0) |
| 3370 | goto out_error_mem; |
| 3371 | |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 3372 | if (trace->syscalls.map) |
| 3373 | trace__init_syscalls_bpf_map(trace); |
| 3374 | |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 3375 | if (trace->syscalls.prog_array.sys_enter) |
| 3376 | trace__init_syscalls_bpf_prog_array_maps(trace); |
| 3377 | |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 3378 | if (trace->ev_qualifier_ids.nr > 0) { |
| 3379 | err = trace__set_ev_qualifier_filter(trace); |
| 3380 | if (err < 0) |
| 3381 | goto out_errno; |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 3382 | |
Arnaldo Carvalho de Melo | 0df50e0 | 2018-12-12 13:47:40 -0300 | [diff] [blame] | 3383 | if (trace->syscalls.events.sys_exit) { |
| 3384 | pr_debug("event qualifier tracepoint filter: %s\n", |
| 3385 | trace->syscalls.events.sys_exit->filter); |
| 3386 | } |
Arnaldo Carvalho de Melo | 2e5e5f8 | 2015-08-03 17:12:29 -0300 | [diff] [blame] | 3387 | } |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 3388 | |
Arnaldo Carvalho de Melo | 79d725c | 2019-07-16 16:56:49 -0300 | [diff] [blame] | 3389 | /* |
| 3390 | * If the "close" syscall is not traced, then we will not have the |
| 3391 | * opportunity to, in syscall_arg__scnprintf_close_fd() invalidate the |
| 3392 | * fd->pathname table and were ending up showing the last value set by |
| 3393 | * syscalls opening a pathname and associating it with a descriptor or |
| 3394 | * reading it from /proc/pid/fd/ in cases where that doesn't make |
| 3395 | * sense. |
| 3396 | * |
| 3397 | * So just disable this beautifier (SCA_FD, SCA_FDAT) when 'close' is |
| 3398 | * not in use. |
| 3399 | */ |
| 3400 | trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close")); |
| 3401 | |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 3402 | err = perf_evlist__apply_filters(evlist, &evsel); |
| 3403 | if (err < 0) |
| 3404 | goto out_error_apply_filters; |
Arnaldo Carvalho de Melo | 241b057 | 2015-02-21 10:15:21 -0800 | [diff] [blame] | 3405 | |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 3406 | if (trace->dump.map) |
| 3407 | bpf_map__fprintf(trace->dump.map, trace->output); |
| 3408 | |
Wang Nan | f74b9d3a | 2017-12-03 02:00:37 +0000 | [diff] [blame] | 3409 | err = perf_evlist__mmap(evlist, trace->opts.mmap_pages); |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 3410 | if (err < 0) |
| 3411 | goto out_error_mmap; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3412 | |
Alexis Berlemont | e36b782 | 2016-10-10 07:43:28 +0200 | [diff] [blame] | 3413 | if (!target__none(&trace->opts.target) && !trace->opts.initial_delay) |
Jiri Olsa | 1c87f16 | 2019-07-21 13:24:08 +0200 | [diff] [blame] | 3414 | evlist__enable(evlist); |
Arnaldo Carvalho de Melo | cb24d01 | 2015-04-22 10:04:23 -0300 | [diff] [blame] | 3415 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3416 | if (forks) |
| 3417 | perf_evlist__start_workload(evlist); |
| 3418 | |
Alexis Berlemont | e36b782 | 2016-10-10 07:43:28 +0200 | [diff] [blame] | 3419 | if (trace->opts.initial_delay) { |
| 3420 | usleep(trace->opts.initial_delay * 1000); |
Jiri Olsa | 1c87f16 | 2019-07-21 13:24:08 +0200 | [diff] [blame] | 3421 | evlist__enable(evlist); |
Alexis Berlemont | e36b782 | 2016-10-10 07:43:28 +0200 | [diff] [blame] | 3422 | } |
| 3423 | |
Jiri Olsa | a2f354e | 2019-08-22 13:11:41 +0200 | [diff] [blame] | 3424 | trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 || |
Jiri Olsa | 03617c2 | 2019-07-21 13:24:42 +0200 | [diff] [blame] | 3425 | evlist->core.threads->nr > 1 || |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3426 | perf_evlist__first(evlist)->core.attr.inherit; |
Arnaldo Carvalho de Melo | bd3dda9 | 2018-01-15 11:33:53 -0300 | [diff] [blame] | 3427 | |
| 3428 | /* |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3429 | * Now that we already used evsel->core.attr to ask the kernel to setup the |
| 3430 | * events, lets reuse evsel->core.attr.sample_max_stack as the limit in |
Arnaldo Carvalho de Melo | bd3dda9 | 2018-01-15 11:33:53 -0300 | [diff] [blame] | 3431 | * trace__resolve_callchain(), allowing per-event max-stack settings |
Ingo Molnar | adba163 | 2018-12-03 11:22:00 +0100 | [diff] [blame] | 3432 | * to override an explicitly set --max-stack global setting. |
Arnaldo Carvalho de Melo | bd3dda9 | 2018-01-15 11:33:53 -0300 | [diff] [blame] | 3433 | */ |
| 3434 | evlist__for_each_entry(evlist, evsel) { |
Arnaldo Carvalho de Melo | 27de9b2 | 2018-05-28 16:00:29 -0300 | [diff] [blame] | 3435 | if (evsel__has_callchain(evsel) && |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3436 | evsel->core.attr.sample_max_stack == 0) |
| 3437 | evsel->core.attr.sample_max_stack = trace->max_stack; |
Arnaldo Carvalho de Melo | bd3dda9 | 2018-01-15 11:33:53 -0300 | [diff] [blame] | 3438 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3439 | again: |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 3440 | before = trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3441 | |
| 3442 | for (i = 0; i < evlist->nr_mmaps; i++) { |
| 3443 | union perf_event *event; |
Kan Liang | d7f55c6 | 2018-03-01 18:08:59 -0500 | [diff] [blame] | 3444 | struct perf_mmap *md; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3445 | |
Kan Liang | d7f55c6 | 2018-03-01 18:08:59 -0500 | [diff] [blame] | 3446 | md = &evlist->mmap[i]; |
Kan Liang | b9bae2c | 2018-03-06 10:36:07 -0500 | [diff] [blame] | 3447 | if (perf_mmap__read_init(md) < 0) |
Kan Liang | d7f55c6 | 2018-03-01 18:08:59 -0500 | [diff] [blame] | 3448 | continue; |
| 3449 | |
Kan Liang | 0019dc87 | 2018-03-06 10:36:06 -0500 | [diff] [blame] | 3450 | while ((event = perf_mmap__read_event(md)) != NULL) { |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 3451 | ++trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3452 | |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3453 | err = trace__deliver_event(trace, event); |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3454 | if (err) |
| 3455 | goto out_disable; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3456 | |
Kan Liang | d6ace3d | 2018-03-06 10:36:05 -0500 | [diff] [blame] | 3457 | perf_mmap__consume(md); |
Arnaldo Carvalho de Melo | 20c5f10 | 2013-09-03 11:55:07 -0300 | [diff] [blame] | 3458 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 3459 | if (interrupted) |
| 3460 | goto out_disable; |
Arnaldo Carvalho de Melo | 02ac542 | 2015-04-22 11:11:57 -0300 | [diff] [blame] | 3461 | |
| 3462 | if (done && !draining) { |
Jiri Olsa | e74676d | 2019-07-21 13:24:09 +0200 | [diff] [blame] | 3463 | evlist__disable(evlist); |
Arnaldo Carvalho de Melo | 02ac542 | 2015-04-22 11:11:57 -0300 | [diff] [blame] | 3464 | draining = true; |
| 3465 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3466 | } |
Kan Liang | d7f55c6 | 2018-03-01 18:08:59 -0500 | [diff] [blame] | 3467 | perf_mmap__read_done(md); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3468 | } |
| 3469 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 3470 | if (trace->nr_events == before) { |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 3471 | int timeout = done ? 100 : -1; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3472 | |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 3473 | if (!draining && perf_evlist__poll(evlist, timeout) > 0) { |
Arnaldo Carvalho de Melo | a9c5e6c | 2018-10-22 14:14:16 -0300 | [diff] [blame] | 3474 | if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0) |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 3475 | draining = true; |
| 3476 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 3477 | goto again; |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3478 | } else { |
Arnaldo Carvalho de Melo | 7ba6152 | 2018-12-10 16:09:51 -0300 | [diff] [blame] | 3479 | if (trace__flush_events(trace)) |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3480 | goto out_disable; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 3481 | } |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 3482 | } else { |
| 3483 | goto again; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 3484 | } |
| 3485 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 3486 | out_disable: |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 3487 | thread__zput(trace->current); |
| 3488 | |
Jiri Olsa | e74676d | 2019-07-21 13:24:09 +0200 | [diff] [blame] | 3489 | evlist__disable(evlist); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3490 | |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 3491 | if (trace->sort_events) |
| 3492 | ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL); |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 3493 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 3494 | if (!err) { |
| 3495 | if (trace->summary) |
| 3496 | trace__fprintf_thread_summary(trace, trace->output); |
| 3497 | |
| 3498 | if (trace->show_tool_stats) { |
| 3499 | fprintf(trace->output, "Stats:\n " |
| 3500 | " vfs_getname : %" PRIu64 "\n" |
| 3501 | " proc_getname: %" PRIu64 "\n", |
| 3502 | trace->stats.vfs_getname, |
| 3503 | trace->stats.proc_getname); |
| 3504 | } |
| 3505 | } |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3506 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3507 | out_delete_evlist: |
Andrei Vagin | 33974a4 | 2017-11-07 16:22:45 -0800 | [diff] [blame] | 3508 | trace__symbols__exit(trace); |
| 3509 | |
Jiri Olsa | c12995a | 2019-07-21 13:23:56 +0200 | [diff] [blame] | 3510 | evlist__delete(evlist); |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 3511 | cgroup__put(trace->cgroup); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3512 | trace->evlist = NULL; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 3513 | trace->live = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3514 | return err; |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 3515 | { |
| 3516 | char errbuf[BUFSIZ]; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 3517 | |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 3518 | out_error_sched_stat_runtime: |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 3519 | 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] | 3520 | goto out_error; |
| 3521 | |
Arnaldo Carvalho de Melo | 801c67b | 2015-01-22 10:52:55 -0300 | [diff] [blame] | 3522 | out_error_raw_syscalls: |
Jiri Olsa | 988bdb3 | 2015-09-02 09:56:35 +0200 | [diff] [blame] | 3523 | 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] | 3524 | goto out_error; |
| 3525 | |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 3526 | out_error_mmap: |
| 3527 | perf_evlist__strerror_mmap(evlist, errno, errbuf, sizeof(errbuf)); |
| 3528 | goto out_error; |
| 3529 | |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 3530 | out_error_open: |
| 3531 | perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); |
| 3532 | |
| 3533 | out_error: |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 3534 | fprintf(trace->output, "%s\n", errbuf); |
Ramkumar Ramachandra | 87f9186 | 2013-10-04 10:47:31 +0530 | [diff] [blame] | 3535 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 3536 | |
| 3537 | out_error_apply_filters: |
| 3538 | fprintf(trace->output, |
| 3539 | "Failed to set filter \"%s\" on event %s with %d (%s)\n", |
| 3540 | evsel->filter, perf_evsel__name(evsel), errno, |
Arnaldo Carvalho de Melo | c8b5f2c | 2016-07-06 11:56:20 -0300 | [diff] [blame] | 3541 | str_error_r(errno, errbuf, sizeof(errbuf))); |
Arnaldo Carvalho de Melo | 94ad89b | 2015-07-03 17:42:03 -0300 | [diff] [blame] | 3542 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3543 | } |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 3544 | out_error_mem: |
| 3545 | fprintf(trace->output, "Not enough memory to run!\n"); |
| 3546 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 19867b6 | 2015-07-04 12:44:59 -0300 | [diff] [blame] | 3547 | |
| 3548 | out_errno: |
| 3549 | fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno)); |
| 3550 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 3551 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 3552 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3553 | static int trace__replay(struct trace *trace) |
| 3554 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3555 | const struct evsel_str_handler handlers[] = { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 3556 | { "probe:vfs_getname", trace__vfs_getname, }, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3557 | }; |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3558 | struct perf_data data = { |
Jiri Olsa | 2d4f279 | 2019-02-21 10:41:30 +0100 | [diff] [blame] | 3559 | .path = input_name, |
| 3560 | .mode = PERF_DATA_MODE_READ, |
| 3561 | .force = trace->force, |
Jiri Olsa | f5fc1412 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 3562 | }; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3563 | struct perf_session *session; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3564 | struct evsel *evsel; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3565 | int err = -1; |
| 3566 | |
| 3567 | trace->tool.sample = trace__process_sample; |
| 3568 | trace->tool.mmap = perf_event__process_mmap; |
David Ahern | 384c671 | 2013-09-22 19:44:58 -0600 | [diff] [blame] | 3569 | trace->tool.mmap2 = perf_event__process_mmap2; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3570 | trace->tool.comm = perf_event__process_comm; |
| 3571 | trace->tool.exit = perf_event__process_exit; |
| 3572 | trace->tool.fork = perf_event__process_fork; |
| 3573 | trace->tool.attr = perf_event__process_attr; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 3574 | trace->tool.tracing_data = perf_event__process_tracing_data; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3575 | trace->tool.build_id = perf_event__process_build_id; |
Hari Bathini | f3b3614 | 2017-03-08 02:11:43 +0530 | [diff] [blame] | 3576 | trace->tool.namespaces = perf_event__process_namespaces; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3577 | |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 3578 | trace->tool.ordered_events = true; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3579 | trace->tool.ordering_requires_timestamps = true; |
| 3580 | |
| 3581 | /* add tid to output */ |
| 3582 | trace->multiple_threads = true; |
| 3583 | |
Jiri Olsa | 8ceb41d | 2017-01-23 22:07:59 +0100 | [diff] [blame] | 3584 | session = perf_session__new(&data, false, &trace->tool); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3585 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 3586 | return -1; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3587 | |
David Ahern | aa07df6 | 2016-11-25 09:29:52 -0700 | [diff] [blame] | 3588 | if (trace->opts.target.pid) |
| 3589 | symbol_conf.pid_list_str = strdup(trace->opts.target.pid); |
| 3590 | |
| 3591 | if (trace->opts.target.tid) |
| 3592 | symbol_conf.tid_list_str = strdup(trace->opts.target.tid); |
| 3593 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 3594 | if (symbol__init(&session->header.env) < 0) |
Namhyung Kim | cb2ffae | 2014-08-12 15:40:44 +0900 | [diff] [blame] | 3595 | goto out; |
| 3596 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 3597 | trace->host = &session->machines.host; |
| 3598 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3599 | err = perf_session__set_tracepoints_handlers(session, handlers); |
| 3600 | if (err) |
| 3601 | goto out; |
| 3602 | |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3603 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3604 | "raw_syscalls:sys_enter"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 3605 | /* older kernels have syscalls tp versus raw_syscalls */ |
| 3606 | if (evsel == NULL) |
| 3607 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3608 | "syscalls:sys_enter"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3609 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3610 | if (evsel && |
Arnaldo Carvalho de Melo | 63f11c8 | 2018-08-02 14:27:09 -0300 | [diff] [blame] | 3611 | (perf_evsel__init_raw_syscall_tp(evsel, trace__sys_enter) < 0 || |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3612 | perf_evsel__init_sc_tp_ptr_field(evsel, args))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3613 | pr_err("Error during initialize raw_syscalls:sys_enter event\n"); |
| 3614 | goto out; |
| 3615 | } |
| 3616 | |
| 3617 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3618 | "raw_syscalls:sys_exit"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 3619 | if (evsel == NULL) |
| 3620 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 3621 | "syscalls:sys_exit"); |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3622 | if (evsel && |
Arnaldo Carvalho de Melo | 63f11c8 | 2018-08-02 14:27:09 -0300 | [diff] [blame] | 3623 | (perf_evsel__init_raw_syscall_tp(evsel, trace__sys_exit) < 0 || |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 3624 | perf_evsel__init_sc_tp_uint_field(evsel, ret))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 3625 | pr_err("Error during initialize raw_syscalls:sys_exit event\n"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3626 | goto out; |
| 3627 | } |
| 3628 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3629 | evlist__for_each_entry(session->evlist, evsel) { |
Jiri Olsa | 1fc632c | 2019-07-21 13:24:29 +0200 | [diff] [blame] | 3630 | if (evsel->core.attr.type == PERF_TYPE_SOFTWARE && |
| 3631 | (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ || |
| 3632 | evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MIN || |
| 3633 | evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS)) |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 3634 | evsel->handler = trace__pgfault; |
| 3635 | } |
| 3636 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3637 | setup_pager(); |
| 3638 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 3639 | err = perf_session__process_events(session); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3640 | if (err) |
| 3641 | pr_err("Failed to process events, error %d", err); |
| 3642 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3643 | else if (trace->summary) |
| 3644 | trace__fprintf_thread_summary(trace, trace->output); |
| 3645 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 3646 | out: |
| 3647 | perf_session__delete(session); |
| 3648 | |
| 3649 | return err; |
| 3650 | } |
| 3651 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3652 | static size_t trace__fprintf_threads_header(FILE *fp) |
| 3653 | { |
| 3654 | size_t printed; |
| 3655 | |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3656 | printed = fprintf(fp, "\n Summary of events:\n\n"); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3657 | |
| 3658 | return printed; |
| 3659 | } |
| 3660 | |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3661 | DEFINE_RESORT_RB(syscall_stats, a->msecs > b->msecs, |
| 3662 | struct stats *stats; |
| 3663 | double msecs; |
| 3664 | int syscall; |
| 3665 | ) |
| 3666 | { |
| 3667 | struct int_node *source = rb_entry(nd, struct int_node, rb_node); |
| 3668 | struct stats *stats = source->priv; |
| 3669 | |
| 3670 | entry->syscall = source->i; |
| 3671 | entry->stats = stats; |
| 3672 | entry->msecs = stats ? (u64)stats->n * (avg_stats(stats) / NSEC_PER_MSEC) : 0; |
| 3673 | } |
| 3674 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3675 | static size_t thread__dump_stats(struct thread_trace *ttrace, |
| 3676 | struct trace *trace, FILE *fp) |
| 3677 | { |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3678 | size_t printed = 0; |
| 3679 | struct syscall *sc; |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3680 | struct rb_node *nd; |
| 3681 | DECLARE_RESORT_RB_INTLIST(syscall_stats, ttrace->syscall_stats); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3682 | |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3683 | if (syscall_stats == NULL) |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3684 | return 0; |
| 3685 | |
| 3686 | printed += fprintf(fp, "\n"); |
| 3687 | |
Milian Wolff | 834fd46 | 2015-08-06 11:24:29 +0200 | [diff] [blame] | 3688 | printed += fprintf(fp, " syscall calls total min avg max stddev\n"); |
| 3689 | printed += fprintf(fp, " (msec) (msec) (msec) (msec) (%%)\n"); |
| 3690 | printed += fprintf(fp, " --------------- -------- --------- --------- --------- --------- ------\n"); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3691 | |
Arnaldo Carvalho de Melo | 98a9183 | 2016-06-23 11:34:10 -0300 | [diff] [blame] | 3692 | resort_rb__for_each_entry(nd, syscall_stats) { |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3693 | struct stats *stats = syscall_stats_entry->stats; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3694 | if (stats) { |
| 3695 | double min = (double)(stats->min) / NSEC_PER_MSEC; |
| 3696 | double max = (double)(stats->max) / NSEC_PER_MSEC; |
| 3697 | double avg = avg_stats(stats); |
| 3698 | double pct; |
| 3699 | u64 n = (u64) stats->n; |
| 3700 | |
| 3701 | pct = avg ? 100.0 * stddev_stats(stats)/avg : 0.0; |
| 3702 | avg /= NSEC_PER_MSEC; |
| 3703 | |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3704 | sc = &trace->syscalls.table[syscall_stats_entry->syscall]; |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3705 | printed += fprintf(fp, " %-15s", sc->name); |
Milian Wolff | 834fd46 | 2015-08-06 11:24:29 +0200 | [diff] [blame] | 3706 | printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f %9.3f", |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3707 | n, syscall_stats_entry->msecs, min, avg); |
Pekka Enberg | 27a778b | 2013-11-13 14:21:48 +0200 | [diff] [blame] | 3708 | printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3709 | } |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3710 | } |
| 3711 | |
Arnaldo Carvalho de Melo | b535d52 | 2016-05-04 16:06:26 -0300 | [diff] [blame] | 3712 | resort_rb__delete(syscall_stats); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3713 | printed += fprintf(fp, "\n\n"); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3714 | |
| 3715 | return printed; |
| 3716 | } |
| 3717 | |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3718 | static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace) |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3719 | { |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3720 | size_t printed = 0; |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 3721 | struct thread_trace *ttrace = thread__priv(thread); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3722 | double ratio; |
| 3723 | |
| 3724 | if (ttrace == NULL) |
| 3725 | return 0; |
| 3726 | |
| 3727 | ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; |
| 3728 | |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 3729 | printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 3730 | printed += fprintf(fp, "%lu events, ", ttrace->nr_events); |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 3731 | printed += fprintf(fp, "%.1f%%", ratio); |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 3732 | if (ttrace->pfmaj) |
| 3733 | printed += fprintf(fp, ", %lu majfaults", ttrace->pfmaj); |
| 3734 | if (ttrace->pfmin) |
| 3735 | printed += fprintf(fp, ", %lu minfaults", ttrace->pfmin); |
Arnaldo Carvalho de Melo | 03548eb | 2016-05-05 15:46:50 -0300 | [diff] [blame] | 3736 | if (trace->sched) |
| 3737 | printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms); |
| 3738 | else if (fputc('\n', fp) != EOF) |
| 3739 | ++printed; |
| 3740 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 3741 | printed += thread__dump_stats(ttrace, trace, fp); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3742 | |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3743 | return printed; |
| 3744 | } |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3745 | |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3746 | static unsigned long thread__nr_events(struct thread_trace *ttrace) |
| 3747 | { |
| 3748 | return ttrace ? ttrace->nr_events : 0; |
| 3749 | } |
| 3750 | |
| 3751 | DEFINE_RESORT_RB(threads, (thread__nr_events(a->thread->priv) < thread__nr_events(b->thread->priv)), |
| 3752 | struct thread *thread; |
| 3753 | ) |
| 3754 | { |
| 3755 | entry->thread = rb_entry(nd, struct thread, rb_node); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 3756 | } |
| 3757 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3758 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) |
| 3759 | { |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3760 | size_t printed = trace__fprintf_threads_header(fp); |
| 3761 | struct rb_node *nd; |
Kan Liang | 91e467b | 2017-09-10 19:23:14 -0700 | [diff] [blame] | 3762 | int i; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3763 | |
Kan Liang | 91e467b | 2017-09-10 19:23:14 -0700 | [diff] [blame] | 3764 | for (i = 0; i < THREADS__TABLE_SIZE; i++) { |
| 3765 | DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i); |
| 3766 | |
| 3767 | if (threads == NULL) { |
| 3768 | fprintf(fp, "%s", "Error sorting output by nr_events!\n"); |
| 3769 | return 0; |
| 3770 | } |
| 3771 | |
| 3772 | resort_rb__for_each_entry(nd, threads) |
| 3773 | printed += trace__fprintf_thread(fp, threads_entry->thread, trace); |
| 3774 | |
| 3775 | resort_rb__delete(threads); |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3776 | } |
Arnaldo Carvalho de Melo | 96c1445 | 2016-05-04 12:47:16 -0300 | [diff] [blame] | 3777 | return printed; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 3778 | } |
| 3779 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 3780 | static int trace__set_duration(const struct option *opt, const char *str, |
| 3781 | int unset __maybe_unused) |
| 3782 | { |
| 3783 | struct trace *trace = opt->value; |
| 3784 | |
| 3785 | trace->duration_filter = atof(str); |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
Arnaldo Carvalho de Melo | 6a0b3ab | 2018-11-07 09:38:49 -0300 | [diff] [blame] | 3789 | static int trace__set_filter_pids_from_option(const struct option *opt, const char *str, |
| 3790 | int unset __maybe_unused) |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 3791 | { |
| 3792 | int ret = -1; |
| 3793 | size_t i; |
| 3794 | struct trace *trace = opt->value; |
| 3795 | /* |
| 3796 | * FIXME: introduce a intarray class, plain parse csv and create a |
| 3797 | * { int nr, int entries[] } struct... |
| 3798 | */ |
| 3799 | struct intlist *list = intlist__new(str); |
| 3800 | |
| 3801 | if (list == NULL) |
| 3802 | return -1; |
| 3803 | |
| 3804 | i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; |
| 3805 | trace->filter_pids.entries = calloc(i, sizeof(pid_t)); |
| 3806 | |
| 3807 | if (trace->filter_pids.entries == NULL) |
| 3808 | goto out; |
| 3809 | |
| 3810 | trace->filter_pids.entries[0] = getpid(); |
| 3811 | |
| 3812 | for (i = 1; i < trace->filter_pids.nr; ++i) |
| 3813 | trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; |
| 3814 | |
| 3815 | intlist__delete(list); |
| 3816 | ret = 0; |
| 3817 | out: |
| 3818 | return ret; |
| 3819 | } |
| 3820 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 3821 | static int trace__open_output(struct trace *trace, const char *filename) |
| 3822 | { |
| 3823 | struct stat st; |
| 3824 | |
| 3825 | if (!stat(filename, &st) && st.st_size) { |
| 3826 | char oldname[PATH_MAX]; |
| 3827 | |
| 3828 | scnprintf(oldname, sizeof(oldname), "%s.old", filename); |
| 3829 | unlink(oldname); |
| 3830 | rename(filename, oldname); |
| 3831 | } |
| 3832 | |
| 3833 | trace->output = fopen(filename, "w"); |
| 3834 | |
| 3835 | return trace->output == NULL ? -errno : 0; |
| 3836 | } |
| 3837 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 3838 | static int parse_pagefaults(const struct option *opt, const char *str, |
| 3839 | int unset __maybe_unused) |
| 3840 | { |
| 3841 | int *trace_pgfaults = opt->value; |
| 3842 | |
| 3843 | if (strcmp(str, "all") == 0) |
| 3844 | *trace_pgfaults |= TRACE_PFMAJ | TRACE_PFMIN; |
| 3845 | else if (strcmp(str, "maj") == 0) |
| 3846 | *trace_pgfaults |= TRACE_PFMAJ; |
| 3847 | else if (strcmp(str, "min") == 0) |
| 3848 | *trace_pgfaults |= TRACE_PFMIN; |
| 3849 | else |
| 3850 | return -1; |
| 3851 | |
| 3852 | return 0; |
| 3853 | } |
| 3854 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3855 | static void evlist__set_evsel_handler(struct evlist *evlist, void *handler) |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3856 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3857 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3858 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 3859 | evlist__for_each_entry(evlist, evsel) |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 3860 | evsel->handler = handler; |
| 3861 | } |
| 3862 | |
Jiri Olsa | 63503db | 2019-07-21 13:23:52 +0200 | [diff] [blame] | 3863 | static int evlist__set_syscall_tp_fields(struct evlist *evlist) |
Arnaldo Carvalho de Melo | d32855f | 2018-08-02 15:09:24 -0300 | [diff] [blame] | 3864 | { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 3865 | struct evsel *evsel; |
Arnaldo Carvalho de Melo | d32855f | 2018-08-02 15:09:24 -0300 | [diff] [blame] | 3866 | |
| 3867 | evlist__for_each_entry(evlist, evsel) { |
| 3868 | if (evsel->priv || !evsel->tp_format) |
| 3869 | continue; |
| 3870 | |
| 3871 | if (strcmp(evsel->tp_format->system, "syscalls")) |
| 3872 | continue; |
| 3873 | |
| 3874 | if (perf_evsel__init_syscall_tp(evsel)) |
| 3875 | return -1; |
| 3876 | |
| 3877 | if (!strncmp(evsel->tp_format->name, "sys_enter_", 10)) { |
| 3878 | struct syscall_tp *sc = evsel->priv; |
| 3879 | |
| 3880 | if (__tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64))) |
| 3881 | return -1; |
| 3882 | } else if (!strncmp(evsel->tp_format->name, "sys_exit_", 9)) { |
| 3883 | struct syscall_tp *sc = evsel->priv; |
| 3884 | |
| 3885 | if (__tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap)) |
| 3886 | return -1; |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | return 0; |
| 3891 | } |
| 3892 | |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3893 | /* |
| 3894 | * XXX: Hackish, just splitting the combined -e+--event (syscalls |
| 3895 | * (raw_syscalls:{sys_{enter,exit}} + events (tracepoints, HW, SW, etc) to use |
| 3896 | * existing facilities unchanged (trace->ev_qualifier + parse_options()). |
| 3897 | * |
| 3898 | * It'd be better to introduce a parse_options() variant that would return a |
| 3899 | * list with the terms it didn't match to an event... |
| 3900 | */ |
| 3901 | static int trace__parse_events_option(const struct option *opt, const char *str, |
| 3902 | int unset __maybe_unused) |
| 3903 | { |
| 3904 | struct trace *trace = (struct trace *)opt->value; |
| 3905 | const char *s = str; |
| 3906 | char *sep = NULL, *lists[2] = { NULL, NULL, }; |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 3907 | int len = strlen(str) + 1, err = -1, list, idx; |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3908 | char *strace_groups_dir = system_path(STRACE_GROUPS_DIR); |
| 3909 | char group_name[PATH_MAX]; |
Arnaldo Carvalho de Melo | f932184 | 2018-10-25 17:24:45 -0300 | [diff] [blame] | 3910 | struct syscall_fmt *fmt; |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3911 | |
| 3912 | if (strace_groups_dir == NULL) |
| 3913 | return -1; |
| 3914 | |
| 3915 | if (*s == '!') { |
| 3916 | ++s; |
| 3917 | trace->not_ev_qualifier = true; |
| 3918 | } |
| 3919 | |
| 3920 | while (1) { |
| 3921 | if ((sep = strchr(s, ',')) != NULL) |
| 3922 | *sep = '\0'; |
| 3923 | |
| 3924 | list = 0; |
Arnaldo Carvalho de Melo | 27702bc | 2017-08-31 11:50:04 -0300 | [diff] [blame] | 3925 | if (syscalltbl__id(trace->sctbl, s) >= 0 || |
| 3926 | syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) { |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3927 | list = 1; |
Arnaldo Carvalho de Melo | f932184 | 2018-10-25 17:24:45 -0300 | [diff] [blame] | 3928 | goto do_concat; |
| 3929 | } |
| 3930 | |
| 3931 | fmt = syscall_fmt__find_by_alias(s); |
| 3932 | if (fmt != NULL) { |
| 3933 | list = 1; |
| 3934 | s = fmt->name; |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3935 | } else { |
| 3936 | path__join(group_name, sizeof(group_name), strace_groups_dir, s); |
| 3937 | if (access(group_name, R_OK) == 0) |
| 3938 | list = 1; |
| 3939 | } |
Arnaldo Carvalho de Melo | f932184 | 2018-10-25 17:24:45 -0300 | [diff] [blame] | 3940 | do_concat: |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3941 | if (lists[list]) { |
| 3942 | sprintf(lists[list] + strlen(lists[list]), ",%s", s); |
| 3943 | } else { |
| 3944 | lists[list] = malloc(len); |
| 3945 | if (lists[list] == NULL) |
| 3946 | goto out; |
| 3947 | strcpy(lists[list], s); |
| 3948 | } |
| 3949 | |
| 3950 | if (!sep) |
| 3951 | break; |
| 3952 | |
| 3953 | *sep = ','; |
| 3954 | s = sep + 1; |
| 3955 | } |
| 3956 | |
| 3957 | if (lists[1] != NULL) { |
| 3958 | struct strlist_config slist_config = { |
| 3959 | .dirname = strace_groups_dir, |
| 3960 | }; |
| 3961 | |
| 3962 | trace->ev_qualifier = strlist__new(lists[1], &slist_config); |
| 3963 | if (trace->ev_qualifier == NULL) { |
| 3964 | fputs("Not enough memory to parse event qualifier", trace->output); |
| 3965 | goto out; |
| 3966 | } |
| 3967 | |
| 3968 | if (trace__validate_ev_qualifier(trace)) |
| 3969 | goto out; |
Arnaldo Carvalho de Melo | b912885 | 2018-08-01 16:20:28 -0300 | [diff] [blame] | 3970 | trace->trace_syscalls = true; |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | err = 0; |
| 3974 | |
| 3975 | if (lists[0]) { |
| 3976 | struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event", |
| 3977 | "event selector. use 'perf list' to list available events", |
| 3978 | parse_events_option); |
| 3979 | err = parse_events_option(&o, lists[0], 0); |
| 3980 | } |
| 3981 | out: |
| 3982 | if (sep) |
| 3983 | *sep = ','; |
| 3984 | |
| 3985 | return err; |
| 3986 | } |
| 3987 | |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 3988 | static int trace__parse_cgroups(const struct option *opt, const char *str, int unset) |
| 3989 | { |
| 3990 | struct trace *trace = opt->value; |
| 3991 | |
Jiri Olsa | ce9036a | 2019-07-21 13:24:23 +0200 | [diff] [blame] | 3992 | if (!list_empty(&trace->evlist->core.entries)) |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 3993 | return parse_cgroups(opt, str, unset); |
| 3994 | |
| 3995 | trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); |
| 3996 | |
| 3997 | return 0; |
| 3998 | } |
| 3999 | |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4000 | static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace, const char *name) |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4001 | { |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4002 | if (trace->bpf_obj == NULL) |
| 4003 | return NULL; |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4004 | |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4005 | return bpf_object__find_map_by_name(trace->bpf_obj, name); |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | static void trace__set_bpf_map_filtered_pids(struct trace *trace) |
| 4009 | { |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4010 | trace->filter_pids.map = trace__find_bpf_map_by_name(trace, "pids_filtered"); |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4011 | } |
| 4012 | |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 4013 | static void trace__set_bpf_map_syscalls(struct trace *trace) |
| 4014 | { |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4015 | trace->syscalls.map = trace__find_bpf_map_by_name(trace, "syscalls"); |
Arnaldo Carvalho de Melo | 3803a22 | 2019-07-16 11:27:03 -0300 | [diff] [blame] | 4016 | trace->syscalls.prog_array.sys_enter = trace__find_bpf_map_by_name(trace, "syscalls_sys_enter"); |
| 4017 | trace->syscalls.prog_array.sys_exit = trace__find_bpf_map_by_name(trace, "syscalls_sys_exit"); |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 4018 | } |
| 4019 | |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4020 | static int trace__config(const char *var, const char *value, void *arg) |
| 4021 | { |
Arnaldo Carvalho de Melo | e7c634f | 2018-12-14 10:12:09 -0300 | [diff] [blame] | 4022 | struct trace *trace = arg; |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4023 | int err = 0; |
| 4024 | |
| 4025 | if (!strcmp(var, "trace.add_events")) { |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4026 | struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event", |
| 4027 | "event selector. use 'perf list' to list available events", |
| 4028 | parse_events_option); |
Leo Yan | 012749ca | 2019-06-06 10:38:59 -0300 | [diff] [blame] | 4029 | /* |
| 4030 | * We can't propagate parse_event_option() return, as it is 1 |
| 4031 | * for failure while perf_config() expects -1. |
| 4032 | */ |
| 4033 | if (parse_events_option(&o, value, 0)) |
| 4034 | err = -1; |
Arnaldo Carvalho de Melo | b036146 | 2018-12-14 11:17:19 -0300 | [diff] [blame] | 4035 | } else if (!strcmp(var, "trace.show_timestamp")) { |
| 4036 | trace->show_tstamp = perf_config_bool(var, value); |
Arnaldo Carvalho de Melo | 42e4a52 | 2018-12-14 10:22:18 -0300 | [diff] [blame] | 4037 | } else if (!strcmp(var, "trace.show_duration")) { |
| 4038 | trace->show_duration = perf_config_bool(var, value); |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 4039 | } else if (!strcmp(var, "trace.show_arg_names")) { |
| 4040 | trace->show_arg_names = perf_config_bool(var, value); |
| 4041 | if (!trace->show_arg_names) |
| 4042 | trace->show_zeros = true; |
Arnaldo Carvalho de Melo | e7c634f | 2018-12-14 10:12:09 -0300 | [diff] [blame] | 4043 | } else if (!strcmp(var, "trace.show_zeros")) { |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 4044 | bool new_show_zeros = perf_config_bool(var, value); |
| 4045 | if (!trace->show_arg_names && !new_show_zeros) { |
| 4046 | pr_warning("trace.show_zeros has to be set when trace.show_arg_names=no\n"); |
| 4047 | goto out; |
| 4048 | } |
| 4049 | trace->show_zeros = new_show_zeros; |
Arnaldo Carvalho de Melo | c65c83f | 2018-12-14 17:06:47 -0300 | [diff] [blame] | 4050 | } else if (!strcmp(var, "trace.show_prefix")) { |
| 4051 | trace->show_string_prefix = perf_config_bool(var, value); |
Arnaldo Carvalho de Melo | d32de87 | 2018-12-14 11:06:16 -0300 | [diff] [blame] | 4052 | } else if (!strcmp(var, "trace.no_inherit")) { |
| 4053 | trace->opts.no_inherit = perf_config_bool(var, value); |
Arnaldo Carvalho de Melo | 9ed45d5 | 2018-12-14 13:40:49 -0300 | [diff] [blame] | 4054 | } else if (!strcmp(var, "trace.args_alignment")) { |
| 4055 | int args_alignment = 0; |
| 4056 | if (perf_config_int(&args_alignment, var, value) == 0) |
| 4057 | trace->args_alignment = args_alignment; |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4058 | } |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 4059 | out: |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4060 | return err; |
| 4061 | } |
| 4062 | |
Arnaldo Carvalho de Melo | b0ad8ea | 2017-03-27 11:47:20 -0300 | [diff] [blame] | 4063 | int cmd_trace(int argc, const char **argv) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4064 | { |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 4065 | const char *trace_usage[] = { |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 4066 | "perf trace [<options>] [<command>]", |
| 4067 | "perf trace [<options>] -- <command> [<options>]", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 4068 | "perf trace record [<options>] [<command>]", |
| 4069 | "perf trace record [<options>] -- <command> [<options>]", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4070 | NULL |
| 4071 | }; |
| 4072 | struct trace trace = { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4073 | .opts = { |
| 4074 | .target = { |
| 4075 | .uid = UINT_MAX, |
| 4076 | .uses_mmap = true, |
| 4077 | }, |
| 4078 | .user_freq = UINT_MAX, |
| 4079 | .user_interval = ULLONG_MAX, |
Arnaldo Carvalho de Melo | 509051e | 2014-01-14 17:52:14 -0300 | [diff] [blame] | 4080 | .no_buffering = true, |
Arnaldo Carvalho de Melo | 38d5447 | 2014-12-12 17:28:32 -0300 | [diff] [blame] | 4081 | .mmap_pages = UINT_MAX, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4082 | }, |
Milian Wolff | 007d66a | 2015-08-05 16:52:23 -0300 | [diff] [blame] | 4083 | .output = stderr, |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 4084 | .show_comm = true, |
Arnaldo Carvalho de Melo | b036146 | 2018-12-14 11:17:19 -0300 | [diff] [blame] | 4085 | .show_tstamp = true, |
Arnaldo Carvalho de Melo | 42e4a52 | 2018-12-14 10:22:18 -0300 | [diff] [blame] | 4086 | .show_duration = true, |
Arnaldo Carvalho de Melo | 9d6dc17 | 2018-12-14 11:32:02 -0300 | [diff] [blame] | 4087 | .show_arg_names = true, |
Arnaldo Carvalho de Melo | 9ed45d5 | 2018-12-14 13:40:49 -0300 | [diff] [blame] | 4088 | .args_alignment = 70, |
Arnaldo Carvalho de Melo | b912885 | 2018-08-01 16:20:28 -0300 | [diff] [blame] | 4089 | .trace_syscalls = false, |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 4090 | .kernel_syscallchains = false, |
Arnaldo Carvalho de Melo | 0561499 | 2016-04-15 16:41:19 -0300 | [diff] [blame] | 4091 | .max_stack = UINT_MAX, |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 4092 | .max_events = ULONG_MAX, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4093 | }; |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 4094 | const char *map_dump_str = NULL; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4095 | const char *output_name = NULL; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4096 | const struct option trace_options[] = { |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 4097 | OPT_CALLBACK('e', "event", &trace, "event", |
| 4098 | "event/syscall selector. use 'perf list' to list available events", |
| 4099 | trace__parse_events_option), |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 4100 | OPT_BOOLEAN(0, "comm", &trace.show_comm, |
| 4101 | "show the thread COMM next to its id"), |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 4102 | OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), |
Arnaldo Carvalho de Melo | 017037f | 2017-01-09 17:26:26 -0300 | [diff] [blame] | 4103 | OPT_CALLBACK(0, "expr", &trace, "expr", "list of syscalls/events to trace", |
| 4104 | trace__parse_events_option), |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4105 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 4106 | 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] | 4107 | OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", |
| 4108 | "trace events on existing process id"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 4109 | OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4110 | "trace events on existing thread id"), |
Arnaldo Carvalho de Melo | fa0e4ff | 2015-04-23 11:59:20 -0300 | [diff] [blame] | 4111 | OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids", |
Arnaldo Carvalho de Melo | 6a0b3ab | 2018-11-07 09:38:49 -0300 | [diff] [blame] | 4112 | "pids to filter (by the kernel)", trace__set_filter_pids_from_option), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 4113 | OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4114 | "system-wide collection from all CPUs"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 4115 | OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4116 | "list of cpus to monitor"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 4117 | OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4118 | "child tasks do not inherit counters"), |
Jiri Olsa | 994a1f7 | 2013-09-01 12:36:12 +0200 | [diff] [blame] | 4119 | OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", |
| 4120 | "number of mmap data pages", |
| 4121 | perf_evlist__parse_mmap_pages), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 4122 | OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4123 | "user to profile"), |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 4124 | OPT_CALLBACK(0, "duration", &trace, "float", |
| 4125 | "show only events with duration > N.M ms", |
| 4126 | trace__set_duration), |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 4127 | #ifdef HAVE_LIBBPF_SUPPORT |
| 4128 | OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"), |
| 4129 | #endif |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 4130 | OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 4131 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
David Ahern | 4bb0919 | 2013-09-04 12:37:43 -0600 | [diff] [blame] | 4132 | OPT_BOOLEAN('T', "time", &trace.full_time, |
| 4133 | "Show full timestamp, not time relative to first start"), |
Arnaldo Carvalho de Melo | 0a6545b | 2018-03-29 12:22:59 -0300 | [diff] [blame] | 4134 | OPT_BOOLEAN(0, "failure", &trace.failure_only, |
| 4135 | "Show only syscalls that failed"), |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 4136 | OPT_BOOLEAN('s', "summary", &trace.summary_only, |
| 4137 | "Show only syscall summary with statistics"), |
| 4138 | OPT_BOOLEAN('S', "with-summary", &trace.summary, |
| 4139 | "Show all syscalls and summary with statistics"), |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 4140 | OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", |
| 4141 | "Trace pagefaults", parse_pagefaults, "maj"), |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 4142 | OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 4143 | OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 4144 | OPT_CALLBACK(0, "call-graph", &trace.opts, |
| 4145 | "record_mode[,record_size]", record_callchain_help, |
| 4146 | &record_parse_callchain_opt), |
Arnaldo Carvalho de Melo | 4462181 | 2016-04-11 15:49:11 -0300 | [diff] [blame] | 4147 | OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains, |
| 4148 | "Show the kernel callchains on the syscall exit path"), |
Arnaldo Carvalho de Melo | 5067a8c | 2018-10-18 16:38:27 -0300 | [diff] [blame] | 4149 | OPT_ULONG(0, "max-events", &trace.max_events, |
| 4150 | "Set the maximum number of events to print, exit after that is reached. "), |
Arnaldo Carvalho de Melo | 5cf9c84 | 2016-04-15 11:10:31 -0300 | [diff] [blame] | 4151 | OPT_UINTEGER(0, "min-stack", &trace.min_stack, |
| 4152 | "Set the minimum stack depth when parsing the callchain, " |
| 4153 | "anything below the specified depth will be ignored."), |
Arnaldo Carvalho de Melo | c6d4a49 | 2016-04-14 18:29:08 -0300 | [diff] [blame] | 4154 | OPT_UINTEGER(0, "max-stack", &trace.max_stack, |
| 4155 | "Set the maximum stack depth when parsing the callchain, " |
| 4156 | "anything beyond the specified depth will be ignored. " |
Arnaldo Carvalho de Melo | 4cb9344 | 2016-04-27 10:16:24 -0300 | [diff] [blame] | 4157 | "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)), |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 4158 | OPT_BOOLEAN(0, "sort-events", &trace.sort_events, |
| 4159 | "Sort batch of events before processing, use if getting out of order events"), |
Arnaldo Carvalho de Melo | 591421e | 2018-01-22 11:38:54 -0300 | [diff] [blame] | 4160 | OPT_BOOLEAN(0, "print-sample", &trace.print_sample, |
| 4161 | "print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info, for debugging"), |
Mark Drayton | 3fcb10e | 2018-12-04 12:34:20 -0800 | [diff] [blame] | 4162 | OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout, |
Kan Liang | 9d9cad7 | 2015-06-17 09:51:11 -0400 | [diff] [blame] | 4163 | "per thread proc mmap processing timeout in ms"), |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 4164 | OPT_CALLBACK('G', "cgroup", &trace, "name", "monitor event in cgroup name only", |
| 4165 | trace__parse_cgroups), |
Alexis Berlemont | e36b782 | 2016-10-10 07:43:28 +0200 | [diff] [blame] | 4166 | OPT_UINTEGER('D', "delay", &trace.opts.initial_delay, |
| 4167 | "ms to wait before starting measurement after program " |
| 4168 | "start"), |
Arnaldo Carvalho de Melo | 22ac431 | 2019-08-15 12:15:39 -0300 | [diff] [blame] | 4169 | OPTS_EVSWITCH(&trace.evswitch), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4170 | OPT_END() |
| 4171 | }; |
Arnaldo Carvalho de Melo | ccd62a8 | 2016-04-16 09:36:32 -0300 | [diff] [blame] | 4172 | bool __maybe_unused max_stack_user_set = true; |
Arnaldo Carvalho de Melo | f3e459d | 2016-04-15 17:52:34 -0300 | [diff] [blame] | 4173 | bool mmap_pages_user_set = true; |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 4174 | struct evsel *evsel; |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 4175 | const char * const trace_subcommands[] = { "record", NULL }; |
Arnaldo Carvalho de Melo | 78e890e | 2018-08-07 16:19:05 -0300 | [diff] [blame] | 4176 | int err = -1; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 4177 | char bf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4178 | |
Arnaldo Carvalho de Melo | 4d08cb8 | 2015-02-24 15:35:55 -0300 | [diff] [blame] | 4179 | signal(SIGSEGV, sighandler_dump_stack); |
| 4180 | signal(SIGFPE, sighandler_dump_stack); |
| 4181 | |
Jiri Olsa | 0f98b11 | 2019-07-21 13:23:55 +0200 | [diff] [blame] | 4182 | trace.evlist = evlist__new(); |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 4183 | trace.sctbl = syscalltbl__new(); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 4184 | |
Arnaldo Carvalho de Melo | fd0db10 | 2016-04-04 13:32:20 -0300 | [diff] [blame] | 4185 | if (trace.evlist == NULL || trace.sctbl == NULL) { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 4186 | pr_err("Not enough memory to run!\n"); |
He Kuang | ff8f695 | 2015-05-11 12:28:36 +0000 | [diff] [blame] | 4187 | err = -ENOMEM; |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 4188 | goto out; |
| 4189 | } |
| 4190 | |
Arnaldo Carvalho de Melo | c3e78a3 | 2019-07-09 16:36:45 -0300 | [diff] [blame] | 4191 | /* |
| 4192 | * Parsing .perfconfig may entail creating a BPF event, that may need |
| 4193 | * to create BPF maps, so bump RLIM_MEMLOCK as the default 64K setting |
| 4194 | * is too small. This affects just this process, not touching the |
| 4195 | * global setting. If it fails we'll get something in 'perf trace -v' |
| 4196 | * to help diagnose the problem. |
| 4197 | */ |
| 4198 | rlimit__bump_memlock(); |
| 4199 | |
Arnaldo Carvalho de Melo | ac96287 | 2018-12-13 17:30:20 -0300 | [diff] [blame] | 4200 | err = perf_config(trace__config, &trace); |
| 4201 | if (err) |
| 4202 | goto out; |
| 4203 | |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 4204 | argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands, |
| 4205 | trace_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 4206 | |
Arnaldo Carvalho de Melo | 9ea42ba | 2018-03-06 16:30:51 -0300 | [diff] [blame] | 4207 | if ((nr_cgroups || trace.cgroup) && !trace.opts.target.system_wide) { |
| 4208 | usage_with_options_msg(trace_usage, trace_options, |
| 4209 | "cgroup monitoring only available in system-wide mode"); |
| 4210 | } |
| 4211 | |
Arnaldo Carvalho de Melo | 78e890e | 2018-08-07 16:19:05 -0300 | [diff] [blame] | 4212 | evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__"); |
| 4213 | if (IS_ERR(evsel)) { |
| 4214 | bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | e0b6d2e | 2018-08-07 15:40:13 -0300 | [diff] [blame] | 4215 | pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf); |
| 4216 | goto out; |
| 4217 | } |
| 4218 | |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4219 | if (evsel) { |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 4220 | trace.syscalls.events.augmented = evsel; |
Arnaldo Carvalho de Melo | c8c8057 | 2019-07-15 16:58:23 -0300 | [diff] [blame] | 4221 | |
| 4222 | evsel = perf_evlist__find_tracepoint_by_name(trace.evlist, "raw_syscalls:sys_enter"); |
| 4223 | if (evsel == NULL) { |
| 4224 | pr_err("ERROR: raw_syscalls:sys_enter not found in the augmented BPF object\n"); |
| 4225 | goto out; |
| 4226 | } |
| 4227 | |
| 4228 | if (evsel->bpf_obj == NULL) { |
| 4229 | pr_err("ERROR: raw_syscalls:sys_enter not associated to a BPF object\n"); |
| 4230 | goto out; |
| 4231 | } |
| 4232 | |
| 4233 | trace.bpf_obj = evsel->bpf_obj; |
| 4234 | |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4235 | trace__set_bpf_map_filtered_pids(&trace); |
Arnaldo Carvalho de Melo | b27b38e | 2018-12-12 13:39:24 -0300 | [diff] [blame] | 4236 | trace__set_bpf_map_syscalls(&trace); |
Arnaldo Carvalho de Melo | 5834da7 | 2019-07-15 17:51:43 -0300 | [diff] [blame] | 4237 | trace.syscalls.unaugmented_prog = trace__find_bpf_program_by_title(&trace, "!raw_syscalls:unaugmented"); |
Arnaldo Carvalho de Melo | 744fafc | 2018-11-07 10:04:51 -0300 | [diff] [blame] | 4238 | } |
Arnaldo Carvalho de Melo | d3d1c4bdf5 | 2018-08-07 16:21:44 -0300 | [diff] [blame] | 4239 | |
Wang Nan | d788857 | 2016-04-08 15:07:24 +0000 | [diff] [blame] | 4240 | err = bpf__setup_stdout(trace.evlist); |
| 4241 | if (err) { |
| 4242 | bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf)); |
| 4243 | pr_err("ERROR: Setup BPF stdout failed: %s\n", bf); |
| 4244 | goto out; |
| 4245 | } |
| 4246 | |
Arnaldo Carvalho de Melo | 59247e3 | 2016-04-12 16:05:02 -0300 | [diff] [blame] | 4247 | err = -1; |
| 4248 | |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 4249 | if (map_dump_str) { |
Arnaldo Carvalho de Melo | 5ca0b7f | 2019-07-15 17:03:10 -0300 | [diff] [blame] | 4250 | trace.dump.map = trace__find_bpf_map_by_name(&trace, map_dump_str); |
Arnaldo Carvalho de Melo | ff7a4f9 | 2019-02-19 16:17:33 -0300 | [diff] [blame] | 4251 | if (trace.dump.map == NULL) { |
| 4252 | pr_err("ERROR: BPF map \"%s\" not found\n", map_dump_str); |
| 4253 | goto out; |
| 4254 | } |
| 4255 | } |
| 4256 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 4257 | if (trace.trace_pgfaults) { |
| 4258 | trace.opts.sample_address = true; |
| 4259 | trace.opts.sample_time = true; |
| 4260 | } |
| 4261 | |
Arnaldo Carvalho de Melo | f3e459d | 2016-04-15 17:52:34 -0300 | [diff] [blame] | 4262 | if (trace.opts.mmap_pages == UINT_MAX) |
| 4263 | mmap_pages_user_set = false; |
| 4264 | |
Arnaldo Carvalho de Melo | 0561499 | 2016-04-15 16:41:19 -0300 | [diff] [blame] | 4265 | if (trace.max_stack == UINT_MAX) { |
Arnaldo Carvalho de Melo | 029c75e | 2018-05-17 16:31:32 -0300 | [diff] [blame] | 4266 | trace.max_stack = input_name ? PERF_MAX_STACK_DEPTH : sysctl__max_stack(); |
Arnaldo Carvalho de Melo | 0561499 | 2016-04-15 16:41:19 -0300 | [diff] [blame] | 4267 | max_stack_user_set = false; |
| 4268 | } |
| 4269 | |
| 4270 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
Arnaldo Carvalho de Melo | 75d5011 | 2018-01-15 10:39:55 -0300 | [diff] [blame] | 4271 | if ((trace.min_stack || max_stack_user_set) && !callchain_param.enabled) { |
Arnaldo Carvalho de Melo | 0561499 | 2016-04-15 16:41:19 -0300 | [diff] [blame] | 4272 | record_opts__parse_callchain(&trace.opts, &callchain_param, "dwarf", false); |
Arnaldo Carvalho de Melo | 75d5011 | 2018-01-15 10:39:55 -0300 | [diff] [blame] | 4273 | } |
Arnaldo Carvalho de Melo | 0561499 | 2016-04-15 16:41:19 -0300 | [diff] [blame] | 4274 | #endif |
| 4275 | |
Arnaldo Carvalho de Melo | 2ddd5c0 | 2016-04-18 12:09:08 -0300 | [diff] [blame] | 4276 | if (callchain_param.enabled) { |
Arnaldo Carvalho de Melo | f3e459d | 2016-04-15 17:52:34 -0300 | [diff] [blame] | 4277 | if (!mmap_pages_user_set && geteuid() == 0) |
| 4278 | trace.opts.mmap_pages = perf_event_mlock_kb_in_pages() * 4; |
| 4279 | |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 4280 | symbol_conf.use_callchain = true; |
Arnaldo Carvalho de Melo | f3e459d | 2016-04-15 17:52:34 -0300 | [diff] [blame] | 4281 | } |
Milian Wolff | 566a088 | 2016-04-08 13:34:15 +0200 | [diff] [blame] | 4282 | |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 4283 | if (trace.evlist->core.nr_entries > 0) { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 4284 | evlist__set_evsel_handler(trace.evlist, trace__event_handler); |
Arnaldo Carvalho de Melo | d32855f | 2018-08-02 15:09:24 -0300 | [diff] [blame] | 4285 | if (evlist__set_syscall_tp_fields(trace.evlist)) { |
| 4286 | perror("failed to set syscalls:* tracepoint fields"); |
| 4287 | goto out; |
| 4288 | } |
| 4289 | } |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 4290 | |
Arnaldo Carvalho de Melo | a761a8d | 2018-12-10 16:27:33 -0300 | [diff] [blame] | 4291 | if (trace.sort_events) { |
| 4292 | ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace); |
| 4293 | ordered_events__set_copy_on_queue(&trace.oe.data, true); |
| 4294 | } |
Jiri Olsa | 028713a | 2018-12-05 17:05:09 +0100 | [diff] [blame] | 4295 | |
Arnaldo Carvalho de Melo | b1a9e25 | 2018-09-03 16:29:39 -0300 | [diff] [blame] | 4296 | /* |
| 4297 | * If we are augmenting syscalls, then combine what we put in the |
| 4298 | * __augmented_syscalls__ BPF map with what is in the |
| 4299 | * syscalls:sys_exit_FOO tracepoints, i.e. just like we do without BPF, |
| 4300 | * combining raw_syscalls:sys_enter with raw_syscalls:sys_exit. |
| 4301 | * |
| 4302 | * We'll switch to look at two BPF maps, one for sys_enter and the |
| 4303 | * other for sys_exit when we start augmenting the sys_exit paths with |
| 4304 | * buffers that are being copied from kernel to userspace, think 'read' |
| 4305 | * syscall. |
| 4306 | */ |
| 4307 | if (trace.syscalls.events.augmented) { |
Arnaldo Carvalho de Melo | b1a9e25 | 2018-09-03 16:29:39 -0300 | [diff] [blame] | 4308 | evlist__for_each_entry(trace.evlist, evsel) { |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 4309 | bool raw_syscalls_sys_exit = strcmp(perf_evsel__name(evsel), "raw_syscalls:sys_exit") == 0; |
| 4310 | |
| 4311 | if (raw_syscalls_sys_exit) { |
| 4312 | trace.raw_augmented_syscalls = true; |
| 4313 | goto init_augmented_syscall_tp; |
| 4314 | } |
| 4315 | |
Arnaldo Carvalho de Melo | 1d59cb1 | 2019-01-24 15:39:15 +0100 | [diff] [blame] | 4316 | if (trace.syscalls.events.augmented->priv == NULL && |
| 4317 | strstr(perf_evsel__name(evsel), "syscalls:sys_enter")) { |
Jiri Olsa | 32dcd02 | 2019-07-21 13:23:51 +0200 | [diff] [blame] | 4318 | struct evsel *augmented = trace.syscalls.events.augmented; |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 4319 | if (perf_evsel__init_augmented_syscall_tp(augmented, evsel) || |
| 4320 | perf_evsel__init_augmented_syscall_tp_args(augmented)) |
| 4321 | goto out; |
Arnaldo Carvalho de Melo | b119970 | 2019-07-16 11:53:03 -0300 | [diff] [blame] | 4322 | /* |
| 4323 | * Augmented is __augmented_syscalls__ BPF_OUTPUT event |
| 4324 | * Above we made sure we can get from the payload the tp fields |
| 4325 | * that we get from syscalls:sys_enter tracefs format file. |
| 4326 | */ |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 4327 | augmented->handler = trace__sys_enter; |
Arnaldo Carvalho de Melo | b119970 | 2019-07-16 11:53:03 -0300 | [diff] [blame] | 4328 | /* |
| 4329 | * Now we do the same for the *syscalls:sys_enter event so that |
| 4330 | * if we handle it directly, i.e. if the BPF prog returns 0 so |
| 4331 | * as not to filter it, then we'll handle it just like we would |
| 4332 | * for the BPF_OUTPUT one: |
| 4333 | */ |
| 4334 | if (perf_evsel__init_augmented_syscall_tp(evsel, evsel) || |
| 4335 | perf_evsel__init_augmented_syscall_tp_args(evsel)) |
| 4336 | goto out; |
| 4337 | evsel->handler = trace__sys_enter; |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 4338 | } |
| 4339 | |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 4340 | if (strstarts(perf_evsel__name(evsel), "syscalls:sys_exit_")) { |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 4341 | struct syscall_tp *sc; |
Arnaldo Carvalho de Melo | cd26ea6 | 2018-11-03 08:19:56 -0300 | [diff] [blame] | 4342 | init_augmented_syscall_tp: |
Arnaldo Carvalho de Melo | b9b6a2e | 2018-12-19 18:54:36 -0300 | [diff] [blame] | 4343 | if (perf_evsel__init_augmented_syscall_tp(evsel, evsel)) |
| 4344 | goto out; |
| 4345 | sc = evsel->priv; |
| 4346 | /* |
| 4347 | * For now with BPF raw_augmented we hook into |
| 4348 | * raw_syscalls:sys_enter and there we get all |
| 4349 | * 6 syscall args plus the tracepoint common |
| 4350 | * fields and the syscall_nr (another long). |
| 4351 | * So we check if that is the case and if so |
| 4352 | * don't look after the sc->args_size but |
| 4353 | * always after the full raw_syscalls:sys_enter |
| 4354 | * payload, which is fixed. |
| 4355 | * |
| 4356 | * We'll revisit this later to pass |
| 4357 | * s->args_size to the BPF augmenter (now |
| 4358 | * tools/perf/examples/bpf/augmented_raw_syscalls.c, |
| 4359 | * so that it copies only what we need for each |
| 4360 | * syscall, like what happens when we use |
| 4361 | * syscalls:sys_enter_NAME, so that we reduce |
| 4362 | * the kernel/userspace traffic to just what is |
| 4363 | * needed for each syscall. |
| 4364 | */ |
| 4365 | if (trace.raw_augmented_syscalls) |
| 4366 | trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset; |
Arnaldo Carvalho de Melo | b1a9e25 | 2018-09-03 16:29:39 -0300 | [diff] [blame] | 4367 | perf_evsel__init_augmented_syscall_tp_ret(evsel); |
| 4368 | evsel->handler = trace__sys_exit; |
| 4369 | } |
| 4370 | } |
| 4371 | } |
| 4372 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 4373 | if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) |
| 4374 | return trace__record(&trace, argc-1, &argv[1]); |
| 4375 | |
| 4376 | /* summary_only implies summary option, but don't overwrite summary if set */ |
| 4377 | if (trace.summary_only) |
| 4378 | trace.summary = trace.summary_only; |
| 4379 | |
Arnaldo Carvalho de Melo | 726f323 | 2015-02-06 10:16:45 +0100 | [diff] [blame] | 4380 | if (!trace.trace_syscalls && !trace.trace_pgfaults && |
Jiri Olsa | 6484d2f | 2019-07-21 13:24:28 +0200 | [diff] [blame] | 4381 | trace.evlist->core.nr_entries == 0 /* Was --events used? */) { |
Arnaldo Carvalho de Melo | b912885 | 2018-08-01 16:20:28 -0300 | [diff] [blame] | 4382 | trace.trace_syscalls = true; |
Arnaldo Carvalho de Melo | 59247e3 | 2016-04-12 16:05:02 -0300 | [diff] [blame] | 4383 | } |
| 4384 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4385 | if (output_name != NULL) { |
| 4386 | err = trace__open_output(&trace, output_name); |
| 4387 | if (err < 0) { |
| 4388 | perror("failed to create output file"); |
| 4389 | goto out; |
| 4390 | } |
| 4391 | } |
| 4392 | |
Arnaldo Carvalho de Melo | 22ac431 | 2019-08-15 12:15:39 -0300 | [diff] [blame] | 4393 | err = evswitch__init(&trace.evswitch, trace.evlist, stderr); |
| 4394 | if (err) |
| 4395 | goto out_close; |
| 4396 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 4397 | err = target__validate(&trace.opts.target); |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 4398 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 4399 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4400 | fprintf(trace.output, "%s", bf); |
| 4401 | goto out_close; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 4402 | } |
| 4403 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 4404 | err = target__parse_uid(&trace.opts.target); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4405 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 4406 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4407 | fprintf(trace.output, "%s", bf); |
| 4408 | goto out_close; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4409 | } |
| 4410 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 4411 | if (!argc && target__none(&trace.opts.target)) |
Namhyung Kim | ee76120 | 2012-10-05 14:02:14 +0900 | [diff] [blame] | 4412 | trace.opts.target.system_wide = true; |
| 4413 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 4414 | if (input_name) |
| 4415 | err = trace__replay(&trace); |
| 4416 | else |
| 4417 | err = trace__run(&trace, argc, argv); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 4418 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 4419 | out_close: |
| 4420 | if (output_name != NULL) |
| 4421 | fclose(trace.output); |
| 4422 | out: |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 4423 | return err; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 4424 | } |