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