• Home
  • Raw
  • Download

Lines Matching +full:oe +full:- +full:extra +full:- +full:delay

2  * builtin-trace.c
8 * event may be specified using --event.
18 #include <traceevent/event-parse.h>
33 #include "util/synthetic-events.h"
38 #include <subcmd/exec-cmd.h>
45 #include <subcmd/parse-options.h>
53 #include "trace-event.h"
54 #include "util/parse-events.h"
55 #include "util/bpf-loader.h"
201 } oe; member
216 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
229 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
239 field->offset = offset; in __tp_field__init_uint()
243 field->integer = tp_field__u8; in __tp_field__init_uint()
246 field->integer = needs_swap ? tp_field__swapped_u16 : tp_field__u16; in __tp_field__init_uint()
249 field->integer = needs_swap ? tp_field__swapped_u32 : tp_field__u32; in __tp_field__init_uint()
252 field->integer = needs_swap ? tp_field__swapped_u64 : tp_field__u64; in __tp_field__init_uint()
255 return -1; in __tp_field__init_uint()
263 return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap); in tp_field__init_uint()
268 return sample->raw_data + field->offset; in tp_field__ptr()
273 field->offset = offset; in __tp_field__init_ptr()
274 field->pointer = tp_field__ptr; in __tp_field__init_ptr()
280 return __tp_field__init_ptr(field, format_field->offset); in tp_field__init_ptr()
291 * The evsel->priv as used by 'perf trace'
310 zfree(&et->fmt); in evsel_trace__delete()
320 struct evsel_trace *et = evsel->priv; in __evsel__syscall_tp()
322 return &et->sc; in __evsel__syscall_tp()
327 if (evsel->priv == NULL) { in evsel__syscall_tp()
328 evsel->priv = evsel_trace__new(); in evsel__syscall_tp()
329 if (evsel->priv == NULL) in evsel__syscall_tp()
341 struct evsel_trace *et = evsel->priv; in __evsel__syscall_arg_fmt()
343 return et->fmt; in __evsel__syscall_arg_fmt()
348 struct evsel_trace *et = evsel->priv; in evsel__syscall_arg_fmt()
350 if (evsel->priv == NULL) { in evsel__syscall_arg_fmt()
351 et = evsel->priv = evsel_trace__new(); in evsel__syscall_arg_fmt()
357 if (et->fmt == NULL) { in evsel__syscall_arg_fmt()
358 et->fmt = calloc(evsel->tp_format->format.nr_fields, sizeof(struct syscall_arg_fmt)); in evsel__syscall_arg_fmt()
359 if (et->fmt == NULL) in evsel__syscall_arg_fmt()
366 evsel_trace__delete(evsel->priv); in evsel__syscall_arg_fmt()
367 evsel->priv = NULL; in evsel__syscall_arg_fmt()
376 return -1; in evsel__init_tp_uint_field()
378 return tp_field__init_uint(field, format_field, evsel->needs_swap); in evsel__init_tp_uint_field()
383 evsel__init_tp_uint_field(evsel, &sc->name, #name); })
390 return -1; in evsel__init_tp_ptr_field()
397 evsel__init_tp_ptr_field(evsel, &sc->name, #name); })
401 zfree(&evsel->priv); in evsel__delete_priv()
410 if (evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") && in evsel__init_syscall_tp()
411 evsel__init_tp_uint_field(evsel, &sc->id, "nr")) in evsel__init_syscall_tp()
412 return -ENOENT; in evsel__init_syscall_tp()
416 return -ENOMEM; in evsel__init_syscall_tp()
428 __tp_field__init_uint(&sc->id, syscall_id->size, syscall_id->offset, evsel->needs_swap)) in evsel__init_augmented_syscall_tp()
429 return -EINVAL; in evsel__init_augmented_syscall_tp()
434 return -ENOMEM; in evsel__init_augmented_syscall_tp()
441 return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)); in evsel__init_augmented_syscall_tp_args()
448 …return __tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap… in evsel__init_augmented_syscall_tp_ret()
455 return -ENOENT; in evsel__init_raw_syscall_tp()
457 evsel->handler = handler; in evsel__init_raw_syscall_tp()
461 return -ENOMEM; in evsel__init_raw_syscall_tp()
487 fields->name.integer(&fields->name, sample); })
491 fields->name.pointer(&fields->name, sample); })
495 int idx = val - sa->offset; in strarray__scnprintf_suffix()
497 if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) { in strarray__scnprintf_suffix()
500 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix); in strarray__scnprintf_suffix()
504 return scnprintf(bf, size, "%s%s", sa->entries[idx], show_suffix ? sa->prefix : ""); in strarray__scnprintf_suffix()
509 int idx = val - sa->offset; in strarray__scnprintf()
511 if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) { in strarray__scnprintf()
514 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix); in strarray__scnprintf()
518 return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); in strarray__scnprintf()
525 return strarray__scnprintf(arg->parm, bf, size, intfmt, arg->show_string_prefix, arg->val); in __syscall_arg__scnprintf_strarray()
538 return strarray__strtoul(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarray()
543 return strarray__strtoul_flags(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarray_flags()
548 return strarrays__strtoul(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarrays()
553 return strarray__scnprintf_flags(arg->parm, bf, size, arg->show_string_prefix, arg->val); in syscall_arg__scnprintf_strarray_flags()
561 for (i = 0; i < sas->nr_entries; ++i) { in strarrays__scnprintf()
562 struct strarray *sa = sas->entries[i]; in strarrays__scnprintf()
563 int idx = val - sa->offset; in strarrays__scnprintf()
565 if (idx >= 0 && idx < sa->nr_entries) { in strarrays__scnprintf()
566 if (sa->entries[idx] == NULL) in strarrays__scnprintf()
568 return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); in strarrays__scnprintf()
574 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sas->entries[0]->prefix); in strarrays__scnprintf()
582 for (i = 0; i < sa->nr_entries; ++i) { in strarray__strtoul()
583 if (sa->entries[i] && strncmp(sa->entries[i], bf, size) == 0 && sa->entries[i][size] == '\0') { in strarray__strtoul()
584 *ret = sa->offset + i; in strarray__strtoul()
604 size -= sep - tok + 1; in strarray__strtoul_flags()
606 end = sep - 1; in strarray__strtoul_flags()
608 --end; in strarray__strtoul_flags()
610 toklen = end - tok + 1; in strarray__strtoul_flags()
625 *ret |= (1 << (val - 1)); in strarray__strtoul_flags()
639 for (i = 0; i < sas->nr_entries; ++i) { in strarrays__strtoul()
640 struct strarray *sa = sas->entries[i]; in strarrays__strtoul()
652 return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix, arg->val); in syscall_arg__scnprintf_strarrays()
656 #define AT_FDCWD -100
662 int fd = arg->val; in syscall_arg__scnprintf_fd_at()
666 return scnprintf(bf, size, "%s%s", arg->show_string_prefix ? prefix : "", "CWD"); in syscall_arg__scnprintf_fd_at()
680 return scnprintf(bf, size, "%#lx", arg->val); in syscall_arg__scnprintf_hex()
685 if (arg->val == 0) in syscall_arg__scnprintf_ptr()
692 return scnprintf(bf, size, "%d", arg->val); in syscall_arg__scnprintf_int()
697 return scnprintf(bf, size, "%ld", arg->val); in syscall_arg__scnprintf_long()
705 return scnprintf(bf, size, "\"%-.*s\"", arg->fmt->nr_entries ?: arg->len, arg->val); in syscall_arg__scnprintf_char_array()
793 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_access_mode()
796 int mode = arg->val; in syscall_arg__scnprintf_access_mode()
802 printed += scnprintf(bf + printed, size - printed, "%s%s", #n, show_prefix ? suffix : ""); \ in syscall_arg__scnprintf_access_mode()
812 printed += scnprintf(bf + printed, size - printed, "|%#x", mode); in syscall_arg__scnprintf_access_mode()
827 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_pipe_flags()
829 int printed = 0, flags = arg->val; in syscall_arg__scnprintf_pipe_flags()
833 …printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? pre… in syscall_arg__scnprintf_pipe_flags()
842 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); in syscall_arg__scnprintf_pipe_flags()
859 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_getrandom_flags()
861 int printed = 0, flags = arg->val; in syscall_arg__scnprintf_getrandom_flags()
865 …printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? pre… in syscall_arg__scnprintf_getrandom_flags()
874 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); in syscall_arg__scnprintf_getrandom_flags()
1159 return strcmp(name, fmt->name); in syscall_fmt__cmp()
1282 ttrace->files.max = -1; in thread_trace__new()
1283 ttrace->syscall_stats = intlist__new(NULL); in thread_trace__new()
1303 ++ttrace->nr_events; in thread__trace()
1316 struct thread_trace *ttrace = thread__priv(arg->thread); in syscall_arg__set_ret_scnprintf()
1318 ttrace->ret_scnprintf = ret_scnprintf; in syscall_arg__set_ret_scnprintf()
1331 if (fd > ttrace->files.max) { in thread_trace__files_entry()
1332 struct file *nfiles = realloc(ttrace->files.table, (fd + 1) * sizeof(struct file)); in thread_trace__files_entry()
1337 if (ttrace->files.max != -1) { in thread_trace__files_entry()
1338 memset(nfiles + ttrace->files.max + 1, 0, in thread_trace__files_entry()
1339 (fd - ttrace->files.max) * sizeof(struct file)); in thread_trace__files_entry()
1344 ttrace->files.table = nfiles; in thread_trace__files_entry()
1345 ttrace->files.max = fd; in thread_trace__files_entry()
1348 return ttrace->files.table + fd; in thread_trace__files_entry()
1364 file->dev_maj = major(st.st_rdev); in trace__set_fd_pathname()
1365 file->pathname = strdup(pathname); in trace__set_fd_pathname()
1366 if (file->pathname) in trace__set_fd_pathname()
1370 return -1; in trace__set_fd_pathname()
1379 if (thread->pid_ == thread->tid) { in thread__read_fd_path()
1381 "/proc/%d/fd/%d", thread->pid_, fd); in thread__read_fd_path()
1384 "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd); in thread__read_fd_path()
1388 return -1; in thread__read_fd_path()
1393 return -1; in thread__read_fd_path()
1404 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1410 if ((fd > ttrace->files.max || ttrace->files.table[fd].pathname == NULL)) { in thread__fd_path()
1411 if (!trace->live) in thread__fd_path()
1413 ++trace->stats.proc_getname; in thread__fd_path()
1418 return ttrace->files.table[fd].pathname; in thread__fd_path()
1423 int fd = arg->val; in syscall_arg__scnprintf_fd()
1425 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1428 printed += scnprintf(bf + printed, size - printed, "<%s>", path); in syscall_arg__scnprintf_fd()
1436 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1442 printed += scnprintf(bf + printed, size - printed, "<%s>", path); in pid__scnprintf_fd()
1453 int fd = arg->val; in syscall_arg__scnprintf_close_fd()
1455 struct thread_trace *ttrace = thread__priv(arg->thread); in syscall_arg__scnprintf_close_fd()
1457 if (ttrace && fd >= 0 && fd <= ttrace->files.max) in syscall_arg__scnprintf_close_fd()
1458 zfree(&ttrace->files.table[fd].pathname); in syscall_arg__scnprintf_close_fd()
1468 ttrace->filename.ptr = ptr; in thread__set_filename_pos()
1469 ttrace->filename.entry_str_pos = bf - ttrace->entry_str; in thread__set_filename_pos()
1474 struct augmented_arg *augmented_arg = arg->augmented.args; in syscall_arg__scnprintf_augmented_string()
1475 size_t printed = scnprintf(bf, size, "\"%.*s\"", augmented_arg->size, augmented_arg->value); in syscall_arg__scnprintf_augmented_string()
1480 int consumed = sizeof(*augmented_arg) + augmented_arg->size; in syscall_arg__scnprintf_augmented_string()
1482 arg->augmented.args = ((void *)arg->augmented.args) + consumed; in syscall_arg__scnprintf_augmented_string()
1483 arg->augmented.size -= consumed; in syscall_arg__scnprintf_augmented_string()
1491 unsigned long ptr = arg->val; in syscall_arg__scnprintf_filename()
1493 if (arg->augmented.args) in syscall_arg__scnprintf_filename()
1496 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1499 thread__set_filename_pos(arg->thread, bf, ptr); in syscall_arg__scnprintf_filename()
1505 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1510 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1517 * using ttrace->entry_time for a thread that receives a sys_exit without
1542 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1543 if (trace->show_comm) in trace__fprintf_comm_tid()
1545 printed += fprintf(fp, "%d ", thread->tid); in trace__fprintf_comm_tid()
1556 if (trace->show_tstamp) in trace__fprintf_entry_head()
1558 if (trace->show_duration) in trace__fprintf_entry_head()
1568 switch (event->header.type) { in trace__process_event()
1570 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1571 "LOST %" PRIu64 " events!\n", event->lost.lost); in trace__process_event()
1595 if (machine->kptr_restrict_warned) in trace__machine__resolve_kernel_addr()
1602 machine->kptr_restrict_warned = true; in trace__machine__resolve_kernel_addr()
1616 trace->host = machine__new_host(); in trace__symbols_init()
1617 if (trace->host == NULL) in trace__symbols_init()
1618 return -ENOMEM; in trace__symbols_init()
1620 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1624 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1625 evlist->core.threads, trace__tool_process, false, in trace__symbols_init()
1636 machine__exit(trace->host); in trace__symbols__exit()
1637 trace->host = NULL; in trace__symbols__exit()
1646 if (nr_args == RAW_SYSCALL_ARGS_NUM && sc->fmt && sc->fmt->nr_args != 0) in syscall__alloc_arg_fmts()
1647 nr_args = sc->fmt->nr_args; in syscall__alloc_arg_fmts()
1649 sc->arg_fmt = calloc(nr_args, sizeof(*sc->arg_fmt)); in syscall__alloc_arg_fmts()
1650 if (sc->arg_fmt == NULL) in syscall__alloc_arg_fmts()
1651 return -1; in syscall__alloc_arg_fmts()
1654 if (sc->fmt) in syscall__alloc_arg_fmts()
1655 sc->arg_fmt[idx] = sc->fmt->arg[idx]; in syscall__alloc_arg_fmts()
1658 sc->nr_args = nr_args; in syscall__alloc_arg_fmts()
1670 return strcmp(name, fmt->name); in syscall_arg_fmt__cmp()
1691 for (; field; field = field->next, ++arg) { in syscall_arg_fmt__init_array()
1694 if (arg->scnprintf) in syscall_arg_fmt__init_array()
1697 len = strlen(field->name); in syscall_arg_fmt__init_array()
1699 if (strcmp(field->type, "const char *") == 0 && in syscall_arg_fmt__init_array()
1700 ((len >= 4 && strcmp(field->name + len - 4, "name") == 0) || in syscall_arg_fmt__init_array()
1701 strstr(field->name, "path") != NULL)) in syscall_arg_fmt__init_array()
1702 arg->scnprintf = SCA_FILENAME; in syscall_arg_fmt__init_array()
1703 else if ((field->flags & TEP_FIELD_IS_POINTER) || strstr(field->name, "addr")) in syscall_arg_fmt__init_array()
1704 arg->scnprintf = SCA_PTR; in syscall_arg_fmt__init_array()
1705 else if (strcmp(field->type, "pid_t") == 0) in syscall_arg_fmt__init_array()
1706 arg->scnprintf = SCA_PID; in syscall_arg_fmt__init_array()
1707 else if (strcmp(field->type, "umode_t") == 0) in syscall_arg_fmt__init_array()
1708 arg->scnprintf = SCA_MODE_T; in syscall_arg_fmt__init_array()
1709 else if ((field->flags & TEP_FIELD_IS_ARRAY) && strstr(field->type, "char")) { in syscall_arg_fmt__init_array()
1710 arg->scnprintf = SCA_CHAR_ARRAY; in syscall_arg_fmt__init_array()
1711 arg->nr_entries = field->arraylen; in syscall_arg_fmt__init_array()
1712 } else if ((strcmp(field->type, "int") == 0 || in syscall_arg_fmt__init_array()
1713 strcmp(field->type, "unsigned int") == 0 || in syscall_arg_fmt__init_array()
1714 strcmp(field->type, "long") == 0) && in syscall_arg_fmt__init_array()
1715 len >= 2 && strcmp(field->name + len - 2, "fd") == 0) { in syscall_arg_fmt__init_array()
1718 * egrep 'field:.*fd;' .../format|sed -r 's/.*field:([a-z ]+) [a-z_]*fd.+/\1/g'|sort|uniq -c in syscall_arg_fmt__init_array()
1723 arg->scnprintf = SCA_FD; in syscall_arg_fmt__init_array()
1725 struct syscall_arg_fmt *fmt = syscall_arg_fmt__find_by_name(field->name); in syscall_arg_fmt__init_array()
1728 arg->scnprintf = fmt->scnprintf; in syscall_arg_fmt__init_array()
1729 arg->strtoul = fmt->strtoul; in syscall_arg_fmt__init_array()
1739 struct tep_format_field *last_field = syscall_arg_fmt__init_array(sc->arg_fmt, sc->args); in syscall__set_arg_fmts()
1742 sc->args_size = last_field->offset + last_field->size; in syscall__set_arg_fmts()
1751 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
1754 if (trace->syscalls.table == NULL) { in trace__read_syscall_info()
1755 trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); in trace__read_syscall_info()
1756 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1757 return -ENOMEM; in trace__read_syscall_info()
1760 if (id > trace->sctbl->syscalls.max_id || (id == 0 && trace->syscalls.table == NULL)) { in trace__read_syscall_info()
1762 struct syscall *table = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1765 return -ENOMEM; in trace__read_syscall_info()
1768 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1771 …memset(table + trace->sctbl->syscalls.max_id + 1, 0, (id - trace->sctbl->syscalls.max_id) * sizeof… in trace__read_syscall_info()
1773 trace->syscalls.table = table; in trace__read_syscall_info()
1774 trace->sctbl->syscalls.max_id = id; in trace__read_syscall_info()
1777 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1778 if (sc->nonexistent) in trace__read_syscall_info()
1779 return -EEXIST; in trace__read_syscall_info()
1782 sc->nonexistent = true; in trace__read_syscall_info()
1783 return -EEXIST; in trace__read_syscall_info()
1786 sc->name = name; in trace__read_syscall_info()
1787 sc->fmt = syscall_fmt__find(sc->name); in trace__read_syscall_info()
1789 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); in trace__read_syscall_info()
1790 sc->tp_format = trace_event__tp_format("syscalls", tp_name); in trace__read_syscall_info()
1792 if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) { in trace__read_syscall_info()
1793 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); in trace__read_syscall_info()
1794 sc->tp_format = trace_event__tp_format("syscalls", tp_name); in trace__read_syscall_info()
1801 if (IS_ERR(sc->tp_format)) { in trace__read_syscall_info()
1802 sc->nonexistent = true; in trace__read_syscall_info()
1803 return PTR_ERR(sc->tp_format); in trace__read_syscall_info()
1806 if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? in trace__read_syscall_info()
1807 RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields)) in trace__read_syscall_info()
1808 return -ENOMEM; in trace__read_syscall_info()
1810 sc->args = sc->tp_format->format.fields; in trace__read_syscall_info()
1816 if (sc->args && (!strcmp(sc->args->name, "__syscall_nr") || !strcmp(sc->args->name, "nr"))) { in trace__read_syscall_info()
1817 sc->args = sc->args->next; in trace__read_syscall_info()
1818 --sc->nr_args; in trace__read_syscall_info()
1821 sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); in trace__read_syscall_info()
1822 sc->is_open = !strcmp(name, "open") || !strcmp(name, "openat"); in trace__read_syscall_info()
1832 syscall_arg_fmt__init_array(fmt, evsel->tp_format->format.fields); in evsel__init_tp_arg_scnprintf()
1836 return -ENOMEM; in evsel__init_tp_arg_scnprintf()
1843 return *one - *another; in intcmp()
1851 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
1853 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
1854 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1856 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
1858 trace->output); in trace__validate_ev_qualifier()
1859 err = -EINVAL; in trace__validate_ev_qualifier()
1863 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
1864 const char *sc = pos->s; in trace__validate_ev_qualifier()
1865 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
1868 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1883 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1884 if (match_next == -1) in trace__validate_ev_qualifier()
1888 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1895 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
1896 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1898 err = -ENOMEM; in trace__validate_ev_qualifier()
1899 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
1902 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
1904 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1908 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
1909 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
1915 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
1916 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
1924 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
1927 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
1928 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
1931 return !trace->not_ev_qualifier; in trace__syscall_enabled()
1933 return trace->not_ev_qualifier; in trace__syscall_enabled()
1938 * 8-byte unaligned accesses. args points to raw_data within the event
1939 * and raw_data is guaranteed to be 8-byte unaligned because it is
1947 unsigned char *p = arg->args + sizeof(unsigned long) * idx; in syscall_arg__val()
1956 if (sc->arg_fmt && sc->arg_fmt[arg->idx].name) in syscall__scnprintf_name()
1957 return scnprintf(bf, size, "%s: ", sc->arg_fmt[arg->idx].name); in syscall__scnprintf_name()
1959 return scnprintf(bf, size, "arg%d: ", arg->idx); in syscall__scnprintf_name()
1969 if (fmt && fmt->mask_val) in syscall_arg_fmt__mask_val()
1970 return fmt->mask_val(arg, val); in syscall_arg_fmt__mask_val()
1978 if (fmt && fmt->scnprintf) { in syscall_arg_fmt__scnprintf_val()
1979 arg->val = val; in syscall_arg_fmt__scnprintf_val()
1980 if (fmt->parm) in syscall_arg_fmt__scnprintf_val()
1981 arg->parm = fmt->parm; in syscall_arg_fmt__scnprintf_val()
1982 return fmt->scnprintf(bf, size, arg); in syscall_arg_fmt__scnprintf_val()
2004 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2013 ttrace->ret_scnprintf = NULL; in syscall__scnprintf_args()
2015 if (sc->args != NULL) { in syscall__scnprintf_args()
2018 for (field = sc->args; field; in syscall__scnprintf_args()
2019 field = field->next, ++arg.idx, bit <<= 1) { in syscall__scnprintf_args()
2023 arg.fmt = &sc->arg_fmt[arg.idx]; in syscall__scnprintf_args()
2029 val = syscall_arg_fmt__mask_val(&sc->arg_fmt[arg.idx], &arg, val); in syscall__scnprintf_args()
2037 !trace->show_zeros && in syscall__scnprintf_args()
2038 !(sc->arg_fmt && in syscall__scnprintf_args()
2039 (sc->arg_fmt[arg.idx].show_zero || in syscall__scnprintf_args()
2040 sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAY || in syscall__scnprintf_args()
2041 sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAYS) && in syscall__scnprintf_args()
2042 sc->arg_fmt[arg.idx].parm)) in syscall__scnprintf_args()
2045 printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : ""); in syscall__scnprintf_args()
2047 if (trace->show_arg_names) in syscall__scnprintf_args()
2048 printed += scnprintf(bf + printed, size - printed, "%s: ", field->name); in syscall__scnprintf_args()
2050 printed += syscall_arg_fmt__scnprintf_val(&sc->arg_fmt[arg.idx], in syscall__scnprintf_args()
2051 bf + printed, size - printed, &arg, val); in syscall__scnprintf_args()
2053 } else if (IS_ERR(sc->tp_format)) { in syscall__scnprintf_args()
2059 while (arg.idx < sc->nr_args) { in syscall__scnprintf_args()
2064 printed += scnprintf(bf + printed, size - printed, ", "); in syscall__scnprintf_args()
2065 printed += syscall__scnprintf_name(sc, bf + printed, size - printed, &arg); in syscall__scnprintf_args()
2066 …printed += syscall_arg_fmt__scnprintf_val(&sc->arg_fmt[arg.idx], bf + printed, size - printed, &ar… in syscall__scnprintf_args()
2093 * grep "NR -1 " /t/trace_pipe
2099 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
2105 err = -EINVAL;
2108 if (id > trace->sctbl->syscalls.max_id) {
2110 if (id >= trace->sctbl->syscalls.max_id) {
2122 if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) &&
2126 if (trace->syscalls.table && trace->syscalls.table[id].nonexistent)
2129 return &trace->syscalls.table[id];
2134 …fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, s…
2135 if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL)
2136 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
2137 fputs(" information\n", trace->output);
2156 inode = intlist__findnew(ttrace->syscall_stats, id);
2160 stats = inode->priv;
2166 stats->nr_failures = 0;
2167 stats->max_errno = 0;
2168 stats->errnos = NULL;
2169 init_stats(&stats->stats);
2170 inode->priv = stats;
2173 if (ttrace->entry_time && sample->time > ttrace->entry_time)
2174 duration = sample->time - ttrace->entry_time;
2176 update_stats(&stats->stats, duration);
2179 ++stats->nr_failures;
2184 err = -err;
2185 if (err > stats->max_errno) {
2186 u32 *new_errnos = realloc(stats->errnos, err * sizeof(u32));
2189 memset(new_errnos + stats->max_errno, 0, (err - stats->max_errno) * sizeof(u32));
2192 thread__comm_str(thread), thread->pid_, thread->tid);
2196 stats->errnos = new_errnos;
2197 stats->max_errno = err;
2200 ++stats->errnos[err - 1];
2210 if (trace->failure_only || trace->current == NULL)
2213 ttrace = thread__priv(trace->current);
2215 if (!ttrace->entry_pending)
2218 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o…
2219 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str);
2221 if (len < trace->args_alignment - 4)
2222 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " ");
2224 printed += fprintf(trace->output, " ...\n");
2226 ttrace->entry_pending = false;
2227 ++trace->nr_events_printed;
2237 if (trace->print_sample) {
2238 double ts = (double)sample->time / NSEC_PER_MSEC;
2240 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n",
2243 sample->pid, sample->tid, sample->cpu);
2257 * sc->args_size but always after the full raw_syscalls:sys_enter payload,
2260 * We'll revisit this later to pass s->args_size to the BPF augmenter
2266 int args_size = raw_augmented_args_size ?: sc->args_size;
2268 *augmented_args_size = sample->raw_size - args_size;
2270 augmented_args = sample->raw_data + args_size;
2283 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
2290 return -1;
2292 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2293 ttrace = thread__trace(thread, trace->output);
2301 if (ttrace->entry_str == NULL) {
2302 ttrace->entry_str = malloc(trace__entry_str_size);
2303 if (!ttrace->entry_str)
2307 if (!(trace->duration_filter || trace->summary_only || trace->min_stack))
2313 * syscall->args_size using each syscalls:sys_enter_NAME tracefs format file,
2316 * thinking that the extra 2 u64 args are the augmented filename, so just check
2319 if (evsel != trace->syscalls.events.sys_enter)
2320 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2321 ttrace->entry_time = sample->time;
2322 msg = ttrace->entry_str;
2323 printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name);
2325 printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed,
2328 if (sc->is_exit) {
2329 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
2332 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
2333 printed = fprintf(trace->output, "%s)", ttrace->entry_str);
2334 if (trace->args_alignment > printed)
2335 alignment = trace->args_alignment - printed;
2336 fprintf(trace->output, "%*s= ?\n", alignment, " ");
2339 ttrace->entry_pending = true;
2341 ttrace->filename.pending_open = false;
2344 if (trace->current != thread) {
2345 thread__put(trace->current);
2346 trace->current = thread__get(thread);
2359 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
2366 return -1;
2368 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2369 ttrace = thread__trace(thread, trace->output);
2378 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2380 fprintf(trace->output, "%s", msg);
2392 int max_stack = evsel->core.attr.sample_max_stack ?
2393 evsel->core.attr.sample_max_stack :
2394 trace->max_stack;
2397 if (machine__resolve(trace->host, &al, sample) < 0)
2398 return -1;
2407 /* TODO: user-configurable print_opts */
2412 …intf_callchain(sample, 38, print_opts, &callchain_cursor, symbol_conf.bt_stop_list, trace->output);
2431 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0;
2432 int alignment = trace->args_alignment;
2437 return -1;
2439 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2440 ttrace = thread__trace(thread, trace->output);
2448 if (trace->summary)
2449 thread__update_stats(thread, ttrace, id, sample, ret, trace->errno_summary);
2451 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
2452 trace__set_fd_pathname(thread, ret, ttrace->filename.name);
2453 ttrace->filename.pending_open = false;
2454 ++trace->stats.vfs_getname;
2457 if (ttrace->entry_time) {
2458 duration = sample->time - ttrace->entry_time;
2462 } else if (trace->duration_filter)
2465 if (sample->callchain) {
2468 if (callchain_cursor.nr < trace->min_stack)
2474 if (trace->summary_only || (ret >= 0 && trace->failure_only))
2477 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-
2479 if (ttrace->entry_pending) {
2480 printed = fprintf(trace->output, "%s", ttrace->entry_str);
2482 printed += fprintf(trace->output, " ... [");
2483 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued");
2485 printed += fprintf(trace->output, "]: %s()", sc->name);
2491 alignment -= printed;
2495 fprintf(trace->output, ")%*s= ", alignment, " ");
2497 if (sc->fmt == NULL) {
2501 fprintf(trace->output, "%ld", ret);
2505 const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
2506 *e = errno_to_name(evsel, -ret);
2508 fprintf(trace->output, "-1 %s (%s)", e, emsg);
2510 } else if (ret == 0 && sc->fmt->timeout)
2511 fprintf(trace->output, "0 (Timeout)");
2512 else if (ttrace->ret_scnprintf) {
2519 ttrace->ret_scnprintf(bf, sizeof(bf), &arg);
2520 ttrace->ret_scnprintf = NULL;
2521 fprintf(trace->output, "%s", bf);
2522 } else if (sc->fmt->hexret)
2523 fprintf(trace->output, "%#lx", ret);
2524 else if (sc->fmt->errpid) {
2525 struct thread *child = machine__find_thread(trace->host, ret, ret);
2528 fprintf(trace->output, "%ld", ret);
2529 if (child->comm_set)
2530 fprintf(trace->output, " (%s)", thread__comm_str(child));
2536 fputc('\n', trace->output);
2539 * We only consider an 'event' for the sake of --max-events a non-filtered
2542 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX)
2550 ttrace->entry_pending = false;
2561 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2579 if (ttrace->filename.namelen < filename_len) {
2580 char *f = realloc(ttrace->filename.name, filename_len + 1);
2585 ttrace->filename.namelen = filename_len;
2586 ttrace->filename.name = f;
2589 strcpy(ttrace->filename.name, filename);
2590 ttrace->filename.pending_open = true;
2592 if (!ttrace->filename.ptr)
2595 entry_str_len = strlen(ttrace->entry_str);
2596 remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */
2601 filename += filename_len - remaining_space;
2605 to_move = entry_str_len - ttrace->filename.entry_str_pos + 1; /* \0 */
2606 pos = ttrace->entry_str + ttrace->filename.entry_str_pos;
2610 ttrace->filename.ptr = 0;
2611 ttrace->filename.entry_str_pos = 0;
2624 struct thread *thread = machine__findnew_thread(trace->host,
2625 sample->pid,
2626 sample->tid);
2627 struct thread_trace *ttrace = thread__trace(thread, trace->output);
2632 ttrace->runtime_ms += runtime_ms;
2633 trace->runtime_ms += runtime_ms;
2639 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n",
2640 evsel->name,
2649 unsigned int val, void *extra __maybe_unused, FILE *fp)
2675 binary__fprintf(sample->raw_data, sample->raw_size, 8,
2676 bpf_output__printer, NULL, trace->output);
2677 ++trace->nr_events_printed;
2685 struct tep_format_field *field = evsel->tp_format->format.fields;
2699 .show_string_prefix = trace->show_string_prefix,
2702 for (; field && arg; field = field->next, ++syscall_arg.idx, bit <<= 1, ++arg) {
2708 if (field->flags & TEP_FIELD_IS_ARRAY) {
2709 int offset = field->offset;
2711 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
2712 offset = format_field__intval(field, sample, evsel->needs_swap);
2717 val = (uintptr_t)(sample->raw_data + offset);
2719 val = format_field__intval(field, sample, evsel->needs_swap);
2732 !trace->show_zeros &&
2733 !((arg->show_zero ||
2734 arg->scnprintf == SCA_STRARRAY ||
2735 arg->scnprintf == SCA_STRARRAYS) &&
2736 arg->parm))
2739 printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : "");
2745 if (1 || trace->show_arg_names)
2746 printed += scnprintf(bf + printed, size - printed, "%s: ", field->name);
2748 printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val);
2751 return printed + fprintf(trace->output, "%s", bf);
2766 if (evsel->disabled)
2769 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2771 if (sample->callchain) {
2774 if (callchain_cursor.nr < trace->min_stack)
2781 trace__fprintf_tstamp(trace, sample->time, trace->output);
2783 if (trace->trace_syscalls && trace->show_duration)
2784 fprintf(trace->output, "( ): ");
2787 trace__fprintf_comm_tid(trace, thread, trace->output);
2789 if (evsel == trace->syscalls.events.augmented) {
2794 fprintf(trace->output, "%s(", sc->name);
2796 fputc(')', trace->output);
2807 fprintf(trace->output, "%s(", evsel->name);
2811 } else if (evsel->tp_format) {
2812 if (strncmp(evsel->tp_format->name, "sys_enter_", 10) ||
2814 if (trace->libtraceevent_print) {
2815 event_format__fprintf(evsel->tp_format, sample->cpu,
2816 sample->raw_data, sample->raw_size,
2817 trace->output);
2825 fprintf(trace->output, ")\n");
2832 ++trace->nr_events_printed;
2834 if (evsel->max_events != ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) {
2848 if ((verbose > 0 || print_dso) && al->map)
2849 fprintf(f, "%s@", al->map->dso->long_name);
2851 if ((verbose > 0 || print_sym) && al->sym)
2852 fprintf(f, "%s+0x%" PRIx64, al->sym->name,
2853 al->addr - al->sym->start);
2854 else if (al->map)
2855 fprintf(f, "0x%" PRIx64, al->addr);
2857 fprintf(f, "0x%" PRIx64, sample->addr);
2869 int err = -1;
2872 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2874 if (sample->callchain) {
2877 if (callchain_cursor.nr < trace->min_stack)
2883 ttrace = thread__trace(thread, trace->output);
2887 if (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)
2888 ttrace->pfmaj++;
2890 ttrace->pfmin++;
2892 if (trace->summary_only)
2895 thread__find_symbol(thread, sample->cpumode, sample->ip, &al);
2897 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
2899 fprintf(trace->output, "%sfault [",
2900 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ?
2903 print_location(trace->output, sample, &al, false, true);
2905 fprintf(trace->output, "] => ");
2907 thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
2910 thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
2918 print_location(trace->output, sample, &al, true, false);
2920 fprintf(trace->output, " (%c%c)\n", map_type, al.level);
2927 ++trace->nr_events_printed;
2941 * and don't use sample->time unconditionally, we may end up having
2947 if (trace->base_time == 0 && !trace->full_time &&
2948 (evsel->core.attr.sample_type & PERF_SAMPLE_TIME))
2949 trace->base_time = sample->time;
2962 tracepoint_handler handler = evsel->handler;
2964 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2971 ++trace->nr_events;
2985 "-R",
2986 "-m", "1024",
2987 "-c", "1",
2991 const char * const sc_args[] = { "-e", };
2993 const char * const majpf_args[] = { "-e", "major-faults" };
2995 const char * const minpf_args[] = { "-e", "minor-faults" };
2997 int err = -1;
3011 if (trace->trace_syscalls) {
3015 /* event string may be different for older kernels - e.g., RHEL6 */
3026 rec_argv[j++] = "--filter";
3029 if (trace->trace_pgfaults & TRACE_PFMAJ)
3033 if (trace->trace_pgfaults & TRACE_PFMIN)
3071 evsel->handler = trace__vfs_getname;
3076 list_del_init(&evsel->core.node);
3077 evsel->evlist = NULL;
3099 evsel->handler = trace__pgfault;
3106 const u32 type = event->header.type;
3110 trace__process_event(trace, trace->host, event, sample);
3114 evsel = perf_evlist__id2evsel(trace->evlist, sample->id);
3116 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id);
3120 if (evswitch__discard(&trace->evswitch, evsel))
3125 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT &&
3126 sample->raw_data == NULL) {
3127 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
3128 evsel__name(evsel), sample->tid,
3129 sample->cpu, sample->raw_size);
3131 tracepoint_handler handler = evsel->handler;
3135 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX)
3141 int ret = -1;
3142 struct evlist *evlist = trace->evlist;
3159 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param);
3160 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param);
3165 if (callchain_param.enabled && !trace->kernel_syscallchains) {
3169 * debugging reasons using --kernel_syscall_callchains
3171 sys_exit->core.attr.exclude_callchain_kernel = 1;
3174 trace->syscalls.events.sys_enter = sys_enter;
3175 trace->syscalls.events.sys_exit = sys_exit;
3190 int err = -1;
3192 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier,
3193 trace->ev_qualifier_ids.nr,
3194 trace->ev_qualifier_ids.entries);
3199 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) {
3200 sys_exit = trace->syscalls.events.sys_exit;
3215 if (trace->bpf_obj == NULL)
3218 return bpf_object__find_map_by_name(trace->bpf_obj, name);
3223 trace->filter_pids.map = trace__find_bpf_map_by_name(trace, "pids_filtered");
3228 trace->syscalls.map = trace__find_bpf_map_by_name(trace, "syscalls");
3229 trace->syscalls.prog_array.sys_enter = trace__find_bpf_map_by_name(trace, "syscalls_sys_enter");
3230 trace->syscalls.prog_array.sys_exit = trace__find_bpf_map_by_name(trace, "syscalls_sys_exit");
3235 if (trace->bpf_obj == NULL)
3238 return bpf_object__find_program_by_title(trace->bpf_obj, name);
3248 scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name);
3252 if (sc->fmt && sc->fmt->alias) {
3253 …scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alia…
3269 prog_name, type, sc->name);
3271 return trace->syscalls.unaugmented_prog;
3281 …sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3282 …sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3288 …return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_…
3294 …return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_p…
3305 for (; arg < sc->nr_args; ++arg) {
3306 entry->string_args_len[arg] = 0;
3307 if (sc->arg_fmt[arg].scnprintf == SCA_FILENAME) {
3308 /* Should be set like strace -s strsize */
3309 entry->string_args_len[arg] = PATH_MAX;
3314 entry->string_args_len[arg] = 0;
3318 int fd = bpf_map__fd(trace->syscalls.map);
3320 .enabled = !trace->not_ev_qualifier,
3325 for (i = 0; i < trace->ev_qualifier_ids.nr; ++i) {
3326 int key = trace->ev_qualifier_ids.entries[i];
3343 int fd = bpf_map__fd(trace->syscalls.map);
3349 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3365 if (trace->ev_qualifier_ids.nr)
3366 enabled = trace->not_ev_qualifier;
3379 for (field = sc->args; field; field = field->next) {
3380 if (field->flags & TEP_FIELD_IS_POINTER)
3387 for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) {
3393 pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog)
3396 for (field = sc->args, candidate_field = pair->args;
3397 field && candidate_field; field = field->next, candidate_field = candidate_field->next) {
3398 bool is_pointer = field->flags & TEP_FIELD_IS_POINTER,
3399 candidate_is_pointer = candidate_field->flags & TEP_FIELD_IS_POINTER;
3414 if (strcmp(field->type, candidate_field->type))
3429 …for (candidate_field = candidate_field->next; candidate_field; candidate_field = candidate_field->…
3430 if (candidate_field->flags & TEP_FIELD_IS_POINTER)
3434 pair_prog = pair->bpf_prog.sys_enter;
3439 * program for a filtered syscall on a non-filtered one.
3445 …pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_ent…
3446 if (pair_prog == trace->syscalls.unaugmented_prog)
3450 pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->name, sc->name);
3461 int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter),
3462 map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit);
3465 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3487 * syscall with an augmenter so that we can auto-reuse it.
3512 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3517 if (sc == NULL || sc->bpf_prog.sys_enter == NULL)
3524 if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog)
3535 sc->bpf_prog.sys_enter = pair_prog;
3541 prog_fd = bpf_program__fd(sc->bpf_prog.sys_enter);
3555 evlist__remove(trace->evlist, trace->syscalls.events.augmented);
3556 evsel__delete(trace->syscalls.events.augmented);
3557 trace->syscalls.events.augmented = NULL;
3559 evlist__for_each_entry_safe(trace->evlist, tmp, evsel) {
3560 if (evsel->bpf_obj == trace->bpf_obj) {
3561 evlist__remove(trace->evlist, evsel);
3567 bpf_object__close(trace->bpf_obj);
3568 trace->bpf_obj = NULL;
3615 evlist__for_each_entry(trace->evlist, evsel) {
3616 if (evsel == trace->syscalls.events.augmented ||
3617 evsel->bpf_obj == trace->bpf_obj)
3628 if (trace->syscalls.map)
3630 if (trace->syscalls.events.sys_enter)
3659 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]);
3662 struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid);
3668 strstarts(thread__comm_str(parent), "gnome-terminal")) {
3669 pids[nr++] = parent->tid;
3675 err = perf_evlist__append_tp_filter_pids(trace->evlist, nr, pids);
3676 if (!err && trace->filter_pids.map)
3677 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids);
3691 if (trace->filter_pids.nr > 0) {
3692 err = perf_evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr,
3693 trace->filter_pids.entries);
3694 if (!err && trace->filter_pids.map) {
3695 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
3696 trace->filter_pids.entries);
3698 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
3707 struct evlist *evlist = trace->evlist;
3713 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
3722 u64 first = ordered_events__first_time(&trace->oe.data);
3723 u64 flush = trace->oe.last - NSEC_PER_SEC;
3727 return ordered_events__flush_time(&trace->oe.data, flush);
3734 return !trace->sort_events ? 0 : __trace__flush_events(trace);
3741 if (!trace->sort_events)
3744 err = perf_evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last);
3745 if (err && err != -1)
3748 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0);
3755 static int ordered_events__deliver_event(struct ordered_events *oe, argument
3758 struct trace *trace = container_of(oe, struct trace, oe.data);
3760 return __trace__deliver_event(trace, event->event);
3768 if (evsel->tp_format == NULL || fmt == NULL)
3771 for (field = evsel->tp_format->format.fields; field; field = field->next, ++fmt)
3772 if (strcmp(field->name, arg) == 0)
3780 char *tok, *left = evsel->filter, *new_filter = evsel->filter;
3809 int left_size = tok - left,
3810 right_size = right_end - right;
3813 while (isspace(left[left_size - 1]))
3814 --left_size;
3821 arg, evsel->name, evsel->filter);
3822 return -1;
3825 pr_debug2("trying to expand \"%s\" \"%.*s\" \"%.*s\" -> ",
3826 arg, (int)(right - tok), tok, right_size, right);
3828 if (fmt->strtoul) {
3831 .parm = fmt->parm,
3834 if (fmt->strtoul(right, right_size, &syscall_arg, &val)) {
3837 int expansion_offset = right - new_filter;
3844 return -1;
3846 if (new_filter != evsel->filter)
3852 right_size, right, arg, evsel->name, evsel->filter);
3853 return -1;
3857 arg, evsel->name, evsel->filter);
3858 return -1;
3867 if (new_filter != evsel->filter) {
3868 pr_debug("New filter for %s: %s\n", evsel->name, new_filter);
3878 struct evlist *evlist = trace->evlist;
3882 if (evsel->filter == NULL)
3887 return -1;
3896 struct evlist *evlist = trace->evlist;
3898 int err = -1, i;
3903 trace->live = true;
3905 if (!trace->raw_augmented_syscalls) {
3906 if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
3909 if (trace->trace_syscalls)
3910 trace->vfs_getname = evlist__add_vfs_getname(evlist);
3913 if ((trace->trace_pgfaults & TRACE_PFMAJ)) {
3917 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param);
3921 if ((trace->trace_pgfaults & TRACE_PFMIN)) {
3925 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param);
3929 if (trace->sched &&
3936 * trace -G A -e sched:*switch
3941 * trace -e sched:*switch -G A
3949 * trace -G A -e sched:*switch -G B
3955 * only for the evsels still without a cgroup, i.e. evsel->cgroup == NULL.
3957 if (trace->cgroup)
3958 evlist__set_default_cgroup(trace->evlist, trace->cgroup);
3960 err = perf_evlist__create_maps(evlist, &trace->opts.target);
3962 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n");
3968 fprintf(trace->output, "Problems initializing symbol libraries!\n");
3972 perf_evlist__config(evlist, &trace->opts, &callchain_param);
3978 err = perf_evlist__prepare_workload(evlist, &trace->opts.target,
3981 fprintf(trace->output, "Couldn't run the workload!\n");
4004 if (trace->syscalls.map)
4007 if (trace->syscalls.prog_array.sys_enter)
4010 if (trace->ev_qualifier_ids.nr > 0) {
4015 if (trace->syscalls.events.sys_exit) {
4017 trace->syscalls.events.sys_exit->filter);
4024 * fd->pathname table and were ending up showing the last value set by
4032 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close"));
4041 if (trace->dump.map)
4042 bpf_map__fprintf(trace->dump.map, trace->output);
4044 err = evlist__mmap(evlist, trace->opts.mmap_pages);
4048 if (!target__none(&trace->opts.target) && !trace->opts.initial_delay)
4054 if (trace->opts.initial_delay) {
4055 usleep(trace->opts.initial_delay * 1000);
4059 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
4060 evlist->core.threads->nr > 1 ||
4061 evlist__first(evlist)->core.attr.inherit;
4064 * Now that we already used evsel->core.attr to ask the kernel to setup the
4065 * events, lets reuse evsel->core.attr.sample_max_stack as the limit in
4066 * trace__resolve_callchain(), allowing per-event max-stack settings
4067 * to override an explicitly set --max-stack global setting.
4071 evsel->core.attr.sample_max_stack == 0)
4072 evsel->core.attr.sample_max_stack = trace->max_stack;
4075 before = trace->nr_events;
4077 for (i = 0; i < evlist->core.nr_mmaps; i++) {
4081 md = &evlist->mmap[i];
4082 if (perf_mmap__read_init(&md->core) < 0)
4085 while ((event = perf_mmap__read_event(&md->core)) != NULL) {
4086 ++trace->nr_events;
4092 perf_mmap__consume(&md->core);
4102 perf_mmap__read_done(&md->core);
4105 if (trace->nr_events == before) {
4106 int timeout = done ? 100 : -1;
4122 thread__zput(trace->current);
4126 if (trace->sort_events)
4127 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL);
4130 if (trace->summary)
4131 trace__fprintf_thread_summary(trace, trace->output);
4133 if (trace->show_tool_stats) {
4134 fprintf(trace->output, "Stats:\n "
4137 trace->stats.vfs_getname,
4138 trace->stats.proc_getname);
4146 cgroup__put(trace->cgroup);
4147 trace->evlist = NULL;
4148 trace->live = false;
4169 fprintf(trace->output, "%s\n", errbuf);
4173 fprintf(trace->output,
4175 evsel->filter, evsel__name(evsel), errno,
4180 fprintf(trace->output, "Not enough memory to run!\n");
4184 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno));
4196 .force = trace->force,
4200 int err = -1;
4202 trace->tool.sample = trace__process_sample;
4203 trace->tool.mmap = perf_event__process_mmap;
4204 trace->tool.mmap2 = perf_event__process_mmap2;
4205 trace->tool.comm = perf_event__process_comm;
4206 trace->tool.exit = perf_event__process_exit;
4207 trace->tool.fork = perf_event__process_fork;
4208 trace->tool.attr = perf_event__process_attr;
4209 trace->tool.tracing_data = perf_event__process_tracing_data;
4210 trace->tool.build_id = perf_event__process_build_id;
4211 trace->tool.namespaces = perf_event__process_namespaces;
4213 trace->tool.ordered_events = true;
4214 trace->tool.ordering_requires_timestamps = true;
4217 trace->multiple_threads = true;
4219 session = perf_session__new(&data, false, &trace->tool);
4223 if (trace->opts.target.pid)
4224 symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
4226 if (trace->opts.target.tid)
4227 symbol_conf.tid_list_str = strdup(trace->opts.target.tid);
4229 if (symbol__init(&session->header.env) < 0)
4232 trace->host = &session->machines.host;
4238 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4242 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4252 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4255 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4264 evlist__for_each_entry(session->evlist, evsel) {
4265 if (evsel->core.attr.type == PERF_TYPE_SOFTWARE &&
4266 (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ||
4267 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MIN ||
4268 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS))
4269 evsel->handler = trace__pgfault;
4278 else if (trace->summary)
4279 trace__fprintf_thread_summary(trace, trace->output);
4296 DEFINE_RESORT_RB(syscall_stats, a->msecs > b->msecs,
4303 struct syscall_stats *stats = source->priv;
4305 entry->syscall = source->i;
4306 entry->stats = stats;
4307 entry->msecs = stats ? (u64)stats->stats.n * (avg_stats(&stats->stats) / NSEC_PER_MSEC) : 0;
4316 DECLARE_RESORT_RB_INTLIST(syscall_stats, ttrace->syscall_stats);
4325 …printed += fprintf(fp, " --------------- -------- ------ -------- --------- --------- ---------
4328 struct syscall_stats *stats = syscall_stats_entry->stats;
4330 double min = (double)(stats->stats.min) / NSEC_PER_MSEC;
4331 double max = (double)(stats->stats.max) / NSEC_PER_MSEC;
4332 double avg = avg_stats(&stats->stats);
4334 u64 n = (u64)stats->stats.n;
4336 pct = avg ? 100.0 * stddev_stats(&stats->stats) / avg : 0.0;
4339 sc = &trace->syscalls.table[syscall_stats_entry->syscall];
4340 printed += fprintf(fp, " %-15s", sc->name);
4342 n, stats->nr_failures, syscall_stats_entry->msecs, min, avg);
4345 if (trace->errno_summary && stats->nr_failures) {
4346 const char *arch_name = perf_env__arch(trace->host->env);
4349 for (e = 0; e < stats->max_errno; ++e) {
4350 if (stats->errnos[e] != 0)
4351 fprintf(fp, "\t\t\t\t%s: %d\n", arch_syscalls__strerrno(arch_name, e + 1), stats->errnos[e]);
4372 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
4374 printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid);
4375 printed += fprintf(fp, "%lu events, ", ttrace->nr_events);
4377 if (ttrace->pfmaj)
4378 printed += fprintf(fp, ", %lu majfaults", ttrace->pfmaj);
4379 if (ttrace->pfmin)
4380 printed += fprintf(fp, ", %lu minfaults", ttrace->pfmin);
4381 if (trace->sched)
4382 printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms);
4393 return ttrace ? ttrace->nr_events : 0;
4396 DEFINE_RESORT_RB(threads, (thread__nr_events(a->thread->priv) < thread__nr_events(b->thread->priv)),
4400 entry->thread = rb_entry(nd, struct thread, rb_node);
4410 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
4418 printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
4428 struct trace *trace = opt->value;
4430 trace->duration_filter = atof(str);
4437 int ret = -1;
4439 struct trace *trace = opt->value;
4447 return -1;
4449 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
4450 trace->filter_pids.entries = calloc(i, sizeof(pid_t));
4452 if (trace->filter_pids.entries == NULL)
4455 trace->filter_pids.entries[0] = getpid();
4457 for (i = 1; i < trace->filter_pids.nr; ++i)
4458 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
4478 trace->output = fopen(filename, "w");
4480 return trace->output == NULL ? -errno : 0;
4486 int *trace_pgfaults = opt->value;
4495 return -1;
4505 if (evsel->handler == NULL)
4506 evsel->handler = handler;
4520 if (strcmp(evsel->tp_format->format.fields->name, "__syscall_nr") == 0 ||
4521 strcmp(evsel->tp_format->format.fields->name, "nr") == 0)
4524 memcpy(fmt + skip, scfmt->arg, (evsel->tp_format->format.nr_fields - skip) * sizeof(*fmt));
4534 if (evsel->priv || !evsel->tp_format)
4537 if (strcmp(evsel->tp_format->system, "syscalls")) {
4543 return -1;
4545 if (!strncmp(evsel->tp_format->name, "sys_enter_", 10)) {
4548 if (__tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)))
4549 return -1;
4551 evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_enter_") - 1);
4552 } else if (!strncmp(evsel->tp_format->name, "sys_exit_", 9)) {
4555 if (__tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap))
4556 return -1;
4558 evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_exit_") - 1);
4566 * XXX: Hackish, just splitting the combined -e+--event (syscalls
4568 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
4576 struct trace *trace = (struct trace *)opt->value;
4579 int len = strlen(str) + 1, err = -1, list, idx;
4585 return -1;
4589 trace->not_ev_qualifier = true;
4597 if (syscalltbl__id(trace->sctbl, s) >= 0 ||
4598 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) {
4606 s = fmt->name;
4634 trace->ev_qualifier = strlist__new(lists[1], &slist_config);
4635 if (trace->ev_qualifier == NULL) {
4636 fputs("Not enough memory to parse event qualifier", trace->output);
4642 trace->trace_syscalls = true;
4649 .value = &trace->evlist,
4662 struct trace *trace = opt->value;
4664 if (!list_empty(&trace->evlist->core.entries)) {
4666 .value = &trace->evlist,
4670 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
4681 trace->perfconfig_events = strdup(value);
4682 if (trace->perfconfig_events == NULL) {
4684 return -1;
4687 trace->show_tstamp = perf_config_bool(var, value);
4689 trace->show_duration = perf_config_bool(var, value);
4691 trace->show_arg_names = perf_config_bool(var, value);
4692 if (!trace->show_arg_names)
4693 trace->show_zeros = true;
4696 if (!trace->show_arg_names && !new_show_zeros) {
4700 trace->show_zeros = new_show_zeros;
4702 trace->show_string_prefix = perf_config_bool(var, value);
4704 trace->opts.no_inherit = perf_config_bool(var, value);
4708 trace->args_alignment = args_alignment;
4711 trace->libtraceevent_print = true;
4713 trace->libtraceevent_print = false;
4723 "perf trace [<options>] -- <command> [<options>]",
4725 "perf trace record [<options>] -- <command> [<options>]",
4769 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids",
4771 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
4772 "system-wide collection from all CPUs"),
4775 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
4777 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
4786 OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"),
4796 OPT_BOOLEAN('S', "with-summary", &trace.summary,
4798 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary,
4799 "Show errno stats per syscall, use with -s or -S"),
4804 OPT_CALLBACK(0, "call-graph", &trace.opts,
4809 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
4811 OPT_ULONG(0, "max-events", &trace.max_events,
4813 OPT_UINTEGER(0, "min-stack", &trace.min_stack,
4816 OPT_UINTEGER(0, "max-stack", &trace.max_stack,
4820 OPT_BOOLEAN(0, "sort-events", &trace.sort_events,
4822 OPT_BOOLEAN(0, "print-sample", &trace.print_sample,
4824 OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
4828 OPT_INTEGER('D', "delay", &trace.opts.initial_delay,
4838 int err = -1;
4849 err = -ENOMEM;
4857 * global setting. If it fails we'll get something in 'perf trace -v'
4871 * already figured out if -e syscall_name, if not but if --event
4873 * tracepoint events, not in the strace-like syscall-name-based mode.
4875 * This is important because we need to check if strace-like mode is
4881 trace.evlist->core.nr_entries == 0 /* Was --events used? */) {
4885 * Now that we have --verbose figured out, lets see if we need to parse
4887 * BPF program fails, then we'll be able to use --verbose to see what went
4903 "cgroup monitoring only available in system-wide mode");
4922 if (evsel->bpf_obj == NULL) {
4927 trace.bpf_obj = evsel->bpf_obj;
4931 * explicit --syscalls, then assume we want all strace-like
4938 * strace-like syscall tracing is not set, then we need to trow
4943 * style of setting up the strace-like eBPF based syscall point
4953 * 'perf trace --config determinism.profile' mode, where for some
4958 * Also --config to specify an alternate .perfconfig file needs
4977 err = -1;
5013 if (trace.evlist->core.nr_entries > 0) {
5022 ordered_events__init(&trace.oe.data, ordered_events__deliver_event, &trace);
5023 ordered_events__set_copy_on_queue(&trace.oe.data, true);
5046 if (trace.syscalls.events.augmented->priv == NULL &&
5057 augmented->handler = trace__sys_enter;
5067 evsel->handler = trace__sys_enter;
5082 * don't look after the sc->args_size but
5087 * s->args_size to the BPF augmenter (now
5096 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset;
5098 evsel->handler = trace__sys_exit;
5104 return trace__record(&trace, argc-1, &argv[1]);
5106 /* Using just --errno-summary will trigger --summary */