Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 1 | #include <traceevent/event-parse.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2 | #include "builtin.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 3 | #include "util/color.h" |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 4 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 5 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 6 | #include "util/machine.h" |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 7 | #include "util/session.h" |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 8 | #include "util/thread.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 9 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 10 | #include "util/strlist.h" |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 11 | #include "util/intlist.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 12 | #include "util/thread_map.h" |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 13 | #include "util/stat.h" |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 14 | #include "trace-event.h" |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 15 | #include "util/parse-events.h" |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 16 | |
| 17 | #include <libaudit.h> |
| 18 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | 49af9e9 | 2013-09-12 12:18:56 -0300 | [diff] [blame] | 19 | #include <sys/eventfd.h> |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 20 | #include <sys/mman.h> |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 21 | #include <linux/futex.h> |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 22 | |
Ingo Molnar | 456857b | 2013-09-12 15:29:00 +0200 | [diff] [blame] | 23 | /* For older distros: */ |
| 24 | #ifndef MAP_STACK |
| 25 | # define MAP_STACK 0x20000 |
| 26 | #endif |
| 27 | |
| 28 | #ifndef MADV_HWPOISON |
| 29 | # define MADV_HWPOISON 100 |
| 30 | #endif |
| 31 | |
| 32 | #ifndef MADV_MERGEABLE |
| 33 | # define MADV_MERGEABLE 12 |
| 34 | #endif |
| 35 | |
| 36 | #ifndef MADV_UNMERGEABLE |
| 37 | # define MADV_UNMERGEABLE 13 |
| 38 | #endif |
| 39 | |
Ben Hutchings | 79d26a6 | 2014-02-06 01:00:35 +0000 | [diff] [blame] | 40 | #ifndef EFD_SEMAPHORE |
| 41 | # define EFD_SEMAPHORE 1 |
| 42 | #endif |
| 43 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 44 | struct tp_field { |
| 45 | int offset; |
| 46 | union { |
| 47 | u64 (*integer)(struct tp_field *field, struct perf_sample *sample); |
| 48 | void *(*pointer)(struct tp_field *field, struct perf_sample *sample); |
| 49 | }; |
| 50 | }; |
| 51 | |
| 52 | #define TP_UINT_FIELD(bits) \ |
| 53 | static u64 tp_field__u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 54 | { \ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 55 | u##bits value; \ |
| 56 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
| 57 | return value; \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | TP_UINT_FIELD(8); |
| 61 | TP_UINT_FIELD(16); |
| 62 | TP_UINT_FIELD(32); |
| 63 | TP_UINT_FIELD(64); |
| 64 | |
| 65 | #define TP_UINT_FIELD__SWAPPED(bits) \ |
| 66 | static u64 tp_field__swapped_u##bits(struct tp_field *field, struct perf_sample *sample) \ |
| 67 | { \ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 68 | u##bits value; \ |
| 69 | memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \ |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 70 | return bswap_##bits(value);\ |
| 71 | } |
| 72 | |
| 73 | TP_UINT_FIELD__SWAPPED(16); |
| 74 | TP_UINT_FIELD__SWAPPED(32); |
| 75 | TP_UINT_FIELD__SWAPPED(64); |
| 76 | |
| 77 | static int tp_field__init_uint(struct tp_field *field, |
| 78 | struct format_field *format_field, |
| 79 | bool needs_swap) |
| 80 | { |
| 81 | field->offset = format_field->offset; |
| 82 | |
| 83 | switch (format_field->size) { |
| 84 | case 1: |
| 85 | field->integer = tp_field__u8; |
| 86 | break; |
| 87 | case 2: |
| 88 | field->integer = needs_swap ? tp_field__swapped_u16 : tp_field__u16; |
| 89 | break; |
| 90 | case 4: |
| 91 | field->integer = needs_swap ? tp_field__swapped_u32 : tp_field__u32; |
| 92 | break; |
| 93 | case 8: |
| 94 | field->integer = needs_swap ? tp_field__swapped_u64 : tp_field__u64; |
| 95 | break; |
| 96 | default: |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static void *tp_field__ptr(struct tp_field *field, struct perf_sample *sample) |
| 104 | { |
| 105 | return sample->raw_data + field->offset; |
| 106 | } |
| 107 | |
| 108 | static int tp_field__init_ptr(struct tp_field *field, struct format_field *format_field) |
| 109 | { |
| 110 | field->offset = format_field->offset; |
| 111 | field->pointer = tp_field__ptr; |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | struct syscall_tp { |
| 116 | struct tp_field id; |
| 117 | union { |
| 118 | struct tp_field args, ret; |
| 119 | }; |
| 120 | }; |
| 121 | |
| 122 | static int perf_evsel__init_tp_uint_field(struct perf_evsel *evsel, |
| 123 | struct tp_field *field, |
| 124 | const char *name) |
| 125 | { |
| 126 | struct format_field *format_field = perf_evsel__field(evsel, name); |
| 127 | |
| 128 | if (format_field == NULL) |
| 129 | return -1; |
| 130 | |
| 131 | return tp_field__init_uint(field, format_field, evsel->needs_swap); |
| 132 | } |
| 133 | |
| 134 | #define perf_evsel__init_sc_tp_uint_field(evsel, name) \ |
| 135 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 136 | perf_evsel__init_tp_uint_field(evsel, &sc->name, #name); }) |
| 137 | |
| 138 | static int perf_evsel__init_tp_ptr_field(struct perf_evsel *evsel, |
| 139 | struct tp_field *field, |
| 140 | const char *name) |
| 141 | { |
| 142 | struct format_field *format_field = perf_evsel__field(evsel, name); |
| 143 | |
| 144 | if (format_field == NULL) |
| 145 | return -1; |
| 146 | |
| 147 | return tp_field__init_ptr(field, format_field); |
| 148 | } |
| 149 | |
| 150 | #define perf_evsel__init_sc_tp_ptr_field(evsel, name) \ |
| 151 | ({ struct syscall_tp *sc = evsel->priv;\ |
| 152 | perf_evsel__init_tp_ptr_field(evsel, &sc->name, #name); }) |
| 153 | |
| 154 | static void perf_evsel__delete_priv(struct perf_evsel *evsel) |
| 155 | { |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 156 | zfree(&evsel->priv); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 157 | perf_evsel__delete(evsel); |
| 158 | } |
| 159 | |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 160 | static int perf_evsel__init_syscall_tp(struct perf_evsel *evsel, void *handler) |
| 161 | { |
| 162 | evsel->priv = malloc(sizeof(struct syscall_tp)); |
| 163 | if (evsel->priv != NULL) { |
| 164 | if (perf_evsel__init_sc_tp_uint_field(evsel, id)) |
| 165 | goto out_delete; |
| 166 | |
| 167 | evsel->handler = handler; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | return -ENOMEM; |
| 172 | |
| 173 | out_delete: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 174 | zfree(&evsel->priv); |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 175 | return -ENOENT; |
| 176 | } |
| 177 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 178 | static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void *handler) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 179 | { |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 180 | struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 181 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 182 | /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */ |
| 183 | if (evsel == NULL) |
| 184 | evsel = perf_evsel__newtp("syscalls", direction); |
| 185 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 186 | if (evsel) { |
Namhyung Kim | 96695d4 | 2013-11-12 08:51:45 -0300 | [diff] [blame] | 187 | if (perf_evsel__init_syscall_tp(evsel, handler)) |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 188 | goto out_delete; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | return evsel; |
| 192 | |
| 193 | out_delete: |
| 194 | perf_evsel__delete_priv(evsel); |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | #define perf_evsel__sc_tp_uint(evsel, name, sample) \ |
| 199 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 200 | fields->name.integer(&fields->name, sample); }) |
| 201 | |
| 202 | #define perf_evsel__sc_tp_ptr(evsel, name, sample) \ |
| 203 | ({ struct syscall_tp *fields = evsel->priv; \ |
| 204 | fields->name.pointer(&fields->name, sample); }) |
| 205 | |
| 206 | static int perf_evlist__add_syscall_newtp(struct perf_evlist *evlist, |
| 207 | void *sys_enter_handler, |
| 208 | void *sys_exit_handler) |
| 209 | { |
| 210 | int ret = -1; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 211 | struct perf_evsel *sys_enter, *sys_exit; |
| 212 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 213 | sys_enter = perf_evsel__syscall_newtp("sys_enter", sys_enter_handler); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 214 | if (sys_enter == NULL) |
| 215 | goto out; |
| 216 | |
| 217 | if (perf_evsel__init_sc_tp_ptr_field(sys_enter, args)) |
| 218 | goto out_delete_sys_enter; |
| 219 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 220 | sys_exit = perf_evsel__syscall_newtp("sys_exit", sys_exit_handler); |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 221 | if (sys_exit == NULL) |
| 222 | goto out_delete_sys_enter; |
| 223 | |
| 224 | if (perf_evsel__init_sc_tp_uint_field(sys_exit, ret)) |
| 225 | goto out_delete_sys_exit; |
| 226 | |
| 227 | perf_evlist__add(evlist, sys_enter); |
| 228 | perf_evlist__add(evlist, sys_exit); |
| 229 | |
| 230 | ret = 0; |
| 231 | out: |
| 232 | return ret; |
| 233 | |
| 234 | out_delete_sys_exit: |
| 235 | perf_evsel__delete_priv(sys_exit); |
| 236 | out_delete_sys_enter: |
| 237 | perf_evsel__delete_priv(sys_enter); |
| 238 | goto out; |
| 239 | } |
| 240 | |
| 241 | |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 242 | struct syscall_arg { |
| 243 | unsigned long val; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 244 | struct thread *thread; |
| 245 | struct trace *trace; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 246 | void *parm; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 247 | u8 idx; |
| 248 | u8 mask; |
| 249 | }; |
| 250 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 251 | struct strarray { |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 252 | int offset; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 253 | int nr_entries; |
| 254 | const char **entries; |
| 255 | }; |
| 256 | |
| 257 | #define DEFINE_STRARRAY(array) struct strarray strarray__##array = { \ |
| 258 | .nr_entries = ARRAY_SIZE(array), \ |
| 259 | .entries = array, \ |
| 260 | } |
| 261 | |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 262 | #define DEFINE_STRARRAY_OFFSET(array, off) struct strarray strarray__##array = { \ |
| 263 | .offset = off, \ |
| 264 | .nr_entries = ARRAY_SIZE(array), \ |
| 265 | .entries = array, \ |
| 266 | } |
| 267 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 268 | static size_t __syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 269 | const char *intfmt, |
| 270 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 271 | { |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 272 | struct strarray *sa = arg->parm; |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 273 | int idx = arg->val - sa->offset; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 274 | |
| 275 | if (idx < 0 || idx >= sa->nr_entries) |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 276 | return scnprintf(bf, size, intfmt, arg->val); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 277 | |
| 278 | return scnprintf(bf, size, "%s", sa->entries[idx]); |
| 279 | } |
| 280 | |
Arnaldo Carvalho de Melo | 975b7c2 | 2013-10-08 17:17:43 -0300 | [diff] [blame] | 281 | static size_t syscall_arg__scnprintf_strarray(char *bf, size_t size, |
| 282 | struct syscall_arg *arg) |
| 283 | { |
| 284 | return __syscall_arg__scnprintf_strarray(bf, size, "%d", arg); |
| 285 | } |
| 286 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 287 | #define SCA_STRARRAY syscall_arg__scnprintf_strarray |
| 288 | |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 289 | #if defined(__i386__) || defined(__x86_64__) |
| 290 | /* |
| 291 | * FIXME: Make this available to all arches as soon as the ioctl beautifier |
| 292 | * gets rewritten to support all arches. |
| 293 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 294 | static size_t syscall_arg__scnprintf_strhexarray(char *bf, size_t size, |
| 295 | struct syscall_arg *arg) |
| 296 | { |
| 297 | return __syscall_arg__scnprintf_strarray(bf, size, "%#x", arg); |
| 298 | } |
| 299 | |
| 300 | #define SCA_STRHEXARRAY syscall_arg__scnprintf_strhexarray |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 301 | #endif /* defined(__i386__) || defined(__x86_64__) */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 302 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 303 | static size_t syscall_arg__scnprintf_fd(char *bf, size_t size, |
| 304 | struct syscall_arg *arg); |
| 305 | |
| 306 | #define SCA_FD syscall_arg__scnprintf_fd |
| 307 | |
| 308 | static size_t syscall_arg__scnprintf_fd_at(char *bf, size_t size, |
| 309 | struct syscall_arg *arg) |
| 310 | { |
| 311 | int fd = arg->val; |
| 312 | |
| 313 | if (fd == AT_FDCWD) |
| 314 | return scnprintf(bf, size, "CWD"); |
| 315 | |
| 316 | return syscall_arg__scnprintf_fd(bf, size, arg); |
| 317 | } |
| 318 | |
| 319 | #define SCA_FDAT syscall_arg__scnprintf_fd_at |
| 320 | |
| 321 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 322 | struct syscall_arg *arg); |
| 323 | |
| 324 | #define SCA_CLOSE_FD syscall_arg__scnprintf_close_fd |
| 325 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 326 | static size_t syscall_arg__scnprintf_hex(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 327 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 328 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 329 | return scnprintf(bf, size, "%#lx", arg->val); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 330 | } |
| 331 | |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 332 | #define SCA_HEX syscall_arg__scnprintf_hex |
| 333 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 334 | static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 335 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 336 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 337 | int printed = 0, prot = arg->val; |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 338 | |
| 339 | if (prot == PROT_NONE) |
| 340 | return scnprintf(bf, size, "NONE"); |
| 341 | #define P_MMAP_PROT(n) \ |
| 342 | if (prot & PROT_##n) { \ |
| 343 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 344 | prot &= ~PROT_##n; \ |
| 345 | } |
| 346 | |
| 347 | P_MMAP_PROT(EXEC); |
| 348 | P_MMAP_PROT(READ); |
| 349 | P_MMAP_PROT(WRITE); |
| 350 | #ifdef PROT_SEM |
| 351 | P_MMAP_PROT(SEM); |
| 352 | #endif |
| 353 | P_MMAP_PROT(GROWSDOWN); |
| 354 | P_MMAP_PROT(GROWSUP); |
| 355 | #undef P_MMAP_PROT |
| 356 | |
| 357 | if (prot) |
| 358 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", prot); |
| 359 | |
| 360 | return printed; |
| 361 | } |
| 362 | |
| 363 | #define SCA_MMAP_PROT syscall_arg__scnprintf_mmap_prot |
| 364 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 365 | static size_t syscall_arg__scnprintf_mmap_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 366 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 367 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 368 | int printed = 0, flags = arg->val; |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 369 | |
| 370 | #define P_MMAP_FLAG(n) \ |
| 371 | if (flags & MAP_##n) { \ |
| 372 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 373 | flags &= ~MAP_##n; \ |
| 374 | } |
| 375 | |
| 376 | P_MMAP_FLAG(SHARED); |
| 377 | P_MMAP_FLAG(PRIVATE); |
Kyle McMartin | 4181781 | 2013-09-05 10:29:47 -0400 | [diff] [blame] | 378 | #ifdef MAP_32BIT |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 379 | P_MMAP_FLAG(32BIT); |
Kyle McMartin | 4181781 | 2013-09-05 10:29:47 -0400 | [diff] [blame] | 380 | #endif |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 381 | P_MMAP_FLAG(ANONYMOUS); |
| 382 | P_MMAP_FLAG(DENYWRITE); |
| 383 | P_MMAP_FLAG(EXECUTABLE); |
| 384 | P_MMAP_FLAG(FILE); |
| 385 | P_MMAP_FLAG(FIXED); |
| 386 | P_MMAP_FLAG(GROWSDOWN); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 387 | #ifdef MAP_HUGETLB |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 388 | P_MMAP_FLAG(HUGETLB); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 389 | #endif |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 390 | P_MMAP_FLAG(LOCKED); |
| 391 | P_MMAP_FLAG(NONBLOCK); |
| 392 | P_MMAP_FLAG(NORESERVE); |
| 393 | P_MMAP_FLAG(POPULATE); |
| 394 | P_MMAP_FLAG(STACK); |
| 395 | #ifdef MAP_UNINITIALIZED |
| 396 | P_MMAP_FLAG(UNINITIALIZED); |
| 397 | #endif |
| 398 | #undef P_MMAP_FLAG |
| 399 | |
| 400 | if (flags) |
| 401 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 402 | |
| 403 | return printed; |
| 404 | } |
| 405 | |
| 406 | #define SCA_MMAP_FLAGS syscall_arg__scnprintf_mmap_flags |
| 407 | |
Alex Snast | 86998dd | 2014-08-13 18:42:40 +0300 | [diff] [blame] | 408 | static size_t syscall_arg__scnprintf_mremap_flags(char *bf, size_t size, |
| 409 | struct syscall_arg *arg) |
| 410 | { |
| 411 | int printed = 0, flags = arg->val; |
| 412 | |
| 413 | #define P_MREMAP_FLAG(n) \ |
| 414 | if (flags & MREMAP_##n) { \ |
| 415 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 416 | flags &= ~MREMAP_##n; \ |
| 417 | } |
| 418 | |
| 419 | P_MREMAP_FLAG(MAYMOVE); |
| 420 | #ifdef MREMAP_FIXED |
| 421 | P_MREMAP_FLAG(FIXED); |
| 422 | #endif |
| 423 | #undef P_MREMAP_FLAG |
| 424 | |
| 425 | if (flags) |
| 426 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 427 | |
| 428 | return printed; |
| 429 | } |
| 430 | |
| 431 | #define SCA_MREMAP_FLAGS syscall_arg__scnprintf_mremap_flags |
| 432 | |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 433 | static size_t syscall_arg__scnprintf_madvise_behavior(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 434 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 435 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 436 | int behavior = arg->val; |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 437 | |
| 438 | switch (behavior) { |
| 439 | #define P_MADV_BHV(n) case MADV_##n: return scnprintf(bf, size, #n) |
| 440 | P_MADV_BHV(NORMAL); |
| 441 | P_MADV_BHV(RANDOM); |
| 442 | P_MADV_BHV(SEQUENTIAL); |
| 443 | P_MADV_BHV(WILLNEED); |
| 444 | P_MADV_BHV(DONTNEED); |
| 445 | P_MADV_BHV(REMOVE); |
| 446 | P_MADV_BHV(DONTFORK); |
| 447 | P_MADV_BHV(DOFORK); |
| 448 | P_MADV_BHV(HWPOISON); |
| 449 | #ifdef MADV_SOFT_OFFLINE |
| 450 | P_MADV_BHV(SOFT_OFFLINE); |
| 451 | #endif |
| 452 | P_MADV_BHV(MERGEABLE); |
| 453 | P_MADV_BHV(UNMERGEABLE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 454 | #ifdef MADV_HUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 455 | P_MADV_BHV(HUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 456 | #endif |
| 457 | #ifdef MADV_NOHUGEPAGE |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 458 | P_MADV_BHV(NOHUGEPAGE); |
David Ahern | f2935f3 | 2013-08-27 10:50:40 -0600 | [diff] [blame] | 459 | #endif |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 460 | #ifdef MADV_DONTDUMP |
| 461 | P_MADV_BHV(DONTDUMP); |
| 462 | #endif |
| 463 | #ifdef MADV_DODUMP |
| 464 | P_MADV_BHV(DODUMP); |
| 465 | #endif |
| 466 | #undef P_MADV_PHV |
| 467 | default: break; |
| 468 | } |
| 469 | |
| 470 | return scnprintf(bf, size, "%#x", behavior); |
| 471 | } |
| 472 | |
| 473 | #define SCA_MADV_BHV syscall_arg__scnprintf_madvise_behavior |
| 474 | |
Arnaldo Carvalho de Melo | 5cea6ff | 2013-09-20 11:49:50 -0300 | [diff] [blame] | 475 | static size_t syscall_arg__scnprintf_flock(char *bf, size_t size, |
| 476 | struct syscall_arg *arg) |
| 477 | { |
| 478 | int printed = 0, op = arg->val; |
| 479 | |
| 480 | if (op == 0) |
| 481 | return scnprintf(bf, size, "NONE"); |
| 482 | #define P_CMD(cmd) \ |
| 483 | if ((op & LOCK_##cmd) == LOCK_##cmd) { \ |
| 484 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #cmd); \ |
| 485 | op &= ~LOCK_##cmd; \ |
| 486 | } |
| 487 | |
| 488 | P_CMD(SH); |
| 489 | P_CMD(EX); |
| 490 | P_CMD(NB); |
| 491 | P_CMD(UN); |
| 492 | P_CMD(MAND); |
| 493 | P_CMD(RW); |
| 494 | P_CMD(READ); |
| 495 | P_CMD(WRITE); |
| 496 | #undef P_OP |
| 497 | |
| 498 | if (op) |
| 499 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", op); |
| 500 | |
| 501 | return printed; |
| 502 | } |
| 503 | |
| 504 | #define SCA_FLOCK syscall_arg__scnprintf_flock |
| 505 | |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 506 | static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 507 | { |
| 508 | enum syscall_futex_args { |
| 509 | SCF_UADDR = (1 << 0), |
| 510 | SCF_OP = (1 << 1), |
| 511 | SCF_VAL = (1 << 2), |
| 512 | SCF_TIMEOUT = (1 << 3), |
| 513 | SCF_UADDR2 = (1 << 4), |
| 514 | SCF_VAL3 = (1 << 5), |
| 515 | }; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 516 | int op = arg->val; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 517 | int cmd = op & FUTEX_CMD_MASK; |
| 518 | size_t printed = 0; |
| 519 | |
| 520 | switch (cmd) { |
| 521 | #define P_FUTEX_OP(n) case FUTEX_##n: printed = scnprintf(bf, size, #n); |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 522 | P_FUTEX_OP(WAIT); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 523 | P_FUTEX_OP(WAKE); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 524 | P_FUTEX_OP(FD); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 525 | P_FUTEX_OP(REQUEUE); arg->mask |= SCF_VAL3|SCF_TIMEOUT; break; |
| 526 | P_FUTEX_OP(CMP_REQUEUE); arg->mask |= SCF_TIMEOUT; break; |
| 527 | P_FUTEX_OP(CMP_REQUEUE_PI); arg->mask |= SCF_TIMEOUT; break; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 528 | P_FUTEX_OP(WAKE_OP); break; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 529 | P_FUTEX_OP(LOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 530 | P_FUTEX_OP(UNLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2|SCF_TIMEOUT; break; |
| 531 | P_FUTEX_OP(TRYLOCK_PI); arg->mask |= SCF_VAL3|SCF_UADDR2; break; |
| 532 | P_FUTEX_OP(WAIT_BITSET); arg->mask |= SCF_UADDR2; break; |
| 533 | P_FUTEX_OP(WAKE_BITSET); arg->mask |= SCF_UADDR2; break; |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 534 | P_FUTEX_OP(WAIT_REQUEUE_PI); break; |
| 535 | default: printed = scnprintf(bf, size, "%#x", cmd); break; |
| 536 | } |
| 537 | |
| 538 | if (op & FUTEX_PRIVATE_FLAG) |
| 539 | printed += scnprintf(bf + printed, size - printed, "|PRIV"); |
| 540 | |
| 541 | if (op & FUTEX_CLOCK_REALTIME) |
| 542 | printed += scnprintf(bf + printed, size - printed, "|CLKRT"); |
| 543 | |
| 544 | return printed; |
| 545 | } |
| 546 | |
Arnaldo Carvalho de Melo | efe6b88 | 2013-09-03 16:15:12 -0300 | [diff] [blame] | 547 | #define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op |
| 548 | |
Arnaldo Carvalho de Melo | 03e3adc | 2013-10-08 16:00:21 -0300 | [diff] [blame] | 549 | static const char *epoll_ctl_ops[] = { "ADD", "DEL", "MOD", }; |
| 550 | static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, 1); |
Arnaldo Carvalho de Melo | eac032c | 2013-09-20 11:27:32 -0300 | [diff] [blame] | 551 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 552 | static const char *itimers[] = { "REAL", "VIRTUAL", "PROF", }; |
| 553 | static DEFINE_STRARRAY(itimers); |
| 554 | |
Arnaldo Carvalho de Melo | efe6b88 | 2013-09-03 16:15:12 -0300 | [diff] [blame] | 555 | static const char *whences[] = { "SET", "CUR", "END", |
| 556 | #ifdef SEEK_DATA |
| 557 | "DATA", |
| 558 | #endif |
| 559 | #ifdef SEEK_HOLE |
| 560 | "HOLE", |
| 561 | #endif |
| 562 | }; |
| 563 | static DEFINE_STRARRAY(whences); |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 564 | |
Arnaldo Carvalho de Melo | 80f587d | 2013-09-03 16:28:58 -0300 | [diff] [blame] | 565 | static const char *fcntl_cmds[] = { |
| 566 | "DUPFD", "GETFD", "SETFD", "GETFL", "SETFL", "GETLK", "SETLK", |
| 567 | "SETLKW", "SETOWN", "GETOWN", "SETSIG", "GETSIG", "F_GETLK64", |
| 568 | "F_SETLK64", "F_SETLKW64", "F_SETOWN_EX", "F_GETOWN_EX", |
| 569 | "F_GETOWNER_UIDS", |
| 570 | }; |
| 571 | static DEFINE_STRARRAY(fcntl_cmds); |
| 572 | |
Arnaldo Carvalho de Melo | c045bf0 | 2013-09-04 11:52:33 -0300 | [diff] [blame] | 573 | static const char *rlimit_resources[] = { |
| 574 | "CPU", "FSIZE", "DATA", "STACK", "CORE", "RSS", "NPROC", "NOFILE", |
| 575 | "MEMLOCK", "AS", "LOCKS", "SIGPENDING", "MSGQUEUE", "NICE", "RTPRIO", |
| 576 | "RTTIME", |
| 577 | }; |
| 578 | static DEFINE_STRARRAY(rlimit_resources); |
| 579 | |
Arnaldo Carvalho de Melo | eb5b1b1 | 2013-09-03 16:37:46 -0300 | [diff] [blame] | 580 | static const char *sighow[] = { "BLOCK", "UNBLOCK", "SETMASK", }; |
| 581 | static DEFINE_STRARRAY(sighow); |
| 582 | |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 583 | static const char *clockid[] = { |
| 584 | "REALTIME", "MONOTONIC", "PROCESS_CPUTIME_ID", "THREAD_CPUTIME_ID", |
| 585 | "MONOTONIC_RAW", "REALTIME_COARSE", "MONOTONIC_COARSE", |
| 586 | }; |
| 587 | static DEFINE_STRARRAY(clockid); |
| 588 | |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 589 | static const char *socket_families[] = { |
| 590 | "UNSPEC", "LOCAL", "INET", "AX25", "IPX", "APPLETALK", "NETROM", |
| 591 | "BRIDGE", "ATMPVC", "X25", "INET6", "ROSE", "DECnet", "NETBEUI", |
| 592 | "SECURITY", "KEY", "NETLINK", "PACKET", "ASH", "ECONET", "ATMSVC", |
| 593 | "RDS", "SNA", "IRDA", "PPPOX", "WANPIPE", "LLC", "IB", "CAN", "TIPC", |
| 594 | "BLUETOOTH", "IUCV", "RXRPC", "ISDN", "PHONET", "IEEE802154", "CAIF", |
| 595 | "ALG", "NFC", "VSOCK", |
| 596 | }; |
| 597 | static DEFINE_STRARRAY(socket_families); |
| 598 | |
Arnaldo Carvalho de Melo | a28b24b | 2013-09-04 11:00:44 -0300 | [diff] [blame] | 599 | #ifndef SOCK_TYPE_MASK |
| 600 | #define SOCK_TYPE_MASK 0xf |
| 601 | #endif |
| 602 | |
| 603 | static size_t syscall_arg__scnprintf_socket_type(char *bf, size_t size, |
| 604 | struct syscall_arg *arg) |
| 605 | { |
| 606 | size_t printed; |
| 607 | int type = arg->val, |
| 608 | flags = type & ~SOCK_TYPE_MASK; |
| 609 | |
| 610 | type &= SOCK_TYPE_MASK; |
| 611 | /* |
| 612 | * Can't use a strarray, MIPS may override for ABI reasons. |
| 613 | */ |
| 614 | switch (type) { |
| 615 | #define P_SK_TYPE(n) case SOCK_##n: printed = scnprintf(bf, size, #n); break; |
| 616 | P_SK_TYPE(STREAM); |
| 617 | P_SK_TYPE(DGRAM); |
| 618 | P_SK_TYPE(RAW); |
| 619 | P_SK_TYPE(RDM); |
| 620 | P_SK_TYPE(SEQPACKET); |
| 621 | P_SK_TYPE(DCCP); |
| 622 | P_SK_TYPE(PACKET); |
| 623 | #undef P_SK_TYPE |
| 624 | default: |
| 625 | printed = scnprintf(bf, size, "%#x", type); |
| 626 | } |
| 627 | |
| 628 | #define P_SK_FLAG(n) \ |
| 629 | if (flags & SOCK_##n) { \ |
| 630 | printed += scnprintf(bf + printed, size - printed, "|%s", #n); \ |
| 631 | flags &= ~SOCK_##n; \ |
| 632 | } |
| 633 | |
| 634 | P_SK_FLAG(CLOEXEC); |
| 635 | P_SK_FLAG(NONBLOCK); |
| 636 | #undef P_SK_FLAG |
| 637 | |
| 638 | if (flags) |
| 639 | printed += scnprintf(bf + printed, size - printed, "|%#x", flags); |
| 640 | |
| 641 | return printed; |
| 642 | } |
| 643 | |
| 644 | #define SCA_SK_TYPE syscall_arg__scnprintf_socket_type |
| 645 | |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 646 | #ifndef MSG_PROBE |
| 647 | #define MSG_PROBE 0x10 |
| 648 | #endif |
David Ahern | b6e8f8f | 2013-09-22 19:44:56 -0600 | [diff] [blame] | 649 | #ifndef MSG_WAITFORONE |
| 650 | #define MSG_WAITFORONE 0x10000 |
| 651 | #endif |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 652 | #ifndef MSG_SENDPAGE_NOTLAST |
| 653 | #define MSG_SENDPAGE_NOTLAST 0x20000 |
| 654 | #endif |
| 655 | #ifndef MSG_FASTOPEN |
| 656 | #define MSG_FASTOPEN 0x20000000 |
| 657 | #endif |
| 658 | |
| 659 | static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size, |
| 660 | struct syscall_arg *arg) |
| 661 | { |
| 662 | int printed = 0, flags = arg->val; |
| 663 | |
| 664 | if (flags == 0) |
| 665 | return scnprintf(bf, size, "NONE"); |
| 666 | #define P_MSG_FLAG(n) \ |
| 667 | if (flags & MSG_##n) { \ |
| 668 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 669 | flags &= ~MSG_##n; \ |
| 670 | } |
| 671 | |
| 672 | P_MSG_FLAG(OOB); |
| 673 | P_MSG_FLAG(PEEK); |
| 674 | P_MSG_FLAG(DONTROUTE); |
| 675 | P_MSG_FLAG(TRYHARD); |
| 676 | P_MSG_FLAG(CTRUNC); |
| 677 | P_MSG_FLAG(PROBE); |
| 678 | P_MSG_FLAG(TRUNC); |
| 679 | P_MSG_FLAG(DONTWAIT); |
| 680 | P_MSG_FLAG(EOR); |
| 681 | P_MSG_FLAG(WAITALL); |
| 682 | P_MSG_FLAG(FIN); |
| 683 | P_MSG_FLAG(SYN); |
| 684 | P_MSG_FLAG(CONFIRM); |
| 685 | P_MSG_FLAG(RST); |
| 686 | P_MSG_FLAG(ERRQUEUE); |
| 687 | P_MSG_FLAG(NOSIGNAL); |
| 688 | P_MSG_FLAG(MORE); |
| 689 | P_MSG_FLAG(WAITFORONE); |
| 690 | P_MSG_FLAG(SENDPAGE_NOTLAST); |
| 691 | P_MSG_FLAG(FASTOPEN); |
| 692 | P_MSG_FLAG(CMSG_CLOEXEC); |
| 693 | #undef P_MSG_FLAG |
| 694 | |
| 695 | if (flags) |
| 696 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 697 | |
| 698 | return printed; |
| 699 | } |
| 700 | |
| 701 | #define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags |
| 702 | |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 703 | static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size, |
| 704 | struct syscall_arg *arg) |
| 705 | { |
| 706 | size_t printed = 0; |
| 707 | int mode = arg->val; |
| 708 | |
| 709 | if (mode == F_OK) /* 0 */ |
| 710 | return scnprintf(bf, size, "F"); |
| 711 | #define P_MODE(n) \ |
| 712 | if (mode & n##_OK) { \ |
| 713 | printed += scnprintf(bf + printed, size - printed, "%s", #n); \ |
| 714 | mode &= ~n##_OK; \ |
| 715 | } |
| 716 | |
| 717 | P_MODE(R); |
| 718 | P_MODE(W); |
| 719 | P_MODE(X); |
| 720 | #undef P_MODE |
| 721 | |
| 722 | if (mode) |
| 723 | printed += scnprintf(bf + printed, size - printed, "|%#x", mode); |
| 724 | |
| 725 | return printed; |
| 726 | } |
| 727 | |
| 728 | #define SCA_ACCMODE syscall_arg__scnprintf_access_mode |
| 729 | |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 730 | static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 731 | struct syscall_arg *arg) |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 732 | { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 733 | int printed = 0, flags = arg->val; |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 734 | |
| 735 | if (!(flags & O_CREAT)) |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 736 | arg->mask |= 1 << (arg->idx + 1); /* Mask the mode parm */ |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 737 | |
| 738 | if (flags == 0) |
| 739 | return scnprintf(bf, size, "RDONLY"); |
| 740 | #define P_FLAG(n) \ |
| 741 | if (flags & O_##n) { \ |
| 742 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 743 | flags &= ~O_##n; \ |
| 744 | } |
| 745 | |
| 746 | P_FLAG(APPEND); |
| 747 | P_FLAG(ASYNC); |
| 748 | P_FLAG(CLOEXEC); |
| 749 | P_FLAG(CREAT); |
| 750 | P_FLAG(DIRECT); |
| 751 | P_FLAG(DIRECTORY); |
| 752 | P_FLAG(EXCL); |
| 753 | P_FLAG(LARGEFILE); |
| 754 | P_FLAG(NOATIME); |
| 755 | P_FLAG(NOCTTY); |
| 756 | #ifdef O_NONBLOCK |
| 757 | P_FLAG(NONBLOCK); |
| 758 | #elif O_NDELAY |
| 759 | P_FLAG(NDELAY); |
| 760 | #endif |
| 761 | #ifdef O_PATH |
| 762 | P_FLAG(PATH); |
| 763 | #endif |
| 764 | P_FLAG(RDWR); |
| 765 | #ifdef O_DSYNC |
| 766 | if ((flags & O_SYNC) == O_SYNC) |
| 767 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", "SYNC"); |
| 768 | else { |
| 769 | P_FLAG(DSYNC); |
| 770 | } |
| 771 | #else |
| 772 | P_FLAG(SYNC); |
| 773 | #endif |
| 774 | P_FLAG(TRUNC); |
| 775 | P_FLAG(WRONLY); |
| 776 | #undef P_FLAG |
| 777 | |
| 778 | if (flags) |
| 779 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 780 | |
| 781 | return printed; |
| 782 | } |
| 783 | |
| 784 | #define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags |
| 785 | |
Arnaldo Carvalho de Melo | 49af9e9 | 2013-09-12 12:18:56 -0300 | [diff] [blame] | 786 | static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size, |
| 787 | struct syscall_arg *arg) |
| 788 | { |
| 789 | int printed = 0, flags = arg->val; |
| 790 | |
| 791 | if (flags == 0) |
| 792 | return scnprintf(bf, size, "NONE"); |
| 793 | #define P_FLAG(n) \ |
| 794 | if (flags & EFD_##n) { \ |
| 795 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 796 | flags &= ~EFD_##n; \ |
| 797 | } |
| 798 | |
| 799 | P_FLAG(SEMAPHORE); |
| 800 | P_FLAG(CLOEXEC); |
| 801 | P_FLAG(NONBLOCK); |
| 802 | #undef P_FLAG |
| 803 | |
| 804 | if (flags) |
| 805 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 806 | |
| 807 | return printed; |
| 808 | } |
| 809 | |
| 810 | #define SCA_EFD_FLAGS syscall_arg__scnprintf_eventfd_flags |
| 811 | |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 812 | static size_t syscall_arg__scnprintf_pipe_flags(char *bf, size_t size, |
| 813 | struct syscall_arg *arg) |
| 814 | { |
| 815 | int printed = 0, flags = arg->val; |
| 816 | |
| 817 | #define P_FLAG(n) \ |
| 818 | if (flags & O_##n) { \ |
| 819 | printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \ |
| 820 | flags &= ~O_##n; \ |
| 821 | } |
| 822 | |
| 823 | P_FLAG(CLOEXEC); |
| 824 | P_FLAG(NONBLOCK); |
| 825 | #undef P_FLAG |
| 826 | |
| 827 | if (flags) |
| 828 | printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); |
| 829 | |
| 830 | return printed; |
| 831 | } |
| 832 | |
| 833 | #define SCA_PIPE_FLAGS syscall_arg__scnprintf_pipe_flags |
| 834 | |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 835 | static size_t syscall_arg__scnprintf_signum(char *bf, size_t size, struct syscall_arg *arg) |
| 836 | { |
| 837 | int sig = arg->val; |
| 838 | |
| 839 | switch (sig) { |
| 840 | #define P_SIGNUM(n) case SIG##n: return scnprintf(bf, size, #n) |
| 841 | P_SIGNUM(HUP); |
| 842 | P_SIGNUM(INT); |
| 843 | P_SIGNUM(QUIT); |
| 844 | P_SIGNUM(ILL); |
| 845 | P_SIGNUM(TRAP); |
| 846 | P_SIGNUM(ABRT); |
| 847 | P_SIGNUM(BUS); |
| 848 | P_SIGNUM(FPE); |
| 849 | P_SIGNUM(KILL); |
| 850 | P_SIGNUM(USR1); |
| 851 | P_SIGNUM(SEGV); |
| 852 | P_SIGNUM(USR2); |
| 853 | P_SIGNUM(PIPE); |
| 854 | P_SIGNUM(ALRM); |
| 855 | P_SIGNUM(TERM); |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 856 | P_SIGNUM(CHLD); |
| 857 | P_SIGNUM(CONT); |
| 858 | P_SIGNUM(STOP); |
| 859 | P_SIGNUM(TSTP); |
| 860 | P_SIGNUM(TTIN); |
| 861 | P_SIGNUM(TTOU); |
| 862 | P_SIGNUM(URG); |
| 863 | P_SIGNUM(XCPU); |
| 864 | P_SIGNUM(XFSZ); |
| 865 | P_SIGNUM(VTALRM); |
| 866 | P_SIGNUM(PROF); |
| 867 | P_SIGNUM(WINCH); |
| 868 | P_SIGNUM(IO); |
| 869 | P_SIGNUM(PWR); |
| 870 | P_SIGNUM(SYS); |
Ben Hutchings | 02c5bb4 | 2014-02-06 01:00:41 +0000 | [diff] [blame] | 871 | #ifdef SIGEMT |
| 872 | P_SIGNUM(EMT); |
| 873 | #endif |
| 874 | #ifdef SIGSTKFLT |
| 875 | P_SIGNUM(STKFLT); |
| 876 | #endif |
| 877 | #ifdef SIGSWI |
| 878 | P_SIGNUM(SWI); |
| 879 | #endif |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 880 | default: break; |
| 881 | } |
| 882 | |
| 883 | return scnprintf(bf, size, "%#x", sig); |
| 884 | } |
| 885 | |
| 886 | #define SCA_SIGNUM syscall_arg__scnprintf_signum |
| 887 | |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 888 | #if defined(__i386__) || defined(__x86_64__) |
| 889 | /* |
| 890 | * FIXME: Make this available to all arches. |
| 891 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 892 | #define TCGETS 0x5401 |
| 893 | |
| 894 | static const char *tioctls[] = { |
| 895 | "TCGETS", "TCSETS", "TCSETSW", "TCSETSF", "TCGETA", "TCSETA", "TCSETAW", |
| 896 | "TCSETAF", "TCSBRK", "TCXONC", "TCFLSH", "TIOCEXCL", "TIOCNXCL", |
| 897 | "TIOCSCTTY", "TIOCGPGRP", "TIOCSPGRP", "TIOCOUTQ", "TIOCSTI", |
| 898 | "TIOCGWINSZ", "TIOCSWINSZ", "TIOCMGET", "TIOCMBIS", "TIOCMBIC", |
| 899 | "TIOCMSET", "TIOCGSOFTCAR", "TIOCSSOFTCAR", "FIONREAD", "TIOCLINUX", |
| 900 | "TIOCCONS", "TIOCGSERIAL", "TIOCSSERIAL", "TIOCPKT", "FIONBIO", |
| 901 | "TIOCNOTTY", "TIOCSETD", "TIOCGETD", "TCSBRKP", [0x27] = "TIOCSBRK", |
| 902 | "TIOCCBRK", "TIOCGSID", "TCGETS2", "TCSETS2", "TCSETSW2", "TCSETSF2", |
| 903 | "TIOCGRS485", "TIOCSRS485", "TIOCGPTN", "TIOCSPTLCK", |
| 904 | "TIOCGDEV||TCGETX", "TCSETX", "TCSETXF", "TCSETXW", "TIOCSIG", |
| 905 | "TIOCVHANGUP", "TIOCGPKT", "TIOCGPTLCK", "TIOCGEXCL", |
| 906 | [0x50] = "FIONCLEX", "FIOCLEX", "FIOASYNC", "TIOCSERCONFIG", |
| 907 | "TIOCSERGWILD", "TIOCSERSWILD", "TIOCGLCKTRMIOS", "TIOCSLCKTRMIOS", |
| 908 | "TIOCSERGSTRUCT", "TIOCSERGETLSR", "TIOCSERGETMULTI", "TIOCSERSETMULTI", |
| 909 | "TIOCMIWAIT", "TIOCGICOUNT", [0x60] = "FIOQSIZE", |
| 910 | }; |
| 911 | |
| 912 | static DEFINE_STRARRAY_OFFSET(tioctls, 0x5401); |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 913 | #endif /* defined(__i386__) || defined(__x86_64__) */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 914 | |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 915 | #define STRARRAY(arg, name, array) \ |
| 916 | .arg_scnprintf = { [arg] = SCA_STRARRAY, }, \ |
| 917 | .arg_parm = { [arg] = &strarray__##array, } |
| 918 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 919 | static struct syscall_fmt { |
| 920 | const char *name; |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 921 | const char *alias; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 922 | size_t (*arg_scnprintf[6])(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 923 | void *arg_parm[6]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 924 | bool errmsg; |
| 925 | bool timeout; |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 926 | bool hexret; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 927 | } syscall_fmts[] = { |
Arnaldo Carvalho de Melo | 5110899 | 2013-09-04 11:42:27 -0300 | [diff] [blame] | 928 | { .name = "access", .errmsg = true, |
| 929 | .arg_scnprintf = { [1] = SCA_ACCMODE, /* mode */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 930 | { .name = "arch_prctl", .errmsg = true, .alias = "prctl", }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 931 | { .name = "brk", .hexret = true, |
| 932 | .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, }, |
David Ahern | 4f8c1b7 | 2013-09-22 19:45:00 -0600 | [diff] [blame] | 933 | { .name = "clock_gettime", .errmsg = true, STRARRAY(0, clk_id, clockid), }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 934 | { .name = "close", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 935 | .arg_scnprintf = { [0] = SCA_CLOSE_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | a14bb86 | 2013-07-30 16:38:23 -0300 | [diff] [blame] | 936 | { .name = "connect", .errmsg = true, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 937 | { .name = "dup", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 938 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 939 | { .name = "dup2", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 940 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 941 | { .name = "dup3", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 942 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 943 | { .name = "epoll_ctl", .errmsg = true, STRARRAY(1, op, epoll_ctl_ops), }, |
Arnaldo Carvalho de Melo | 49af9e9 | 2013-09-12 12:18:56 -0300 | [diff] [blame] | 944 | { .name = "eventfd2", .errmsg = true, |
| 945 | .arg_scnprintf = { [1] = SCA_EFD_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 946 | { .name = "faccessat", .errmsg = true, |
| 947 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
| 948 | { .name = "fadvise64", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 949 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 950 | { .name = "fallocate", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 951 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 952 | { .name = "fchdir", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 953 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 954 | { .name = "fchmod", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 955 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 956 | { .name = "fchmodat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 957 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 958 | { .name = "fchown", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 959 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 960 | { .name = "fchownat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 961 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 962 | { .name = "fcntl", .errmsg = true, |
| 963 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 964 | [1] = SCA_STRARRAY, /* cmd */ }, |
| 965 | .arg_parm = { [1] = &strarray__fcntl_cmds, /* cmd */ }, }, |
| 966 | { .name = "fdatasync", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 967 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 5cea6ff | 2013-09-20 11:49:50 -0300 | [diff] [blame] | 968 | { .name = "flock", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 969 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 970 | [1] = SCA_FLOCK, /* cmd */ }, }, |
| 971 | { .name = "fsetxattr", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 972 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 973 | { .name = "fstat", .errmsg = true, .alias = "newfstat", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 974 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 975 | { .name = "fstatat", .errmsg = true, .alias = "newfstatat", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 976 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 977 | { .name = "fstatfs", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 978 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 979 | { .name = "fsync", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 980 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 981 | { .name = "ftruncate", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 982 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | f9da0b0 | 2013-09-02 13:46:44 -0300 | [diff] [blame] | 983 | { .name = "futex", .errmsg = true, |
| 984 | .arg_scnprintf = { [1] = SCA_FUTEX_OP, /* op */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 985 | { .name = "futimesat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 986 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 987 | { .name = "getdents", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 988 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 989 | { .name = "getdents64", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 990 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 991 | { .name = "getitimer", .errmsg = true, STRARRAY(0, which, itimers), }, |
| 992 | { .name = "getrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 993 | { .name = "ioctl", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 994 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 995 | #if defined(__i386__) || defined(__x86_64__) |
| 996 | /* |
| 997 | * FIXME: Make this available to all arches. |
| 998 | */ |
Arnaldo Carvalho de Melo | 78645cf | 2013-10-08 17:43:20 -0300 | [diff] [blame] | 999 | [1] = SCA_STRHEXARRAY, /* cmd */ |
| 1000 | [2] = SCA_HEX, /* arg */ }, |
| 1001 | .arg_parm = { [1] = &strarray__tioctls, /* cmd */ }, }, |
Arnaldo Carvalho de Melo | 844ae5b | 2014-02-10 14:09:48 -0300 | [diff] [blame] | 1002 | #else |
| 1003 | [2] = SCA_HEX, /* arg */ }, }, |
| 1004 | #endif |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1005 | { .name = "kill", .errmsg = true, |
| 1006 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1007 | { .name = "linkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1008 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1009 | { .name = "lseek", .errmsg = true, |
| 1010 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ |
| 1011 | [2] = SCA_STRARRAY, /* whence */ }, |
| 1012 | .arg_parm = { [2] = &strarray__whences, /* whence */ }, }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 1013 | { .name = "lstat", .errmsg = true, .alias = "newlstat", }, |
Arnaldo Carvalho de Melo | 9e9716d | 2013-08-23 10:06:41 -0300 | [diff] [blame] | 1014 | { .name = "madvise", .errmsg = true, |
| 1015 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 1016 | [2] = SCA_MADV_BHV, /* behavior */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1017 | { .name = "mkdirat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1018 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1019 | { .name = "mknodat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1020 | .arg_scnprintf = { [0] = SCA_FDAT, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 3d903aa | 2013-09-24 00:09:38 -0300 | [diff] [blame] | 1021 | { .name = "mlock", .errmsg = true, |
| 1022 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
| 1023 | { .name = "mlockall", .errmsg = true, |
| 1024 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1025 | { .name = "mmap", .hexret = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1026 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
Arnaldo Carvalho de Melo | 941557e | 2013-08-23 10:48:33 -0300 | [diff] [blame] | 1027 | [2] = SCA_MMAP_PROT, /* prot */ |
Namhyung Kim | 73faab3 | 2013-11-12 15:24:59 +0900 | [diff] [blame] | 1028 | [3] = SCA_MMAP_FLAGS, /* flags */ |
| 1029 | [4] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1030 | { .name = "mprotect", .errmsg = true, |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1031 | .arg_scnprintf = { [0] = SCA_HEX, /* start */ |
| 1032 | [2] = SCA_MMAP_PROT, /* prot */ }, }, |
| 1033 | { .name = "mremap", .hexret = true, |
| 1034 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ |
Alex Snast | 86998dd | 2014-08-13 18:42:40 +0300 | [diff] [blame] | 1035 | [3] = SCA_MREMAP_FLAGS, /* flags */ |
Arnaldo Carvalho de Melo | ae68538 | 2013-08-20 17:44:42 -0300 | [diff] [blame] | 1036 | [4] = SCA_HEX, /* new_addr */ }, }, |
Arnaldo Carvalho de Melo | 3d903aa | 2013-09-24 00:09:38 -0300 | [diff] [blame] | 1037 | { .name = "munlock", .errmsg = true, |
| 1038 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1039 | { .name = "munmap", .errmsg = true, |
| 1040 | .arg_scnprintf = { [0] = SCA_HEX, /* addr */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1041 | { .name = "name_to_handle_at", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1042 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1043 | { .name = "newfstatat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1044 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | be65a89 | 2013-09-02 16:22:31 -0300 | [diff] [blame] | 1045 | { .name = "open", .errmsg = true, |
| 1046 | .arg_scnprintf = { [1] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame] | 1047 | { .name = "open_by_handle_at", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1048 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1049 | [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 31cd385 | 2013-09-02 16:40:40 -0300 | [diff] [blame] | 1050 | { .name = "openat", .errmsg = true, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1051 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ |
| 1052 | [2] = SCA_OPEN_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 46cce19 | 2013-09-23 12:52:04 -0300 | [diff] [blame] | 1053 | { .name = "pipe2", .errmsg = true, |
| 1054 | .arg_scnprintf = { [1] = SCA_PIPE_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1055 | { .name = "poll", .errmsg = true, .timeout = true, }, |
| 1056 | { .name = "ppoll", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1057 | { .name = "pread", .errmsg = true, .alias = "pread64", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1058 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1059 | { .name = "preadv", .errmsg = true, .alias = "pread", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1060 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1061 | { .name = "prlimit64", .errmsg = true, STRARRAY(1, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1062 | { .name = "pwrite", .errmsg = true, .alias = "pwrite64", |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1063 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1064 | { .name = "pwritev", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1065 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1066 | { .name = "read", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1067 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1068 | { .name = "readlinkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1069 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1070 | { .name = "readv", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1071 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1072 | { .name = "recvfrom", .errmsg = true, |
| 1073 | .arg_scnprintf = { [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
| 1074 | { .name = "recvmmsg", .errmsg = true, |
| 1075 | .arg_scnprintf = { [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
| 1076 | { .name = "recvmsg", .errmsg = true, |
| 1077 | .arg_scnprintf = { [2] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1078 | { .name = "renameat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1079 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1080 | { .name = "rt_sigaction", .errmsg = true, |
| 1081 | .arg_scnprintf = { [0] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1082 | { .name = "rt_sigprocmask", .errmsg = true, STRARRAY(0, how, sighow), }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1083 | { .name = "rt_sigqueueinfo", .errmsg = true, |
| 1084 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
| 1085 | { .name = "rt_tgsigqueueinfo", .errmsg = true, |
| 1086 | .arg_scnprintf = { [2] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1087 | { .name = "select", .errmsg = true, .timeout = true, }, |
Arnaldo Carvalho de Melo | b2cc99fd | 2013-09-12 11:54:48 -0300 | [diff] [blame] | 1088 | { .name = "sendmmsg", .errmsg = true, |
| 1089 | .arg_scnprintf = { [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
| 1090 | { .name = "sendmsg", .errmsg = true, |
| 1091 | .arg_scnprintf = { [2] = SCA_MSG_FLAGS, /* flags */ }, }, |
| 1092 | { .name = "sendto", .errmsg = true, |
| 1093 | .arg_scnprintf = { [3] = SCA_MSG_FLAGS, /* flags */ }, }, |
Arnaldo Carvalho de Melo | 453350d | 2013-09-20 12:13:37 -0300 | [diff] [blame] | 1094 | { .name = "setitimer", .errmsg = true, STRARRAY(0, which, itimers), }, |
| 1095 | { .name = "setrlimit", .errmsg = true, STRARRAY(0, resource, rlimit_resources), }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1096 | { .name = "shutdown", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1097 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 1098 | { .name = "socket", .errmsg = true, |
Arnaldo Carvalho de Melo | a28b24b | 2013-09-04 11:00:44 -0300 | [diff] [blame] | 1099 | .arg_scnprintf = { [0] = SCA_STRARRAY, /* family */ |
| 1100 | [1] = SCA_SK_TYPE, /* type */ }, |
Arnaldo Carvalho de Melo | e10bce8 | 2013-09-04 10:27:41 -0300 | [diff] [blame] | 1101 | .arg_parm = { [0] = &strarray__socket_families, /* family */ }, }, |
Arnaldo Carvalho de Melo | 07120aa | 2013-09-20 12:24:20 -0300 | [diff] [blame] | 1102 | { .name = "socketpair", .errmsg = true, |
| 1103 | .arg_scnprintf = { [0] = SCA_STRARRAY, /* family */ |
| 1104 | [1] = SCA_SK_TYPE, /* type */ }, |
| 1105 | .arg_parm = { [0] = &strarray__socket_families, /* family */ }, }, |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1106 | { .name = "stat", .errmsg = true, .alias = "newstat", }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1107 | { .name = "symlinkat", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1108 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
Arnaldo Carvalho de Melo | 8bad5b0 | 2013-09-03 17:17:15 -0300 | [diff] [blame] | 1109 | { .name = "tgkill", .errmsg = true, |
| 1110 | .arg_scnprintf = { [2] = SCA_SIGNUM, /* sig */ }, }, |
| 1111 | { .name = "tkill", .errmsg = true, |
| 1112 | .arg_scnprintf = { [1] = SCA_SIGNUM, /* sig */ }, }, |
Arnaldo Carvalho de Melo | e595968 | 2013-08-26 12:21:41 -0300 | [diff] [blame] | 1113 | { .name = "uname", .errmsg = true, .alias = "newuname", }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1114 | { .name = "unlinkat", .errmsg = true, |
| 1115 | .arg_scnprintf = { [0] = SCA_FDAT, /* dfd */ }, }, |
| 1116 | { .name = "utimensat", .errmsg = true, |
| 1117 | .arg_scnprintf = { [0] = SCA_FDAT, /* dirfd */ }, }, |
| 1118 | { .name = "write", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1119 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1120 | { .name = "writev", .errmsg = true, |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1121 | .arg_scnprintf = { [0] = SCA_FD, /* fd */ }, }, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1122 | }; |
| 1123 | |
| 1124 | static int syscall_fmt__cmp(const void *name, const void *fmtp) |
| 1125 | { |
| 1126 | const struct syscall_fmt *fmt = fmtp; |
| 1127 | return strcmp(name, fmt->name); |
| 1128 | } |
| 1129 | |
| 1130 | static struct syscall_fmt *syscall_fmt__find(const char *name) |
| 1131 | { |
| 1132 | const int nmemb = ARRAY_SIZE(syscall_fmts); |
| 1133 | return bsearch(name, syscall_fmts, nmemb, sizeof(struct syscall_fmt), syscall_fmt__cmp); |
| 1134 | } |
| 1135 | |
| 1136 | struct syscall { |
| 1137 | struct event_format *tp_format; |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1138 | int nr_args; |
| 1139 | struct format_field *args; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1140 | const char *name; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1141 | bool filtered; |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1142 | bool is_exit; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1143 | struct syscall_fmt *fmt; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1144 | size_t (**arg_scnprintf)(char *bf, size_t size, struct syscall_arg *arg); |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1145 | void **arg_parm; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1146 | }; |
| 1147 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1148 | static size_t fprintf_duration(unsigned long t, FILE *fp) |
| 1149 | { |
| 1150 | double duration = (double)t / NSEC_PER_MSEC; |
| 1151 | size_t printed = fprintf(fp, "("); |
| 1152 | |
| 1153 | if (duration >= 1.0) |
| 1154 | printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration); |
| 1155 | else if (duration >= 0.01) |
| 1156 | printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration); |
| 1157 | else |
| 1158 | 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] | 1159 | return printed + fprintf(fp, "): "); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1162 | struct thread_trace { |
| 1163 | u64 entry_time; |
| 1164 | u64 exit_time; |
| 1165 | bool entry_pending; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1166 | unsigned long nr_events; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 1167 | unsigned long pfmaj, pfmin; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1168 | char *entry_str; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1169 | double runtime_ms; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1170 | struct { |
| 1171 | int max; |
| 1172 | char **table; |
| 1173 | } paths; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1174 | |
| 1175 | struct intlist *syscall_stats; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1176 | }; |
| 1177 | |
| 1178 | static struct thread_trace *thread_trace__new(void) |
| 1179 | { |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1180 | struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); |
| 1181 | |
| 1182 | if (ttrace) |
| 1183 | ttrace->paths.max = -1; |
| 1184 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1185 | ttrace->syscall_stats = intlist__new(NULL); |
| 1186 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1187 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1188 | } |
| 1189 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1190 | 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] | 1191 | { |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1192 | struct thread_trace *ttrace; |
| 1193 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1194 | if (thread == NULL) |
| 1195 | goto fail; |
| 1196 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1197 | if (thread__priv(thread) == NULL) |
| 1198 | thread__set_priv(thread, thread_trace__new()); |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 1199 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1200 | if (thread__priv(thread) == NULL) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1201 | goto fail; |
| 1202 | |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1203 | ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1204 | ++ttrace->nr_events; |
| 1205 | |
| 1206 | return ttrace; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1207 | fail: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1208 | color_fprintf(fp, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1209 | "WARNING: not enough memory, dropping samples!\n"); |
| 1210 | return NULL; |
| 1211 | } |
| 1212 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1213 | #define TRACE_PFMAJ (1 << 0) |
| 1214 | #define TRACE_PFMIN (1 << 1) |
| 1215 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1216 | struct trace { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1217 | struct perf_tool tool; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1218 | struct { |
| 1219 | int machine; |
| 1220 | int open_id; |
| 1221 | } audit; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1222 | struct { |
| 1223 | int max; |
| 1224 | struct syscall *table; |
| 1225 | } syscalls; |
Arnaldo Carvalho de Melo | b400679 | 2013-12-19 14:43:45 -0300 | [diff] [blame] | 1226 | struct record_opts opts; |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 1227 | struct perf_evlist *evlist; |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1228 | struct machine *host; |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1229 | struct thread *current; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1230 | u64 base_time; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1231 | FILE *output; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 1232 | unsigned long nr_events; |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 1233 | struct strlist *ev_qualifier; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1234 | const char *last_vfs_getname; |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 1235 | struct intlist *tid_list; |
| 1236 | struct intlist *pid_list; |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 1237 | struct { |
| 1238 | size_t nr; |
| 1239 | pid_t *entries; |
| 1240 | } filter_pids; |
Arnaldo Carvalho de Melo | 98eafce | 2014-01-06 15:43:02 -0300 | [diff] [blame] | 1241 | double duration_filter; |
| 1242 | double runtime_ms; |
| 1243 | struct { |
| 1244 | u64 vfs_getname, |
| 1245 | proc_getname; |
| 1246 | } stats; |
| 1247 | bool not_ev_qualifier; |
| 1248 | bool live; |
| 1249 | bool full_time; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1250 | bool sched; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1251 | bool multiple_threads; |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1252 | bool summary; |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 1253 | bool summary_only; |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1254 | bool show_comm; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1255 | bool show_tool_stats; |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 1256 | bool trace_syscalls; |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 1257 | bool force; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1258 | int trace_pgfaults; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1259 | }; |
| 1260 | |
Arnaldo Carvalho de Melo | 97119f3 | 2013-09-27 17:34:10 -0300 | [diff] [blame] | 1261 | 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] | 1262 | { |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1263 | struct thread_trace *ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1264 | |
| 1265 | if (fd > ttrace->paths.max) { |
| 1266 | char **npath = realloc(ttrace->paths.table, (fd + 1) * sizeof(char *)); |
| 1267 | |
| 1268 | if (npath == NULL) |
| 1269 | return -1; |
| 1270 | |
| 1271 | if (ttrace->paths.max != -1) { |
| 1272 | memset(npath + ttrace->paths.max + 1, 0, |
| 1273 | (fd - ttrace->paths.max) * sizeof(char *)); |
| 1274 | } else { |
| 1275 | memset(npath, 0, (fd + 1) * sizeof(char *)); |
| 1276 | } |
| 1277 | |
| 1278 | ttrace->paths.table = npath; |
| 1279 | ttrace->paths.max = fd; |
| 1280 | } |
| 1281 | |
| 1282 | ttrace->paths.table[fd] = strdup(pathname); |
| 1283 | |
| 1284 | return ttrace->paths.table[fd] != NULL ? 0 : -1; |
| 1285 | } |
| 1286 | |
Arnaldo Carvalho de Melo | 97119f3 | 2013-09-27 17:34:10 -0300 | [diff] [blame] | 1287 | static int thread__read_fd_path(struct thread *thread, int fd) |
| 1288 | { |
| 1289 | char linkname[PATH_MAX], pathname[PATH_MAX]; |
| 1290 | struct stat st; |
| 1291 | int ret; |
| 1292 | |
| 1293 | if (thread->pid_ == thread->tid) { |
| 1294 | scnprintf(linkname, sizeof(linkname), |
| 1295 | "/proc/%d/fd/%d", thread->pid_, fd); |
| 1296 | } else { |
| 1297 | scnprintf(linkname, sizeof(linkname), |
| 1298 | "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd); |
| 1299 | } |
| 1300 | |
| 1301 | if (lstat(linkname, &st) < 0 || st.st_size + 1 > (off_t)sizeof(pathname)) |
| 1302 | return -1; |
| 1303 | |
| 1304 | ret = readlink(linkname, pathname, sizeof(pathname)); |
| 1305 | |
| 1306 | if (ret < 0 || ret > st.st_size) |
| 1307 | return -1; |
| 1308 | |
| 1309 | pathname[ret] = '\0'; |
| 1310 | return trace__set_fd_pathname(thread, fd, pathname); |
| 1311 | } |
| 1312 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1313 | static const char *thread__fd_path(struct thread *thread, int fd, |
| 1314 | struct trace *trace) |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1315 | { |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1316 | struct thread_trace *ttrace = thread__priv(thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1317 | |
| 1318 | if (ttrace == NULL) |
| 1319 | return NULL; |
| 1320 | |
| 1321 | if (fd < 0) |
| 1322 | return NULL; |
| 1323 | |
Arnaldo Carvalho de Melo | cdcd1e6 | 2014-06-10 16:00:18 -0300 | [diff] [blame] | 1324 | if ((fd > ttrace->paths.max || ttrace->paths.table[fd] == NULL)) { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1325 | if (!trace->live) |
| 1326 | return NULL; |
| 1327 | ++trace->stats.proc_getname; |
Arnaldo Carvalho de Melo | cdcd1e6 | 2014-06-10 16:00:18 -0300 | [diff] [blame] | 1328 | if (thread__read_fd_path(thread, fd)) |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1329 | return NULL; |
| 1330 | } |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1331 | |
| 1332 | return ttrace->paths.table[fd]; |
| 1333 | } |
| 1334 | |
| 1335 | static size_t syscall_arg__scnprintf_fd(char *bf, size_t size, |
| 1336 | struct syscall_arg *arg) |
| 1337 | { |
| 1338 | int fd = arg->val; |
| 1339 | size_t printed = scnprintf(bf, size, "%d", fd); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1340 | 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] | 1341 | |
| 1342 | if (path) |
| 1343 | printed += scnprintf(bf + printed, size - printed, "<%s>", path); |
| 1344 | |
| 1345 | return printed; |
| 1346 | } |
| 1347 | |
| 1348 | static size_t syscall_arg__scnprintf_close_fd(char *bf, size_t size, |
| 1349 | struct syscall_arg *arg) |
| 1350 | { |
| 1351 | int fd = arg->val; |
| 1352 | size_t printed = syscall_arg__scnprintf_fd(bf, size, arg); |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 1353 | struct thread_trace *ttrace = thread__priv(arg->thread); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1354 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1355 | if (ttrace && fd >= 0 && fd <= ttrace->paths.max) |
| 1356 | zfree(&ttrace->paths.table[fd]); |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1357 | |
| 1358 | return printed; |
| 1359 | } |
| 1360 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1361 | static bool trace__filter_duration(struct trace *trace, double t) |
| 1362 | { |
| 1363 | return t < (trace->duration_filter * NSEC_PER_MSEC); |
| 1364 | } |
| 1365 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1366 | static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp) |
| 1367 | { |
| 1368 | double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; |
| 1369 | |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1370 | return fprintf(fp, "%10.3f ", ts); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1371 | } |
| 1372 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1373 | static bool done = false; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1374 | static bool interrupted = false; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1375 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1376 | static void sig_handler(int sig) |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1377 | { |
| 1378 | done = true; |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 1379 | interrupted = sig == SIGINT; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 1380 | } |
| 1381 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1382 | static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1383 | u64 duration, u64 tstamp, FILE *fp) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1384 | { |
| 1385 | size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1386 | printed += fprintf_duration(duration, fp); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1387 | |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1388 | if (trace->multiple_threads) { |
| 1389 | if (trace->show_comm) |
Frederic Weisbecker | 1902efe | 2013-09-11 16:56:44 +0200 | [diff] [blame] | 1390 | printed += fprintf(fp, "%.14s/", thread__comm_str(thread)); |
Adrian Hunter | 3805123 | 2013-07-04 16:20:31 +0300 | [diff] [blame] | 1391 | printed += fprintf(fp, "%d ", thread->tid); |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 1392 | } |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1393 | |
| 1394 | return printed; |
| 1395 | } |
| 1396 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1397 | static int trace__process_event(struct trace *trace, struct machine *machine, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1398 | union perf_event *event, struct perf_sample *sample) |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1399 | { |
| 1400 | int ret = 0; |
| 1401 | |
| 1402 | switch (event->header.type) { |
| 1403 | case PERF_RECORD_LOST: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1404 | color_fprintf(trace->output, PERF_COLOR_RED, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1405 | "LOST %" PRIu64 " events!\n", event->lost.lost); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1406 | ret = machine__process_lost_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1407 | default: |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1408 | ret = machine__process_event(machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1409 | break; |
| 1410 | } |
| 1411 | |
| 1412 | return ret; |
| 1413 | } |
| 1414 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1415 | static int trace__tool_process(struct perf_tool *tool, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1416 | union perf_event *event, |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1417 | struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1418 | struct machine *machine) |
| 1419 | { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1420 | struct trace *trace = container_of(tool, struct trace, tool); |
Frederic Weisbecker | 162f0be | 2013-09-11 16:18:24 +0200 | [diff] [blame] | 1421 | return trace__process_event(trace, machine, event, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist) |
| 1425 | { |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 1426 | int err = symbol__init(NULL); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1427 | |
| 1428 | if (err) |
| 1429 | return err; |
| 1430 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1431 | trace->host = machine__new_host(); |
| 1432 | if (trace->host == NULL) |
| 1433 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1434 | |
Arnaldo Carvalho de Melo | a33fbd5 | 2013-11-11 11:36:12 -0300 | [diff] [blame] | 1435 | err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, |
| 1436 | evlist->threads, trace__tool_process, false); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1437 | if (err) |
| 1438 | symbol__exit(); |
| 1439 | |
| 1440 | return err; |
| 1441 | } |
| 1442 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1443 | static int syscall__set_arg_fmts(struct syscall *sc) |
| 1444 | { |
| 1445 | struct format_field *field; |
| 1446 | int idx = 0; |
| 1447 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1448 | sc->arg_scnprintf = calloc(sc->nr_args, sizeof(void *)); |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1449 | if (sc->arg_scnprintf == NULL) |
| 1450 | return -1; |
| 1451 | |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1452 | if (sc->fmt) |
| 1453 | sc->arg_parm = sc->fmt->arg_parm; |
| 1454 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1455 | for (field = sc->args; field; field = field->next) { |
Arnaldo Carvalho de Melo | beccb2b | 2013-08-26 12:29:38 -0300 | [diff] [blame] | 1456 | if (sc->fmt && sc->fmt->arg_scnprintf[idx]) |
| 1457 | sc->arg_scnprintf[idx] = sc->fmt->arg_scnprintf[idx]; |
| 1458 | else if (field->flags & FIELD_IS_POINTER) |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1459 | sc->arg_scnprintf[idx] = syscall_arg__scnprintf_hex; |
| 1460 | ++idx; |
| 1461 | } |
| 1462 | |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1466 | static int trace__read_syscall_info(struct trace *trace, int id) |
| 1467 | { |
| 1468 | char tp_name[128]; |
| 1469 | struct syscall *sc; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1470 | const char *name = audit_syscall_to_name(id, trace->audit.machine); |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1471 | |
| 1472 | if (name == NULL) |
| 1473 | return -1; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1474 | |
| 1475 | if (id > trace->syscalls.max) { |
| 1476 | struct syscall *nsyscalls = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); |
| 1477 | |
| 1478 | if (nsyscalls == NULL) |
| 1479 | return -1; |
| 1480 | |
| 1481 | if (trace->syscalls.max != -1) { |
| 1482 | memset(nsyscalls + trace->syscalls.max + 1, 0, |
| 1483 | (id - trace->syscalls.max) * sizeof(*sc)); |
| 1484 | } else { |
| 1485 | memset(nsyscalls, 0, (id + 1) * sizeof(*sc)); |
| 1486 | } |
| 1487 | |
| 1488 | trace->syscalls.table = nsyscalls; |
| 1489 | trace->syscalls.max = id; |
| 1490 | } |
| 1491 | |
| 1492 | sc = trace->syscalls.table + id; |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1493 | sc->name = name; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1494 | |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 1495 | if (trace->ev_qualifier) { |
| 1496 | bool in = strlist__find(trace->ev_qualifier, name) != NULL; |
| 1497 | |
| 1498 | if (!(in ^ trace->not_ev_qualifier)) { |
| 1499 | sc->filtered = true; |
| 1500 | /* |
| 1501 | * No need to do read tracepoint information since this will be |
| 1502 | * filtered out. |
| 1503 | */ |
| 1504 | return 0; |
| 1505 | } |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1506 | } |
| 1507 | |
Arnaldo Carvalho de Melo | 3a53126 | 2012-10-20 12:39:03 -0300 | [diff] [blame] | 1508 | sc->fmt = syscall_fmt__find(sc->name); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1509 | |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1510 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1511 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1512 | |
| 1513 | if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) { |
| 1514 | snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 1515 | sc->tp_format = trace_event__tp_format("syscalls", tp_name); |
Arnaldo Carvalho de Melo | aec1930 | 2012-09-27 13:16:00 -0300 | [diff] [blame] | 1516 | } |
| 1517 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1518 | if (sc->tp_format == NULL) |
| 1519 | return -1; |
| 1520 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1521 | sc->args = sc->tp_format->format.fields; |
| 1522 | sc->nr_args = sc->tp_format->format.nr_fields; |
| 1523 | /* drop nr field - not relevant here; does not exist on older kernels */ |
| 1524 | if (sc->args && strcmp(sc->args->name, "nr") == 0) { |
| 1525 | sc->args = sc->args->next; |
| 1526 | --sc->nr_args; |
| 1527 | } |
| 1528 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1529 | sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); |
| 1530 | |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1531 | return syscall__set_arg_fmts(sc); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1532 | } |
| 1533 | |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1534 | /* |
| 1535 | * args is to be interpreted as a series of longs but we need to handle |
| 1536 | * 8-byte unaligned accesses. args points to raw_data within the event |
| 1537 | * and raw_data is guaranteed to be 8-byte unaligned because it is |
| 1538 | * preceded by raw_size which is a u32. So we need to copy args to a temp |
| 1539 | * variable to read it. Most notably this avoids extended load instructions |
| 1540 | * on unaligned addresses |
| 1541 | */ |
| 1542 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1543 | static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1544 | unsigned char *args, struct trace *trace, |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1545 | struct thread *thread) |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1546 | { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1547 | size_t printed = 0; |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1548 | unsigned char *p; |
| 1549 | unsigned long val; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1550 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1551 | if (sc->args != NULL) { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1552 | struct format_field *field; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1553 | u8 bit = 1; |
| 1554 | struct syscall_arg arg = { |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1555 | .idx = 0, |
| 1556 | .mask = 0, |
| 1557 | .trace = trace, |
| 1558 | .thread = thread, |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1559 | }; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1560 | |
Arnaldo Carvalho de Melo | f208bd8 | 2015-03-20 17:46:53 -0300 | [diff] [blame] | 1561 | for (field = sc->args; field; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1562 | field = field->next, ++arg.idx, bit <<= 1) { |
| 1563 | if (arg.mask & bit) |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1564 | continue; |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1565 | |
| 1566 | /* special care for unaligned accesses */ |
| 1567 | p = args + sizeof(unsigned long) * arg.idx; |
| 1568 | memcpy(&val, p, sizeof(val)); |
| 1569 | |
Arnaldo Carvalho de Melo | 4aa5823 | 2013-09-20 12:19:41 -0300 | [diff] [blame] | 1570 | /* |
| 1571 | * Suppress this argument if its value is zero and |
| 1572 | * and we don't have a string associated in an |
| 1573 | * strarray for it. |
| 1574 | */ |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1575 | if (val == 0 && |
Arnaldo Carvalho de Melo | 4aa5823 | 2013-09-20 12:19:41 -0300 | [diff] [blame] | 1576 | !(sc->arg_scnprintf && |
| 1577 | sc->arg_scnprintf[arg.idx] == SCA_STRARRAY && |
| 1578 | sc->arg_parm[arg.idx])) |
Arnaldo Carvalho de Melo | 22ae5cf1 | 2013-09-12 11:27:34 -0300 | [diff] [blame] | 1579 | continue; |
| 1580 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1581 | printed += scnprintf(bf + printed, size - printed, |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1582 | "%s%s: ", printed ? ", " : "", field->name); |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1583 | if (sc->arg_scnprintf && sc->arg_scnprintf[arg.idx]) { |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1584 | arg.val = val; |
Arnaldo Carvalho de Melo | 1f115cb | 2013-09-03 15:50:28 -0300 | [diff] [blame] | 1585 | if (sc->arg_parm) |
| 1586 | arg.parm = sc->arg_parm[arg.idx]; |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1587 | printed += sc->arg_scnprintf[arg.idx](bf + printed, |
| 1588 | size - printed, &arg); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1589 | } else { |
Arnaldo Carvalho de Melo | 13d4ff3 | 2013-08-23 18:14:48 -0300 | [diff] [blame] | 1590 | printed += scnprintf(bf + printed, size - printed, |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1591 | "%ld", val); |
Arnaldo Carvalho de Melo | 6e7eeb5 | 2013-09-02 10:39:21 -0300 | [diff] [blame] | 1592 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1593 | } |
| 1594 | } else { |
Arnaldo Carvalho de Melo | 01533e9 | 2013-09-03 12:20:12 -0300 | [diff] [blame] | 1595 | int i = 0; |
| 1596 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1597 | while (i < 6) { |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1598 | /* special care for unaligned accesses */ |
| 1599 | p = args + sizeof(unsigned long) * i; |
| 1600 | memcpy(&val, p, sizeof(val)); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1601 | printed += scnprintf(bf + printed, size - printed, |
| 1602 | "%sarg%d: %ld", |
David Ahern | 55d43bc | 2015-02-19 15:00:22 -0500 | [diff] [blame] | 1603 | printed ? ", " : "", i, val); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 1604 | ++i; |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | return printed; |
| 1609 | } |
| 1610 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1611 | typedef int (*tracepoint_handler)(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1612 | union perf_event *event, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1613 | struct perf_sample *sample); |
| 1614 | |
| 1615 | static struct syscall *trace__syscall_info(struct trace *trace, |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1616 | struct perf_evsel *evsel, int id) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1617 | { |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1618 | |
| 1619 | if (id < 0) { |
Arnaldo Carvalho de Melo | adaa18b | 2013-08-22 17:55:25 -0300 | [diff] [blame] | 1620 | |
| 1621 | /* |
| 1622 | * XXX: Noticed on x86_64, reproduced as far back as 3.0.36, haven't tried |
| 1623 | * before that, leaving at a higher verbosity level till that is |
| 1624 | * explained. Reproduced with plain ftrace with: |
| 1625 | * |
| 1626 | * echo 1 > /t/events/raw_syscalls/sys_exit/enable |
| 1627 | * grep "NR -1 " /t/trace_pipe |
| 1628 | * |
| 1629 | * After generating some load on the machine. |
| 1630 | */ |
| 1631 | if (verbose > 1) { |
| 1632 | static u64 n; |
| 1633 | fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n", |
| 1634 | id, perf_evsel__name(evsel), ++n); |
| 1635 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1636 | return NULL; |
| 1637 | } |
| 1638 | |
| 1639 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL) && |
| 1640 | trace__read_syscall_info(trace, id)) |
| 1641 | goto out_cant_read; |
| 1642 | |
| 1643 | if ((id > trace->syscalls.max || trace->syscalls.table[id].name == NULL)) |
| 1644 | goto out_cant_read; |
| 1645 | |
| 1646 | return &trace->syscalls.table[id]; |
| 1647 | |
| 1648 | out_cant_read: |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 1649 | if (verbose) { |
| 1650 | fprintf(trace->output, "Problems reading syscall %d", id); |
| 1651 | if (id <= trace->syscalls.max && trace->syscalls.table[id].name != NULL) |
| 1652 | fprintf(trace->output, "(%s)", trace->syscalls.table[id].name); |
| 1653 | fputs(" information\n", trace->output); |
| 1654 | } |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1655 | return NULL; |
| 1656 | } |
| 1657 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1658 | static void thread__update_stats(struct thread_trace *ttrace, |
| 1659 | int id, struct perf_sample *sample) |
| 1660 | { |
| 1661 | struct int_node *inode; |
| 1662 | struct stats *stats; |
| 1663 | u64 duration = 0; |
| 1664 | |
| 1665 | inode = intlist__findnew(ttrace->syscall_stats, id); |
| 1666 | if (inode == NULL) |
| 1667 | return; |
| 1668 | |
| 1669 | stats = inode->priv; |
| 1670 | if (stats == NULL) { |
| 1671 | stats = malloc(sizeof(struct stats)); |
| 1672 | if (stats == NULL) |
| 1673 | return; |
| 1674 | init_stats(stats); |
| 1675 | inode->priv = stats; |
| 1676 | } |
| 1677 | |
| 1678 | if (ttrace->entry_time && sample->time > ttrace->entry_time) |
| 1679 | duration = sample->time - ttrace->entry_time; |
| 1680 | |
| 1681 | update_stats(stats, duration); |
| 1682 | } |
| 1683 | |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1684 | static int trace__printf_interrupted_entry(struct trace *trace, struct perf_sample *sample) |
| 1685 | { |
| 1686 | struct thread_trace *ttrace; |
| 1687 | u64 duration; |
| 1688 | size_t printed; |
| 1689 | |
| 1690 | if (trace->current == NULL) |
| 1691 | return 0; |
| 1692 | |
| 1693 | ttrace = thread__priv(trace->current); |
| 1694 | |
| 1695 | if (!ttrace->entry_pending) |
| 1696 | return 0; |
| 1697 | |
| 1698 | duration = sample->time - ttrace->entry_time; |
| 1699 | |
| 1700 | printed = trace__fprintf_entry_head(trace, trace->current, duration, sample->time, trace->output); |
| 1701 | printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str); |
| 1702 | ttrace->entry_pending = false; |
| 1703 | |
| 1704 | return printed; |
| 1705 | } |
| 1706 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1707 | static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1708 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1709 | struct perf_sample *sample) |
| 1710 | { |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1711 | char *msg; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1712 | void *args; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1713 | size_t printed = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1714 | struct thread *thread; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 1715 | int id = perf_evsel__sc_tp_uint(evsel, id, sample); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1716 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1717 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1718 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1719 | if (sc == NULL) |
| 1720 | return -1; |
| 1721 | |
| 1722 | if (sc->filtered) |
| 1723 | return 0; |
| 1724 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1725 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1726 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1727 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1728 | return -1; |
| 1729 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 1730 | args = perf_evsel__sc_tp_ptr(evsel, args, sample); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1731 | |
| 1732 | if (ttrace->entry_str == NULL) { |
| 1733 | ttrace->entry_str = malloc(1024); |
| 1734 | if (!ttrace->entry_str) |
| 1735 | return -1; |
| 1736 | } |
| 1737 | |
David Ahern | 13f22a2 | 2015-03-19 12:23:03 -0600 | [diff] [blame] | 1738 | if (!trace->summary_only) |
Arnaldo Carvalho de Melo | 6ebad5c | 2015-03-25 18:01:15 -0300 | [diff] [blame] | 1739 | trace__printf_interrupted_entry(trace, sample); |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1740 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1741 | ttrace->entry_time = sample->time; |
| 1742 | msg = ttrace->entry_str; |
| 1743 | printed += scnprintf(msg + printed, 1024 - printed, "%s(", sc->name); |
| 1744 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 1745 | printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, |
| 1746 | args, trace, thread); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1747 | |
Arnaldo Carvalho de Melo | 5089f20 | 2014-06-17 14:29:24 -0300 | [diff] [blame] | 1748 | if (sc->is_exit) { |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 1749 | if (!trace->duration_filter && !trace->summary_only) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1750 | trace__fprintf_entry_head(trace, thread, 1, sample->time, trace->output); |
| 1751 | fprintf(trace->output, "%-70s\n", ttrace->entry_str); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1752 | } |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1753 | } else |
| 1754 | ttrace->entry_pending = true; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1755 | |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 1756 | if (trace->current != thread) { |
| 1757 | thread__put(trace->current); |
| 1758 | trace->current = thread__get(thread); |
| 1759 | } |
Arnaldo Carvalho de Melo | e596663 | 2015-02-13 13:22:21 -0300 | [diff] [blame] | 1760 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1765 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1766 | struct perf_sample *sample) |
| 1767 | { |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 1768 | long ret; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1769 | u64 duration = 0; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1770 | struct thread *thread; |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 1771 | int id = perf_evsel__sc_tp_uint(evsel, id, sample); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1772 | struct syscall *sc = trace__syscall_info(trace, evsel, id); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1773 | struct thread_trace *ttrace; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1774 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1775 | if (sc == NULL) |
| 1776 | return -1; |
| 1777 | |
| 1778 | if (sc->filtered) |
| 1779 | return 0; |
| 1780 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1781 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1782 | ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 1783 | if (ttrace == NULL) |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1784 | return -1; |
| 1785 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 1786 | if (trace->summary) |
| 1787 | thread__update_stats(ttrace, id, sample); |
| 1788 | |
Arnaldo Carvalho de Melo | 7717098 | 2013-11-06 16:35:57 -0300 | [diff] [blame] | 1789 | ret = perf_evsel__sc_tp_uint(evsel, ret, sample); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1790 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1791 | if (id == trace->audit.open_id && ret >= 0 && trace->last_vfs_getname) { |
| 1792 | trace__set_fd_pathname(thread, ret, trace->last_vfs_getname); |
| 1793 | trace->last_vfs_getname = NULL; |
| 1794 | ++trace->stats.vfs_getname; |
| 1795 | } |
| 1796 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1797 | ttrace->exit_time = sample->time; |
| 1798 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1799 | if (ttrace->entry_time) { |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1800 | duration = sample->time - ttrace->entry_time; |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1801 | if (trace__filter_duration(trace, duration)) |
| 1802 | goto out; |
| 1803 | } else if (trace->duration_filter) |
| 1804 | goto out; |
Arnaldo Carvalho de Melo | 60c907a | 2012-10-24 17:24:47 -0200 | [diff] [blame] | 1805 | |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 1806 | if (trace->summary_only) |
| 1807 | goto out; |
| 1808 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1809 | trace__fprintf_entry_head(trace, thread, duration, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1810 | |
| 1811 | if (ttrace->entry_pending) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1812 | fprintf(trace->output, "%-70s", ttrace->entry_str); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1813 | } else { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1814 | fprintf(trace->output, " ... ["); |
| 1815 | color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued"); |
| 1816 | fprintf(trace->output, "]: %s()", sc->name); |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1817 | } |
| 1818 | |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 1819 | if (sc->fmt == NULL) { |
| 1820 | signed_print: |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 1821 | fprintf(trace->output, ") = %ld", ret); |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 1822 | } else if (ret < 0 && sc->fmt->errmsg) { |
Masami Hiramatsu | 942a91e | 2014-08-14 02:22:41 +0000 | [diff] [blame] | 1823 | char bf[STRERR_BUFSIZE]; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1824 | const char *emsg = strerror_r(-ret, bf, sizeof(bf)), |
| 1825 | *e = audit_errno_to_name(-ret); |
| 1826 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1827 | fprintf(trace->output, ") = -1 %s %s", e, emsg); |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 1828 | } else if (ret == 0 && sc->fmt->timeout) |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1829 | fprintf(trace->output, ") = 0 Timeout"); |
Arnaldo Carvalho de Melo | 04b3472 | 2013-08-26 11:36:30 -0300 | [diff] [blame] | 1830 | else if (sc->fmt->hexret) |
Chang Hyun Park | 2c82c3a | 2014-09-26 21:54:01 +0900 | [diff] [blame] | 1831 | fprintf(trace->output, ") = %#lx", ret); |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1832 | else |
Arnaldo Carvalho de Melo | da3c9a4 | 2013-08-26 11:28:34 -0300 | [diff] [blame] | 1833 | goto signed_print; |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1834 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1835 | fputc('\n', trace->output); |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 1836 | out: |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 1837 | ttrace->entry_pending = false; |
| 1838 | |
Arnaldo Carvalho de Melo | ba3d7de | 2012-09-28 17:58:36 -0300 | [diff] [blame] | 1839 | return 0; |
| 1840 | } |
| 1841 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1842 | static int trace__vfs_getname(struct trace *trace, struct perf_evsel *evsel, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1843 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 1844 | struct perf_sample *sample) |
| 1845 | { |
| 1846 | trace->last_vfs_getname = perf_evsel__rawptr(evsel, sample, "pathname"); |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1850 | 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] | 1851 | union perf_event *event __maybe_unused, |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1852 | struct perf_sample *sample) |
| 1853 | { |
| 1854 | u64 runtime = perf_evsel__intval(evsel, sample, "runtime"); |
| 1855 | double runtime_ms = (double)runtime / NSEC_PER_MSEC; |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 1856 | struct thread *thread = machine__findnew_thread(trace->host, |
Adrian Hunter | 314add6 | 2013-08-27 11:23:03 +0300 | [diff] [blame] | 1857 | sample->pid, |
| 1858 | sample->tid); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1859 | struct thread_trace *ttrace = thread__trace(thread, trace->output); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 1860 | |
| 1861 | if (ttrace == NULL) |
| 1862 | goto out_dump; |
| 1863 | |
| 1864 | ttrace->runtime_ms += runtime_ms; |
| 1865 | trace->runtime_ms += runtime_ms; |
| 1866 | return 0; |
| 1867 | |
| 1868 | out_dump: |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 1869 | 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] | 1870 | evsel->name, |
| 1871 | perf_evsel__strval(evsel, sample, "comm"), |
| 1872 | (pid_t)perf_evsel__intval(evsel, sample, "pid"), |
| 1873 | runtime, |
| 1874 | perf_evsel__intval(evsel, sample, "vruntime")); |
| 1875 | return 0; |
| 1876 | } |
| 1877 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 1878 | static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel, |
| 1879 | union perf_event *event __maybe_unused, |
| 1880 | struct perf_sample *sample) |
| 1881 | { |
| 1882 | trace__printf_interrupted_entry(trace, sample); |
| 1883 | trace__fprintf_tstamp(trace, sample->time, trace->output); |
Arnaldo Carvalho de Melo | 0808921 | 2015-02-19 21:51:50 -0800 | [diff] [blame] | 1884 | |
| 1885 | if (trace->trace_syscalls) |
| 1886 | fprintf(trace->output, "( ): "); |
| 1887 | |
| 1888 | fprintf(trace->output, "%s:", evsel->name); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 1889 | |
| 1890 | if (evsel->tp_format) { |
| 1891 | event_format__fprintf(evsel->tp_format, sample->cpu, |
| 1892 | sample->raw_data, sample->raw_size, |
| 1893 | trace->output); |
| 1894 | } |
| 1895 | |
| 1896 | fprintf(trace->output, ")\n"); |
| 1897 | return 0; |
| 1898 | } |
| 1899 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1900 | static void print_location(FILE *f, struct perf_sample *sample, |
| 1901 | struct addr_location *al, |
| 1902 | bool print_dso, bool print_sym) |
| 1903 | { |
| 1904 | |
| 1905 | if ((verbose || print_dso) && al->map) |
| 1906 | fprintf(f, "%s@", al->map->dso->long_name); |
| 1907 | |
| 1908 | if ((verbose || print_sym) && al->sym) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 1909 | fprintf(f, "%s+0x%" PRIx64, al->sym->name, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1910 | al->addr - al->sym->start); |
| 1911 | else if (al->map) |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 1912 | fprintf(f, "0x%" PRIx64, al->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1913 | else |
Arnaldo Carvalho de Melo | 4414a3c | 2014-07-08 15:39:21 -0300 | [diff] [blame] | 1914 | fprintf(f, "0x%" PRIx64, sample->addr); |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | static int trace__pgfault(struct trace *trace, |
| 1918 | struct perf_evsel *evsel, |
| 1919 | union perf_event *event, |
| 1920 | struct perf_sample *sample) |
| 1921 | { |
| 1922 | struct thread *thread; |
| 1923 | u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
| 1924 | struct addr_location al; |
| 1925 | char map_type = 'd'; |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 1926 | struct thread_trace *ttrace; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1927 | |
| 1928 | thread = machine__findnew_thread(trace->host, sample->pid, sample->tid); |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 1929 | ttrace = thread__trace(thread, trace->output); |
| 1930 | if (ttrace == NULL) |
| 1931 | return -1; |
| 1932 | |
| 1933 | if (evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ) |
| 1934 | ttrace->pfmaj++; |
| 1935 | else |
| 1936 | ttrace->pfmin++; |
| 1937 | |
| 1938 | if (trace->summary_only) |
| 1939 | return 0; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1940 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 1941 | thread__find_addr_location(thread, cpumode, MAP__FUNCTION, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1942 | sample->ip, &al); |
| 1943 | |
| 1944 | trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); |
| 1945 | |
| 1946 | fprintf(trace->output, "%sfault [", |
| 1947 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ? |
| 1948 | "maj" : "min"); |
| 1949 | |
| 1950 | print_location(trace->output, sample, &al, false, true); |
| 1951 | |
| 1952 | fprintf(trace->output, "] => "); |
| 1953 | |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 1954 | thread__find_addr_location(thread, cpumode, MAP__VARIABLE, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1955 | sample->addr, &al); |
| 1956 | |
| 1957 | if (!al.map) { |
Arnaldo Carvalho de Melo | bb871a9 | 2014-10-23 12:50:25 -0300 | [diff] [blame] | 1958 | thread__find_addr_location(thread, cpumode, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 1959 | MAP__FUNCTION, sample->addr, &al); |
| 1960 | |
| 1961 | if (al.map) |
| 1962 | map_type = 'x'; |
| 1963 | else |
| 1964 | map_type = '?'; |
| 1965 | } |
| 1966 | |
| 1967 | print_location(trace->output, sample, &al, true, false); |
| 1968 | |
| 1969 | fprintf(trace->output, " (%c%c)\n", map_type, al.level); |
| 1970 | |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 1974 | static bool skip_sample(struct trace *trace, struct perf_sample *sample) |
| 1975 | { |
| 1976 | if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) || |
| 1977 | (trace->tid_list && intlist__find(trace->tid_list, sample->tid))) |
| 1978 | return false; |
| 1979 | |
| 1980 | if (trace->pid_list || trace->tid_list) |
| 1981 | return true; |
| 1982 | |
| 1983 | return false; |
| 1984 | } |
| 1985 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1986 | static int trace__process_sample(struct perf_tool *tool, |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 1987 | union perf_event *event, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1988 | struct perf_sample *sample, |
| 1989 | struct perf_evsel *evsel, |
| 1990 | struct machine *machine __maybe_unused) |
| 1991 | { |
| 1992 | struct trace *trace = container_of(tool, struct trace, tool); |
| 1993 | int err = 0; |
| 1994 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 1995 | tracepoint_handler handler = evsel->handler; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 1996 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 1997 | if (skip_sample(trace, sample)) |
| 1998 | return 0; |
| 1999 | |
David Ahern | 4bb0919 | 2013-09-04 12:37:43 -0600 | [diff] [blame] | 2000 | if (!trace->full_time && trace->base_time == 0) |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2001 | trace->base_time = sample->time; |
| 2002 | |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2003 | if (handler) { |
| 2004 | ++trace->nr_events; |
Stanislav Fomichev | 0c82adc | 2014-06-26 20:14:24 +0400 | [diff] [blame] | 2005 | handler(trace, evsel, event, sample); |
David Ahern | 3160565 | 2013-12-04 19:41:41 -0700 | [diff] [blame] | 2006 | } |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2007 | |
| 2008 | return err; |
| 2009 | } |
| 2010 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2011 | static int parse_target_str(struct trace *trace) |
| 2012 | { |
| 2013 | if (trace->opts.target.pid) { |
| 2014 | trace->pid_list = intlist__new(trace->opts.target.pid); |
| 2015 | if (trace->pid_list == NULL) { |
| 2016 | pr_err("Error parsing process id string\n"); |
| 2017 | return -EINVAL; |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | if (trace->opts.target.tid) { |
| 2022 | trace->tid_list = intlist__new(trace->opts.target.tid); |
| 2023 | if (trace->tid_list == NULL) { |
| 2024 | pr_err("Error parsing thread id string\n"); |
| 2025 | return -EINVAL; |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2032 | static int trace__record(struct trace *trace, int argc, const char **argv) |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2033 | { |
| 2034 | unsigned int rec_argc, i, j; |
| 2035 | const char **rec_argv; |
| 2036 | const char * const record_args[] = { |
| 2037 | "record", |
| 2038 | "-R", |
| 2039 | "-m", "1024", |
| 2040 | "-c", "1", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2041 | }; |
| 2042 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2043 | const char * const sc_args[] = { "-e", }; |
| 2044 | unsigned int sc_args_nr = ARRAY_SIZE(sc_args); |
| 2045 | const char * const majpf_args[] = { "-e", "major-faults" }; |
| 2046 | unsigned int majpf_args_nr = ARRAY_SIZE(majpf_args); |
| 2047 | const char * const minpf_args[] = { "-e", "minor-faults" }; |
| 2048 | unsigned int minpf_args_nr = ARRAY_SIZE(minpf_args); |
| 2049 | |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2050 | /* +1 is for the event string below */ |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2051 | rec_argc = ARRAY_SIZE(record_args) + sc_args_nr + 1 + |
| 2052 | majpf_args_nr + minpf_args_nr + argc; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2053 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 2054 | |
| 2055 | if (rec_argv == NULL) |
| 2056 | return -ENOMEM; |
| 2057 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2058 | j = 0; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2059 | for (i = 0; i < ARRAY_SIZE(record_args); i++) |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2060 | rec_argv[j++] = record_args[i]; |
| 2061 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2062 | if (trace->trace_syscalls) { |
| 2063 | for (i = 0; i < sc_args_nr; i++) |
| 2064 | rec_argv[j++] = sc_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2065 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2066 | /* event string may be different for older kernels - e.g., RHEL6 */ |
| 2067 | if (is_valid_tracepoint("raw_syscalls:sys_enter")) |
| 2068 | rec_argv[j++] = "raw_syscalls:sys_enter,raw_syscalls:sys_exit"; |
| 2069 | else if (is_valid_tracepoint("syscalls:sys_enter")) |
| 2070 | rec_argv[j++] = "syscalls:sys_enter,syscalls:sys_exit"; |
| 2071 | else { |
| 2072 | pr_err("Neither raw_syscalls nor syscalls events exist.\n"); |
| 2073 | return -1; |
| 2074 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2075 | } |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2076 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2077 | if (trace->trace_pgfaults & TRACE_PFMAJ) |
| 2078 | for (i = 0; i < majpf_args_nr; i++) |
| 2079 | rec_argv[j++] = majpf_args[i]; |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2080 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2081 | if (trace->trace_pgfaults & TRACE_PFMIN) |
| 2082 | for (i = 0; i < minpf_args_nr; i++) |
| 2083 | rec_argv[j++] = minpf_args[i]; |
| 2084 | |
| 2085 | for (i = 0; i < (unsigned int)argc; i++) |
| 2086 | rec_argv[j++] = argv[i]; |
| 2087 | |
| 2088 | return cmd_record(j, rec_argv, NULL); |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2089 | } |
| 2090 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2091 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); |
| 2092 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2093 | static void perf_evlist__add_vfs_getname(struct perf_evlist *evlist) |
| 2094 | { |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 2095 | struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname"); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2096 | if (evsel == NULL) |
| 2097 | return; |
| 2098 | |
| 2099 | if (perf_evsel__field(evsel, "pathname") == NULL) { |
| 2100 | perf_evsel__delete(evsel); |
| 2101 | return; |
| 2102 | } |
| 2103 | |
Arnaldo Carvalho de Melo | 744a971 | 2013-11-06 10:17:38 -0300 | [diff] [blame] | 2104 | evsel->handler = trace__vfs_getname; |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2105 | perf_evlist__add(evlist, evsel); |
| 2106 | } |
| 2107 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2108 | static int perf_evlist__add_pgfault(struct perf_evlist *evlist, |
| 2109 | u64 config) |
| 2110 | { |
| 2111 | struct perf_evsel *evsel; |
| 2112 | struct perf_event_attr attr = { |
| 2113 | .type = PERF_TYPE_SOFTWARE, |
| 2114 | .mmap_data = 1, |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2115 | }; |
| 2116 | |
| 2117 | attr.config = config; |
Arnaldo Carvalho de Melo | 0524798 | 2014-07-23 18:15:09 -0300 | [diff] [blame] | 2118 | attr.sample_period = 1; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2119 | |
| 2120 | event_attr_init(&attr); |
| 2121 | |
| 2122 | evsel = perf_evsel__new(&attr); |
| 2123 | if (!evsel) |
| 2124 | return -ENOMEM; |
| 2125 | |
| 2126 | evsel->handler = trace__pgfault; |
| 2127 | perf_evlist__add(evlist, evsel); |
| 2128 | |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2132 | static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample) |
| 2133 | { |
| 2134 | const u32 type = event->header.type; |
| 2135 | struct perf_evsel *evsel; |
| 2136 | |
| 2137 | if (!trace->full_time && trace->base_time == 0) |
| 2138 | trace->base_time = sample->time; |
| 2139 | |
| 2140 | if (type != PERF_RECORD_SAMPLE) { |
| 2141 | trace__process_event(trace, trace->host, event, sample); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | evsel = perf_evlist__id2evsel(trace->evlist, sample->id); |
| 2146 | if (evsel == NULL) { |
| 2147 | fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
| 2151 | if (evsel->attr.type == PERF_TYPE_TRACEPOINT && |
| 2152 | sample->raw_data == NULL) { |
| 2153 | fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", |
| 2154 | perf_evsel__name(evsel), sample->tid, |
| 2155 | sample->cpu, sample->raw_size); |
| 2156 | } else { |
| 2157 | tracepoint_handler handler = evsel->handler; |
| 2158 | handler(trace, evsel, event, sample); |
| 2159 | } |
| 2160 | } |
| 2161 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2162 | 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] | 2163 | { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2164 | struct perf_evlist *evlist = trace->evlist; |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2165 | int err = -1, i; |
| 2166 | unsigned long before; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2167 | const bool forks = argc > 0; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2168 | bool draining = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2169 | |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 2170 | trace->live = true; |
| 2171 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2172 | if (trace->trace_syscalls && |
| 2173 | perf_evlist__add_syscall_newtp(evlist, trace__sys_enter, |
| 2174 | trace__sys_exit)) |
Arnaldo Carvalho de Melo | 801c67b | 2015-01-22 10:52:55 -0300 | [diff] [blame] | 2175 | goto out_error_raw_syscalls; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2176 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2177 | if (trace->trace_syscalls) |
| 2178 | perf_evlist__add_vfs_getname(evlist); |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2179 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2180 | if ((trace->trace_pgfaults & TRACE_PFMAJ) && |
Arnaldo Carvalho de Melo | e2726d9 | 2015-01-22 10:34:22 -0300 | [diff] [blame] | 2181 | perf_evlist__add_pgfault(evlist, PERF_COUNT_SW_PAGE_FAULTS_MAJ)) { |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2182 | goto out_error_mem; |
Arnaldo Carvalho de Melo | e2726d9 | 2015-01-22 10:34:22 -0300 | [diff] [blame] | 2183 | } |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2184 | |
| 2185 | if ((trace->trace_pgfaults & TRACE_PFMIN) && |
| 2186 | perf_evlist__add_pgfault(evlist, PERF_COUNT_SW_PAGE_FAULTS_MIN)) |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2187 | goto out_error_mem; |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2188 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2189 | if (trace->sched && |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2190 | perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime", |
| 2191 | trace__sched_stat_runtime)) |
| 2192 | goto out_error_sched_stat_runtime; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2193 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2194 | err = perf_evlist__create_maps(evlist, &trace->opts.target); |
| 2195 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2196 | 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] | 2197 | goto out_delete_evlist; |
| 2198 | } |
| 2199 | |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2200 | err = trace__symbols_init(trace, evlist); |
| 2201 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2202 | fprintf(trace->output, "Problems initializing symbol libraries!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 2203 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 752fde4 | 2012-10-06 18:43:19 -0300 | [diff] [blame] | 2204 | } |
| 2205 | |
Arnaldo Carvalho de Melo | f77a951 | 2012-12-10 16:41:31 -0300 | [diff] [blame] | 2206 | perf_evlist__config(evlist, &trace->opts); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2207 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2208 | signal(SIGCHLD, sig_handler); |
| 2209 | signal(SIGINT, sig_handler); |
| 2210 | |
| 2211 | if (forks) { |
Namhyung Kim | 6ef73ec | 2013-03-11 16:43:15 +0900 | [diff] [blame] | 2212 | err = perf_evlist__prepare_workload(evlist, &trace->opts.target, |
Arnaldo Carvalho de Melo | 735f7e0 | 2014-01-03 14:56:49 -0300 | [diff] [blame] | 2213 | argv, false, NULL); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2214 | if (err < 0) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2215 | fprintf(trace->output, "Couldn't run the workload!\n"); |
Arnaldo Carvalho de Melo | 03ad974 | 2014-01-03 15:56:06 -0300 | [diff] [blame] | 2216 | goto out_delete_evlist; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2220 | err = perf_evlist__open(evlist); |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2221 | if (err < 0) |
| 2222 | goto out_error_open; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2223 | |
Arnaldo Carvalho de Melo | 241b057 | 2015-02-21 10:15:21 -0800 | [diff] [blame] | 2224 | /* |
| 2225 | * Better not use !target__has_task() here because we need to cover the |
| 2226 | * case where no threads were specified in the command line, but a |
| 2227 | * workload was, and in that case we will fill in the thread_map when |
| 2228 | * we fork the workload in perf_evlist__prepare_workload. |
| 2229 | */ |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 2230 | if (trace->filter_pids.nr > 0) |
| 2231 | err = perf_evlist__set_filter_pids(evlist, trace->filter_pids.nr, trace->filter_pids.entries); |
| 2232 | else if (evlist->threads->map[0] == -1) |
| 2233 | err = perf_evlist__set_filter_pid(evlist, getpid()); |
| 2234 | |
| 2235 | if (err < 0) { |
| 2236 | printf("err=%d,%s\n", -err, strerror(-err)); |
| 2237 | exit(1); |
| 2238 | } |
Arnaldo Carvalho de Melo | 241b057 | 2015-02-21 10:15:21 -0800 | [diff] [blame] | 2239 | |
Jiri Olsa | f885037 | 2013-11-28 17:57:22 +0100 | [diff] [blame] | 2240 | err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false); |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 2241 | if (err < 0) |
| 2242 | goto out_error_mmap; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2243 | |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2244 | if (forks) |
| 2245 | perf_evlist__start_workload(evlist); |
Arnaldo Carvalho de Melo | f7aa222 | 2015-02-03 13:25:39 -0300 | [diff] [blame] | 2246 | else |
| 2247 | perf_evlist__enable(evlist); |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2248 | |
Arnaldo Carvalho de Melo | 42052be | 2015-02-13 12:32:45 -0300 | [diff] [blame] | 2249 | trace->multiple_threads = evlist->threads->map[0] == -1 || |
| 2250 | evlist->threads->nr > 1 || |
| 2251 | perf_evlist__first(evlist)->attr.inherit; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2252 | again: |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2253 | before = trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2254 | |
| 2255 | for (i = 0; i < evlist->nr_mmaps; i++) { |
| 2256 | union perf_event *event; |
| 2257 | |
| 2258 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2259 | struct perf_sample sample; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2260 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2261 | ++trace->nr_events; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2262 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2263 | err = perf_evlist__parse_sample(evlist, event, &sample); |
| 2264 | if (err) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2265 | fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 2266 | goto next_event; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2267 | } |
| 2268 | |
Arnaldo Carvalho de Melo | ddbb1b1 | 2015-02-21 12:10:29 -0800 | [diff] [blame] | 2269 | trace__handle_event(trace, event, &sample); |
Zhouyi Zhou | 8e50d38 | 2013-10-24 15:43:33 +0800 | [diff] [blame] | 2270 | next_event: |
| 2271 | perf_evlist__mmap_consume(evlist, i); |
Arnaldo Carvalho de Melo | 20c5f10 | 2013-09-03 11:55:07 -0300 | [diff] [blame] | 2272 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2273 | if (interrupted) |
| 2274 | goto out_disable; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
Arnaldo Carvalho de Melo | efd5745 | 2012-10-17 17:09:46 -0300 | [diff] [blame] | 2278 | if (trace->nr_events == before) { |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2279 | int timeout = done ? 100 : -1; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2280 | |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2281 | if (!draining && perf_evlist__poll(evlist, timeout) > 0) { |
| 2282 | if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP) == 0) |
| 2283 | draining = true; |
| 2284 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2285 | goto again; |
Arnaldo Carvalho de Melo | 46fb3c2 | 2014-09-22 14:39:48 -0300 | [diff] [blame] | 2286 | } |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2287 | } else { |
| 2288 | goto again; |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2289 | } |
| 2290 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2291 | out_disable: |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 2292 | thread__zput(trace->current); |
| 2293 | |
Arnaldo Carvalho de Melo | ba209f8 | 2013-10-16 11:57:33 -0300 | [diff] [blame] | 2294 | perf_evlist__disable(evlist); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2295 | |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2296 | if (!err) { |
| 2297 | if (trace->summary) |
| 2298 | trace__fprintf_thread_summary(trace, trace->output); |
| 2299 | |
| 2300 | if (trace->show_tool_stats) { |
| 2301 | fprintf(trace->output, "Stats:\n " |
| 2302 | " vfs_getname : %" PRIu64 "\n" |
| 2303 | " proc_getname: %" PRIu64 "\n", |
| 2304 | trace->stats.vfs_getname, |
| 2305 | trace->stats.proc_getname); |
| 2306 | } |
| 2307 | } |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2308 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2309 | out_delete_evlist: |
| 2310 | perf_evlist__delete(evlist); |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2311 | trace->evlist = NULL; |
Arnaldo Carvalho de Melo | 75b757ca | 2013-09-24 11:04:32 -0300 | [diff] [blame] | 2312 | trace->live = false; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2313 | return err; |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 2314 | { |
| 2315 | char errbuf[BUFSIZ]; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2316 | |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2317 | out_error_sched_stat_runtime: |
| 2318 | debugfs__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime"); |
| 2319 | goto out_error; |
| 2320 | |
Arnaldo Carvalho de Melo | 801c67b | 2015-01-22 10:52:55 -0300 | [diff] [blame] | 2321 | out_error_raw_syscalls: |
Arnaldo Carvalho de Melo | 2cc990b | 2015-01-22 11:13:43 -0300 | [diff] [blame] | 2322 | debugfs__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] | 2323 | goto out_error; |
| 2324 | |
Arnaldo Carvalho de Melo | e09b18d | 2014-12-11 18:04:10 -0300 | [diff] [blame] | 2325 | out_error_mmap: |
| 2326 | perf_evlist__strerror_mmap(evlist, errno, errbuf, sizeof(errbuf)); |
| 2327 | goto out_error; |
| 2328 | |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2329 | out_error_open: |
| 2330 | perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); |
| 2331 | |
| 2332 | out_error: |
Arnaldo Carvalho de Melo | 6ef068c | 2013-10-17 12:07:58 -0300 | [diff] [blame] | 2333 | fprintf(trace->output, "%s\n", errbuf); |
Ramkumar Ramachandra | 87f9186 | 2013-10-04 10:47:31 +0530 | [diff] [blame] | 2334 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2335 | } |
Arnaldo Carvalho de Melo | 5ed08da | 2015-01-22 11:08:04 -0300 | [diff] [blame] | 2336 | out_error_mem: |
| 2337 | fprintf(trace->output, "Not enough memory to run!\n"); |
| 2338 | goto out_delete_evlist; |
Arnaldo Carvalho de Melo | a8f23d8 | 2013-10-17 17:38:29 -0300 | [diff] [blame] | 2339 | } |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2340 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2341 | static int trace__replay(struct trace *trace) |
| 2342 | { |
| 2343 | const struct perf_evsel_str_handler handlers[] = { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2344 | { "probe:vfs_getname", trace__vfs_getname, }, |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2345 | }; |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2346 | struct perf_data_file file = { |
| 2347 | .path = input_name, |
| 2348 | .mode = PERF_DATA_MODE_READ, |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 2349 | .force = trace->force, |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2350 | }; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2351 | struct perf_session *session; |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 2352 | struct perf_evsel *evsel; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2353 | int err = -1; |
| 2354 | |
| 2355 | trace->tool.sample = trace__process_sample; |
| 2356 | trace->tool.mmap = perf_event__process_mmap; |
David Ahern | 384c671 | 2013-09-22 19:44:58 -0600 | [diff] [blame] | 2357 | trace->tool.mmap2 = perf_event__process_mmap2; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2358 | trace->tool.comm = perf_event__process_comm; |
| 2359 | trace->tool.exit = perf_event__process_exit; |
| 2360 | trace->tool.fork = perf_event__process_fork; |
| 2361 | trace->tool.attr = perf_event__process_attr; |
| 2362 | trace->tool.tracing_data = perf_event__process_tracing_data; |
| 2363 | trace->tool.build_id = perf_event__process_build_id; |
| 2364 | |
Jiri Olsa | 0a8cb85 | 2014-07-06 14:18:21 +0200 | [diff] [blame] | 2365 | trace->tool.ordered_events = true; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2366 | trace->tool.ordering_requires_timestamps = true; |
| 2367 | |
| 2368 | /* add tid to output */ |
| 2369 | trace->multiple_threads = true; |
| 2370 | |
Jiri Olsa | f5fc141 | 2013-10-15 16:27:32 +0200 | [diff] [blame] | 2371 | session = perf_session__new(&file, false, &trace->tool); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2372 | if (session == NULL) |
Taeung Song | 52e02834 | 2014-09-24 10:33:37 +0900 | [diff] [blame] | 2373 | return -1; |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2374 | |
Namhyung Kim | 0a7e6d1 | 2014-08-12 15:40:45 +0900 | [diff] [blame] | 2375 | if (symbol__init(&session->header.env) < 0) |
Namhyung Kim | cb2ffae | 2014-08-12 15:40:44 +0900 | [diff] [blame] | 2376 | goto out; |
| 2377 | |
David Ahern | 8fb598e | 2013-09-28 13:13:00 -0600 | [diff] [blame] | 2378 | trace->host = &session->machines.host; |
| 2379 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2380 | err = perf_session__set_tracepoints_handlers(session, handlers); |
| 2381 | if (err) |
| 2382 | goto out; |
| 2383 | |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 2384 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 2385 | "raw_syscalls:sys_enter"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2386 | /* older kernels have syscalls tp versus raw_syscalls */ |
| 2387 | if (evsel == NULL) |
| 2388 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 2389 | "syscalls:sys_enter"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2390 | |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2391 | if (evsel && |
| 2392 | (perf_evsel__init_syscall_tp(evsel, trace__sys_enter) < 0 || |
| 2393 | perf_evsel__init_sc_tp_ptr_field(evsel, args))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 2394 | pr_err("Error during initialize raw_syscalls:sys_enter event\n"); |
| 2395 | goto out; |
| 2396 | } |
| 2397 | |
| 2398 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 2399 | "raw_syscalls:sys_exit"); |
David Ahern | 9aca7f1 | 2013-12-04 19:41:39 -0700 | [diff] [blame] | 2400 | if (evsel == NULL) |
| 2401 | evsel = perf_evlist__find_tracepoint_by_name(session->evlist, |
| 2402 | "syscalls:sys_exit"); |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2403 | if (evsel && |
| 2404 | (perf_evsel__init_syscall_tp(evsel, trace__sys_exit) < 0 || |
| 2405 | perf_evsel__init_sc_tp_uint_field(evsel, ret))) { |
Namhyung Kim | 003824e | 2013-11-12 15:25:00 +0900 | [diff] [blame] | 2406 | pr_err("Error during initialize raw_syscalls:sys_exit event\n"); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2407 | goto out; |
| 2408 | } |
| 2409 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2410 | evlist__for_each(session->evlist, evsel) { |
| 2411 | if (evsel->attr.type == PERF_TYPE_SOFTWARE && |
| 2412 | (evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ || |
| 2413 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS_MIN || |
| 2414 | evsel->attr.config == PERF_COUNT_SW_PAGE_FAULTS)) |
| 2415 | evsel->handler = trace__pgfault; |
| 2416 | } |
| 2417 | |
David Ahern | bdc8966 | 2013-08-28 22:29:53 -0600 | [diff] [blame] | 2418 | err = parse_target_str(trace); |
| 2419 | if (err != 0) |
| 2420 | goto out; |
| 2421 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2422 | setup_pager(); |
| 2423 | |
Arnaldo Carvalho de Melo | b7b61cb | 2015-03-03 11:58:45 -0300 | [diff] [blame] | 2424 | err = perf_session__process_events(session); |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2425 | if (err) |
| 2426 | pr_err("Failed to process events, error %d", err); |
| 2427 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2428 | else if (trace->summary) |
| 2429 | trace__fprintf_thread_summary(trace, trace->output); |
| 2430 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2431 | out: |
| 2432 | perf_session__delete(session); |
| 2433 | |
| 2434 | return err; |
| 2435 | } |
| 2436 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2437 | static size_t trace__fprintf_threads_header(FILE *fp) |
| 2438 | { |
| 2439 | size_t printed; |
| 2440 | |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 2441 | printed = fprintf(fp, "\n Summary of events:\n\n"); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2442 | |
| 2443 | return printed; |
| 2444 | } |
| 2445 | |
| 2446 | static size_t thread__dump_stats(struct thread_trace *ttrace, |
| 2447 | struct trace *trace, FILE *fp) |
| 2448 | { |
| 2449 | struct stats *stats; |
| 2450 | size_t printed = 0; |
| 2451 | struct syscall *sc; |
| 2452 | struct int_node *inode = intlist__first(ttrace->syscall_stats); |
| 2453 | |
| 2454 | if (inode == NULL) |
| 2455 | return 0; |
| 2456 | |
| 2457 | printed += fprintf(fp, "\n"); |
| 2458 | |
Pekka Enberg | 27a778b | 2013-11-13 14:21:48 +0200 | [diff] [blame] | 2459 | printed += fprintf(fp, " syscall calls min avg max stddev\n"); |
| 2460 | printed += fprintf(fp, " (msec) (msec) (msec) (%%)\n"); |
| 2461 | printed += fprintf(fp, " --------------- -------- --------- --------- --------- ------\n"); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 2462 | |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2463 | /* each int_node is a syscall */ |
| 2464 | while (inode) { |
| 2465 | stats = inode->priv; |
| 2466 | if (stats) { |
| 2467 | double min = (double)(stats->min) / NSEC_PER_MSEC; |
| 2468 | double max = (double)(stats->max) / NSEC_PER_MSEC; |
| 2469 | double avg = avg_stats(stats); |
| 2470 | double pct; |
| 2471 | u64 n = (u64) stats->n; |
| 2472 | |
| 2473 | pct = avg ? 100.0 * stddev_stats(stats)/avg : 0.0; |
| 2474 | avg /= NSEC_PER_MSEC; |
| 2475 | |
| 2476 | sc = &trace->syscalls.table[inode->i]; |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 2477 | printed += fprintf(fp, " %-15s", sc->name); |
Pekka Enberg | 27a778b | 2013-11-13 14:21:48 +0200 | [diff] [blame] | 2478 | printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f", |
Pekka Enberg | 7f7a413 | 2013-11-12 16:10:10 +0200 | [diff] [blame] | 2479 | n, min, avg); |
Pekka Enberg | 27a778b | 2013-11-13 14:21:48 +0200 | [diff] [blame] | 2480 | printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | inode = intlist__next(inode); |
| 2484 | } |
| 2485 | |
| 2486 | printed += fprintf(fp, "\n\n"); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2487 | |
| 2488 | return printed; |
| 2489 | } |
| 2490 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2491 | /* struct used to pass data to per-thread function */ |
| 2492 | struct summary_data { |
| 2493 | FILE *fp; |
| 2494 | struct trace *trace; |
| 2495 | size_t printed; |
| 2496 | }; |
| 2497 | |
| 2498 | static int trace__fprintf_one_thread(struct thread *thread, void *priv) |
| 2499 | { |
| 2500 | struct summary_data *data = priv; |
| 2501 | FILE *fp = data->fp; |
| 2502 | size_t printed = data->printed; |
| 2503 | struct trace *trace = data->trace; |
Namhyung Kim | 89dceb2 | 2014-10-06 09:46:03 +0900 | [diff] [blame] | 2504 | struct thread_trace *ttrace = thread__priv(thread); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2505 | double ratio; |
| 2506 | |
| 2507 | if (ttrace == NULL) |
| 2508 | return 0; |
| 2509 | |
| 2510 | ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; |
| 2511 | |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 2512 | printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 2513 | printed += fprintf(fp, "%lu events, ", ttrace->nr_events); |
Pekka Enberg | 15e65c6 | 2013-11-14 18:43:30 +0200 | [diff] [blame] | 2514 | printed += fprintf(fp, "%.1f%%", ratio); |
Stanislav Fomichev | a2ea67d | 2014-07-08 22:05:16 +0400 | [diff] [blame] | 2515 | if (ttrace->pfmaj) |
| 2516 | printed += fprintf(fp, ", %lu majfaults", ttrace->pfmaj); |
| 2517 | if (ttrace->pfmin) |
| 2518 | printed += fprintf(fp, ", %lu minfaults", ttrace->pfmin); |
Pekka Enberg | 99ff715 | 2013-11-12 16:42:14 +0200 | [diff] [blame] | 2519 | printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms); |
David Ahern | bf2575c | 2013-10-08 21:26:53 -0600 | [diff] [blame] | 2520 | printed += thread__dump_stats(ttrace, trace, fp); |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2521 | |
| 2522 | data->printed += printed; |
| 2523 | |
| 2524 | return 0; |
| 2525 | } |
| 2526 | |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2527 | static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) |
| 2528 | { |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2529 | struct summary_data data = { |
| 2530 | .fp = fp, |
| 2531 | .trace = trace |
| 2532 | }; |
| 2533 | data.printed = trace__fprintf_threads_header(fp); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2534 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2535 | machine__for_each_thread(trace->host, trace__fprintf_one_thread, &data); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2536 | |
David Ahern | 896cbb5 | 2013-09-28 13:12:59 -0600 | [diff] [blame] | 2537 | return data.printed; |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2538 | } |
| 2539 | |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2540 | static int trace__set_duration(const struct option *opt, const char *str, |
| 2541 | int unset __maybe_unused) |
| 2542 | { |
| 2543 | struct trace *trace = opt->value; |
| 2544 | |
| 2545 | trace->duration_filter = atof(str); |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 2549 | static int trace__set_filter_pids(const struct option *opt, const char *str, |
| 2550 | int unset __maybe_unused) |
| 2551 | { |
| 2552 | int ret = -1; |
| 2553 | size_t i; |
| 2554 | struct trace *trace = opt->value; |
| 2555 | /* |
| 2556 | * FIXME: introduce a intarray class, plain parse csv and create a |
| 2557 | * { int nr, int entries[] } struct... |
| 2558 | */ |
| 2559 | struct intlist *list = intlist__new(str); |
| 2560 | |
| 2561 | if (list == NULL) |
| 2562 | return -1; |
| 2563 | |
| 2564 | i = trace->filter_pids.nr = intlist__nr_entries(list) + 1; |
| 2565 | trace->filter_pids.entries = calloc(i, sizeof(pid_t)); |
| 2566 | |
| 2567 | if (trace->filter_pids.entries == NULL) |
| 2568 | goto out; |
| 2569 | |
| 2570 | trace->filter_pids.entries[0] = getpid(); |
| 2571 | |
| 2572 | for (i = 1; i < trace->filter_pids.nr; ++i) |
| 2573 | trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i; |
| 2574 | |
| 2575 | intlist__delete(list); |
| 2576 | ret = 0; |
| 2577 | out: |
| 2578 | return ret; |
| 2579 | } |
| 2580 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2581 | static int trace__open_output(struct trace *trace, const char *filename) |
| 2582 | { |
| 2583 | struct stat st; |
| 2584 | |
| 2585 | if (!stat(filename, &st) && st.st_size) { |
| 2586 | char oldname[PATH_MAX]; |
| 2587 | |
| 2588 | scnprintf(oldname, sizeof(oldname), "%s.old", filename); |
| 2589 | unlink(oldname); |
| 2590 | rename(filename, oldname); |
| 2591 | } |
| 2592 | |
| 2593 | trace->output = fopen(filename, "w"); |
| 2594 | |
| 2595 | return trace->output == NULL ? -errno : 0; |
| 2596 | } |
| 2597 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2598 | static int parse_pagefaults(const struct option *opt, const char *str, |
| 2599 | int unset __maybe_unused) |
| 2600 | { |
| 2601 | int *trace_pgfaults = opt->value; |
| 2602 | |
| 2603 | if (strcmp(str, "all") == 0) |
| 2604 | *trace_pgfaults |= TRACE_PFMAJ | TRACE_PFMIN; |
| 2605 | else if (strcmp(str, "maj") == 0) |
| 2606 | *trace_pgfaults |= TRACE_PFMAJ; |
| 2607 | else if (strcmp(str, "min") == 0) |
| 2608 | *trace_pgfaults |= TRACE_PFMIN; |
| 2609 | else |
| 2610 | return -1; |
| 2611 | |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2615 | static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler) |
| 2616 | { |
| 2617 | struct perf_evsel *evsel; |
| 2618 | |
| 2619 | evlist__for_each(evlist, evsel) |
| 2620 | evsel->handler = handler; |
| 2621 | } |
| 2622 | |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2623 | int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) |
| 2624 | { |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 2625 | const char *trace_usage[] = { |
Namhyung Kim | f15eb53 | 2012-10-05 14:02:16 +0900 | [diff] [blame] | 2626 | "perf trace [<options>] [<command>]", |
| 2627 | "perf trace [<options>] -- <command> [<options>]", |
David Ahern | 5e2485b | 2013-09-28 13:13:01 -0600 | [diff] [blame] | 2628 | "perf trace record [<options>] [<command>]", |
| 2629 | "perf trace record [<options>] -- <command> [<options>]", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2630 | NULL |
| 2631 | }; |
| 2632 | struct trace trace = { |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2633 | .audit = { |
| 2634 | .machine = audit_detect_machine(), |
| 2635 | .open_id = audit_name_to_syscall("open", trace.audit.machine), |
| 2636 | }, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2637 | .syscalls = { |
| 2638 | . max = -1, |
| 2639 | }, |
| 2640 | .opts = { |
| 2641 | .target = { |
| 2642 | .uid = UINT_MAX, |
| 2643 | .uses_mmap = true, |
| 2644 | }, |
| 2645 | .user_freq = UINT_MAX, |
| 2646 | .user_interval = ULLONG_MAX, |
Arnaldo Carvalho de Melo | 509051e | 2014-01-14 17:52:14 -0300 | [diff] [blame] | 2647 | .no_buffering = true, |
Arnaldo Carvalho de Melo | 38d5447 | 2014-12-12 17:28:32 -0300 | [diff] [blame] | 2648 | .mmap_pages = UINT_MAX, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2649 | }, |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2650 | .output = stdout, |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 2651 | .show_comm = true, |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2652 | .trace_syscalls = true, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2653 | }; |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2654 | const char *output_name = NULL; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2655 | const char *ev_qualifier_str = NULL; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2656 | const struct option trace_options[] = { |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2657 | OPT_CALLBACK(0, "event", &trace.evlist, "event", |
| 2658 | "event selector. use 'perf list' to list available events", |
| 2659 | parse_events_option), |
Arnaldo Carvalho de Melo | 50c95cb | 2013-09-12 12:35:21 -0300 | [diff] [blame] | 2660 | OPT_BOOLEAN(0, "comm", &trace.show_comm, |
| 2661 | "show the thread COMM next to its id"), |
Arnaldo Carvalho de Melo | c522739 | 2013-09-27 18:06:19 -0300 | [diff] [blame] | 2662 | OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2663 | OPT_STRING('e', "expr", &ev_qualifier_str, "expr", |
| 2664 | "list of events to trace"), |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2665 | OPT_STRING('o', "output", &output_name, "file", "output file name"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2666 | 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] | 2667 | OPT_STRING('p', "pid", &trace.opts.target.pid, "pid", |
| 2668 | "trace events on existing process id"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 2669 | OPT_STRING('t', "tid", &trace.opts.target.tid, "tid", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2670 | "trace events on existing thread id"), |
Arnaldo Carvalho de Melo | f078c38 | 2015-02-21 11:36:52 -0800 | [diff] [blame] | 2671 | OPT_CALLBACK(0, "filter-pids", &trace, "float", |
| 2672 | "show only events with duration > N.M ms", trace__set_filter_pids), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 2673 | OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2674 | "system-wide collection from all CPUs"), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 2675 | OPT_STRING('C', "cpu", &trace.opts.target.cpu_list, "cpu", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2676 | "list of cpus to monitor"), |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2677 | OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit, |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2678 | "child tasks do not inherit counters"), |
Jiri Olsa | 994a1f7 | 2013-09-01 12:36:12 +0200 | [diff] [blame] | 2679 | OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages", |
| 2680 | "number of mmap data pages", |
| 2681 | perf_evlist__parse_mmap_pages), |
David Ahern | ac9be8e | 2013-08-20 11:15:45 -0600 | [diff] [blame] | 2682 | OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user", |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2683 | "user to profile"), |
Arnaldo Carvalho de Melo | ae9ed03 | 2012-10-08 09:56:00 -0300 | [diff] [blame] | 2684 | OPT_CALLBACK(0, "duration", &trace, "float", |
| 2685 | "show only events with duration > N.M ms", |
| 2686 | trace__set_duration), |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2687 | OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"), |
Arnaldo Carvalho de Melo | 7c304ee0 | 2013-08-22 16:49:54 -0300 | [diff] [blame] | 2688 | OPT_INCR('v', "verbose", &verbose, "be more verbose"), |
David Ahern | 4bb0919 | 2013-09-04 12:37:43 -0600 | [diff] [blame] | 2689 | OPT_BOOLEAN('T', "time", &trace.full_time, |
| 2690 | "Show full timestamp, not time relative to first start"), |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 2691 | OPT_BOOLEAN('s', "summary", &trace.summary_only, |
| 2692 | "Show only syscall summary with statistics"), |
| 2693 | OPT_BOOLEAN('S', "with-summary", &trace.summary, |
| 2694 | "Show all syscalls and summary with statistics"), |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2695 | OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min", |
| 2696 | "Trace pagefaults", parse_pagefaults, "maj"), |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2697 | OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"), |
Yunlong Song | e366a6d | 2015-04-02 21:47:18 +0800 | [diff] [blame] | 2698 | OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"), |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2699 | OPT_END() |
| 2700 | }; |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 2701 | const char * const trace_subcommands[] = { "record", NULL }; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2702 | int err; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 2703 | char bf[BUFSIZ]; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2704 | |
Arnaldo Carvalho de Melo | 4d08cb8 | 2015-02-24 15:35:55 -0300 | [diff] [blame] | 2705 | signal(SIGSEGV, sighandler_dump_stack); |
| 2706 | signal(SIGFPE, sighandler_dump_stack); |
| 2707 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2708 | trace.evlist = perf_evlist__new(); |
| 2709 | if (trace.evlist == NULL) |
| 2710 | return -ENOMEM; |
| 2711 | |
| 2712 | if (trace.evlist == NULL) { |
| 2713 | pr_err("Not enough memory to run!\n"); |
| 2714 | goto out; |
| 2715 | } |
| 2716 | |
Yunlong Song | 6fdd9cb | 2015-03-18 21:35:57 +0800 | [diff] [blame] | 2717 | argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands, |
| 2718 | trace_usage, PARSE_OPT_STOP_AT_NON_OPTION); |
David Ahern | fd2eaba | 2013-11-12 09:31:15 -0700 | [diff] [blame] | 2719 | |
Stanislav Fomichev | 598d02c | 2014-06-26 20:14:25 +0400 | [diff] [blame] | 2720 | if (trace.trace_pgfaults) { |
| 2721 | trace.opts.sample_address = true; |
| 2722 | trace.opts.sample_time = true; |
| 2723 | } |
| 2724 | |
Arnaldo Carvalho de Melo | 14a052d | 2015-02-03 12:58:57 -0300 | [diff] [blame] | 2725 | if (trace.evlist->nr_entries > 0) |
| 2726 | evlist__set_evsel_handler(trace.evlist, trace__event_handler); |
| 2727 | |
Stanislav Fomichev | 1e28fe0 | 2014-06-26 20:14:26 +0400 | [diff] [blame] | 2728 | if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) |
| 2729 | return trace__record(&trace, argc-1, &argv[1]); |
| 2730 | |
| 2731 | /* summary_only implies summary option, but don't overwrite summary if set */ |
| 2732 | if (trace.summary_only) |
| 2733 | trace.summary = trace.summary_only; |
| 2734 | |
Arnaldo Carvalho de Melo | 726f323 | 2015-02-06 10:16:45 +0100 | [diff] [blame] | 2735 | if (!trace.trace_syscalls && !trace.trace_pgfaults && |
| 2736 | trace.evlist->nr_entries == 0 /* Was --events used? */) { |
Stanislav Fomichev | e281a96 | 2014-06-26 20:14:28 +0400 | [diff] [blame] | 2737 | pr_err("Please specify something to trace.\n"); |
| 2738 | return -1; |
| 2739 | } |
| 2740 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2741 | if (output_name != NULL) { |
| 2742 | err = trace__open_output(&trace, output_name); |
| 2743 | if (err < 0) { |
| 2744 | perror("failed to create output file"); |
| 2745 | goto out; |
| 2746 | } |
| 2747 | } |
| 2748 | |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2749 | if (ev_qualifier_str != NULL) { |
Arnaldo Carvalho de Melo | b059efd | 2013-08-21 12:56:21 -0300 | [diff] [blame] | 2750 | const char *s = ev_qualifier_str; |
| 2751 | |
| 2752 | trace.not_ev_qualifier = *s == '!'; |
| 2753 | if (trace.not_ev_qualifier) |
| 2754 | ++s; |
| 2755 | trace.ev_qualifier = strlist__new(true, s); |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2756 | if (trace.ev_qualifier == NULL) { |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2757 | fputs("Not enough memory to parse event qualifier", |
| 2758 | trace.output); |
| 2759 | err = -ENOMEM; |
| 2760 | goto out_close; |
Arnaldo Carvalho de Melo | 2ae3a31 | 2013-08-09 12:28:31 -0300 | [diff] [blame] | 2761 | } |
| 2762 | } |
| 2763 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2764 | err = target__validate(&trace.opts.target); |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 2765 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2766 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2767 | fprintf(trace.output, "%s", bf); |
| 2768 | goto out_close; |
Namhyung Kim | 32caf0d | 2012-10-05 14:02:13 +0900 | [diff] [blame] | 2769 | } |
| 2770 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2771 | err = target__parse_uid(&trace.opts.target); |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2772 | if (err) { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2773 | target__strerror(&trace.opts.target, err, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2774 | fprintf(trace.output, "%s", bf); |
| 2775 | goto out_close; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2776 | } |
| 2777 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2778 | if (!argc && target__none(&trace.opts.target)) |
Namhyung Kim | ee76120 | 2012-10-05 14:02:14 +0900 | [diff] [blame] | 2779 | trace.opts.target.system_wide = true; |
| 2780 | |
David Ahern | 6810fc9 | 2013-08-28 22:29:52 -0600 | [diff] [blame] | 2781 | if (input_name) |
| 2782 | err = trace__replay(&trace); |
| 2783 | else |
| 2784 | err = trace__run(&trace, argc, argv); |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2785 | |
Arnaldo Carvalho de Melo | c24ff99 | 2013-08-19 12:01:10 -0300 | [diff] [blame] | 2786 | out_close: |
| 2787 | if (output_name != NULL) |
| 2788 | fclose(trace.output); |
| 2789 | out: |
Arnaldo Carvalho de Melo | 1302d88 | 2012-10-17 17:13:12 -0300 | [diff] [blame] | 2790 | return err; |
Arnaldo Carvalho de Melo | 514f1c6 | 2012-09-26 20:05:56 -0300 | [diff] [blame] | 2791 | } |