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