Lines Matching +full:avg +full:- +full:samples

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"
214 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
227 memcpy(&value, sample->raw_data + field->offset, sizeof(value)); \
237 field->offset = offset; in __tp_field__init_uint()
241 field->integer = tp_field__u8; in __tp_field__init_uint()
244 field->integer = needs_swap ? tp_field__swapped_u16 : tp_field__u16; in __tp_field__init_uint()
247 field->integer = needs_swap ? tp_field__swapped_u32 : tp_field__u32; in __tp_field__init_uint()
250 field->integer = needs_swap ? tp_field__swapped_u64 : tp_field__u64; in __tp_field__init_uint()
253 return -1; in __tp_field__init_uint()
261 return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap); in tp_field__init_uint()
266 return sample->raw_data + field->offset; in tp_field__ptr()
271 field->offset = offset; in __tp_field__init_ptr()
272 field->pointer = tp_field__ptr; in __tp_field__init_ptr()
278 return __tp_field__init_ptr(field, format_field->offset); in tp_field__init_ptr()
289 * The evsel->priv as used by 'perf trace'
308 zfree(&et->fmt); in evsel_trace__delete()
318 struct evsel_trace *et = evsel->priv; in __evsel__syscall_tp()
320 return &et->sc; in __evsel__syscall_tp()
325 if (evsel->priv == NULL) { in evsel__syscall_tp()
326 evsel->priv = evsel_trace__new(); in evsel__syscall_tp()
327 if (evsel->priv == NULL) in evsel__syscall_tp()
339 struct evsel_trace *et = evsel->priv; in __evsel__syscall_arg_fmt()
341 return et->fmt; in __evsel__syscall_arg_fmt()
346 struct evsel_trace *et = evsel->priv; in evsel__syscall_arg_fmt()
348 if (evsel->priv == NULL) { in evsel__syscall_arg_fmt()
349 et = evsel->priv = evsel_trace__new(); in evsel__syscall_arg_fmt()
355 if (et->fmt == NULL) { in evsel__syscall_arg_fmt()
356 et->fmt = calloc(evsel->tp_format->format.nr_fields, sizeof(struct syscall_arg_fmt)); in evsel__syscall_arg_fmt()
357 if (et->fmt == NULL) in evsel__syscall_arg_fmt()
364 evsel_trace__delete(evsel->priv); in evsel__syscall_arg_fmt()
365 evsel->priv = NULL; in evsel__syscall_arg_fmt()
374 return -1; in evsel__init_tp_uint_field()
376 return tp_field__init_uint(field, format_field, evsel->needs_swap); in evsel__init_tp_uint_field()
381 evsel__init_tp_uint_field(evsel, &sc->name, #name); })
388 return -1; in evsel__init_tp_ptr_field()
395 evsel__init_tp_ptr_field(evsel, &sc->name, #name); })
399 zfree(&evsel->priv); in evsel__delete_priv()
408 if (evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") && in evsel__init_syscall_tp()
409 evsel__init_tp_uint_field(evsel, &sc->id, "nr")) in evsel__init_syscall_tp()
410 return -ENOENT; in evsel__init_syscall_tp()
414 return -ENOMEM; in evsel__init_syscall_tp()
426 __tp_field__init_uint(&sc->id, syscall_id->size, syscall_id->offset, evsel->needs_swap)) in evsel__init_augmented_syscall_tp()
427 return -EINVAL; in evsel__init_augmented_syscall_tp()
432 return -ENOMEM; in evsel__init_augmented_syscall_tp()
439 return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)); in evsel__init_augmented_syscall_tp_args()
446 …return __tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap… in evsel__init_augmented_syscall_tp_ret()
453 return -ENOENT; in evsel__init_raw_syscall_tp()
455 evsel->handler = handler; in evsel__init_raw_syscall_tp()
459 return -ENOMEM; in evsel__init_raw_syscall_tp()
485 fields->name.integer(&fields->name, sample); })
489 fields->name.pointer(&fields->name, sample); })
493 int idx = val - sa->offset; in strarray__scnprintf_suffix()
495 if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) { in strarray__scnprintf_suffix()
498 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix); in strarray__scnprintf_suffix()
502 return scnprintf(bf, size, "%s%s", sa->entries[idx], show_suffix ? sa->prefix : ""); in strarray__scnprintf_suffix()
507 int idx = val - sa->offset; in strarray__scnprintf()
509 if (idx < 0 || idx >= sa->nr_entries || sa->entries[idx] == NULL) { in strarray__scnprintf()
512 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sa->prefix); in strarray__scnprintf()
516 return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); in strarray__scnprintf()
523 return strarray__scnprintf(arg->parm, bf, size, intfmt, arg->show_string_prefix, arg->val); in __syscall_arg__scnprintf_strarray()
536 return strarray__strtoul(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarray()
541 return strarray__strtoul_flags(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarray_flags()
546 return strarrays__strtoul(arg->parm, bf, size, ret); in syscall_arg__strtoul_strarrays()
551 return strarray__scnprintf_flags(arg->parm, bf, size, arg->show_string_prefix, arg->val); in syscall_arg__scnprintf_strarray_flags()
559 for (i = 0; i < sas->nr_entries; ++i) { in strarrays__scnprintf()
560 struct strarray *sa = sas->entries[i]; in strarrays__scnprintf()
561 int idx = val - sa->offset; in strarrays__scnprintf()
563 if (idx >= 0 && idx < sa->nr_entries) { in strarrays__scnprintf()
564 if (sa->entries[idx] == NULL) in strarrays__scnprintf()
566 return scnprintf(bf, size, "%s%s", show_prefix ? sa->prefix : "", sa->entries[idx]); in strarrays__scnprintf()
572 printed += scnprintf(bf + printed, size - printed, " /* %s??? */", sas->entries[0]->prefix); in strarrays__scnprintf()
580 for (i = 0; i < sa->nr_entries; ++i) { in strarray__strtoul()
581 if (sa->entries[i] && strncmp(sa->entries[i], bf, size) == 0 && sa->entries[i][size] == '\0') { in strarray__strtoul()
582 *ret = sa->offset + i; in strarray__strtoul()
602 size -= sep - tok + 1; in strarray__strtoul_flags()
604 end = sep - 1; in strarray__strtoul_flags()
606 --end; in strarray__strtoul_flags()
608 toklen = end - tok + 1; in strarray__strtoul_flags()
623 *ret |= (1 << (val - 1)); in strarray__strtoul_flags()
637 for (i = 0; i < sas->nr_entries; ++i) { in strarrays__strtoul()
638 struct strarray *sa = sas->entries[i]; in strarrays__strtoul()
650 return strarrays__scnprintf(arg->parm, bf, size, "%d", arg->show_string_prefix, arg->val); in syscall_arg__scnprintf_strarrays()
654 #define AT_FDCWD -100
660 int fd = arg->val; in syscall_arg__scnprintf_fd_at()
664 return scnprintf(bf, size, "%s%s", arg->show_string_prefix ? prefix : "", "CWD"); in syscall_arg__scnprintf_fd_at()
678 return scnprintf(bf, size, "%#lx", arg->val); in syscall_arg__scnprintf_hex()
683 if (arg->val == 0) in syscall_arg__scnprintf_ptr()
690 return scnprintf(bf, size, "%d", arg->val); in syscall_arg__scnprintf_int()
695 return scnprintf(bf, size, "%ld", arg->val); in syscall_arg__scnprintf_long()
703 return scnprintf(bf, size, "\"%-.*s\"", arg->fmt->nr_entries ?: arg->len, arg->val); in syscall_arg__scnprintf_char_array()
791 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_access_mode()
794 int mode = arg->val; in syscall_arg__scnprintf_access_mode()
800 printed += scnprintf(bf + printed, size - printed, "%s%s", #n, show_prefix ? suffix : ""); \ in syscall_arg__scnprintf_access_mode()
810 printed += scnprintf(bf + printed, size - printed, "|%#x", mode); in syscall_arg__scnprintf_access_mode()
825 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_pipe_flags()
827 int printed = 0, flags = arg->val; in syscall_arg__scnprintf_pipe_flags()
831 …printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? pre… in syscall_arg__scnprintf_pipe_flags()
840 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); in syscall_arg__scnprintf_pipe_flags()
857 bool show_prefix = arg->show_string_prefix; in syscall_arg__scnprintf_getrandom_flags()
859 int printed = 0, flags = arg->val; in syscall_arg__scnprintf_getrandom_flags()
863 …printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? pre… in syscall_arg__scnprintf_getrandom_flags()
872 printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags); in syscall_arg__scnprintf_getrandom_flags()
1157 return strcmp(name, fmt->name); in syscall_fmt__cmp()
1280 ttrace->files.max = -1; in thread_trace__new()
1281 ttrace->syscall_stats = intlist__new(NULL); in thread_trace__new()
1301 ++ttrace->nr_events; in thread__trace()
1306 "WARNING: not enough memory, dropping samples!\n"); in thread__trace()
1314 struct thread_trace *ttrace = thread__priv(arg->thread); in syscall_arg__set_ret_scnprintf()
1316 ttrace->ret_scnprintf = ret_scnprintf; in syscall_arg__set_ret_scnprintf()
1329 if (fd > ttrace->files.max) { in thread_trace__files_entry()
1330 struct file *nfiles = realloc(ttrace->files.table, (fd + 1) * sizeof(struct file)); in thread_trace__files_entry()
1335 if (ttrace->files.max != -1) { in thread_trace__files_entry()
1336 memset(nfiles + ttrace->files.max + 1, 0, in thread_trace__files_entry()
1337 (fd - ttrace->files.max) * sizeof(struct file)); in thread_trace__files_entry()
1342 ttrace->files.table = nfiles; in thread_trace__files_entry()
1343 ttrace->files.max = fd; in thread_trace__files_entry()
1346 return ttrace->files.table + fd; in thread_trace__files_entry()
1362 file->dev_maj = major(st.st_rdev); in trace__set_fd_pathname()
1363 file->pathname = strdup(pathname); in trace__set_fd_pathname()
1364 if (file->pathname) in trace__set_fd_pathname()
1368 return -1; in trace__set_fd_pathname()
1377 if (thread->pid_ == thread->tid) { in thread__read_fd_path()
1379 "/proc/%d/fd/%d", thread->pid_, fd); in thread__read_fd_path()
1382 "/proc/%d/task/%d/fd/%d", thread->pid_, thread->tid, fd); in thread__read_fd_path()
1386 return -1; in thread__read_fd_path()
1391 return -1; in thread__read_fd_path()
1402 if (ttrace == NULL || trace->fd_path_disabled) in thread__fd_path()
1408 if ((fd > ttrace->files.max || ttrace->files.table[fd].pathname == NULL)) { in thread__fd_path()
1409 if (!trace->live) in thread__fd_path()
1411 ++trace->stats.proc_getname; in thread__fd_path()
1416 return ttrace->files.table[fd].pathname; in thread__fd_path()
1421 int fd = arg->val; in syscall_arg__scnprintf_fd()
1423 const char *path = thread__fd_path(arg->thread, fd, arg->trace); in syscall_arg__scnprintf_fd()
1426 printed += scnprintf(bf + printed, size - printed, "<%s>", path); in syscall_arg__scnprintf_fd()
1434 struct thread *thread = machine__find_thread(trace->host, pid, pid); in pid__scnprintf_fd()
1440 printed += scnprintf(bf + printed, size - printed, "<%s>", path); in pid__scnprintf_fd()
1451 int fd = arg->val; in syscall_arg__scnprintf_close_fd()
1453 struct thread_trace *ttrace = thread__priv(arg->thread); in syscall_arg__scnprintf_close_fd()
1455 if (ttrace && fd >= 0 && fd <= ttrace->files.max) in syscall_arg__scnprintf_close_fd()
1456 zfree(&ttrace->files.table[fd].pathname); in syscall_arg__scnprintf_close_fd()
1466 ttrace->filename.ptr = ptr; in thread__set_filename_pos()
1467 ttrace->filename.entry_str_pos = bf - ttrace->entry_str; in thread__set_filename_pos()
1472 struct augmented_arg *augmented_arg = arg->augmented.args; in syscall_arg__scnprintf_augmented_string()
1473 size_t printed = scnprintf(bf, size, "\"%.*s\"", augmented_arg->size, augmented_arg->value); in syscall_arg__scnprintf_augmented_string()
1478 int consumed = sizeof(*augmented_arg) + augmented_arg->size; in syscall_arg__scnprintf_augmented_string()
1480 arg->augmented.args = ((void *)arg->augmented.args) + consumed; in syscall_arg__scnprintf_augmented_string()
1481 arg->augmented.size -= consumed; in syscall_arg__scnprintf_augmented_string()
1489 unsigned long ptr = arg->val; in syscall_arg__scnprintf_filename()
1491 if (arg->augmented.args) in syscall_arg__scnprintf_filename()
1494 if (!arg->trace->vfs_getname) in syscall_arg__scnprintf_filename()
1497 thread__set_filename_pos(arg->thread, bf, ptr); in syscall_arg__scnprintf_filename()
1503 return t < (trace->duration_filter * NSEC_PER_MSEC); in trace__filter_duration()
1508 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; in __trace__fprintf_tstamp()
1515 * using ttrace->entry_time for a thread that receives a sys_exit without
1540 if (trace->multiple_threads) { in trace__fprintf_comm_tid()
1541 if (trace->show_comm) in trace__fprintf_comm_tid()
1543 printed += fprintf(fp, "%d ", thread->tid); in trace__fprintf_comm_tid()
1554 if (trace->show_tstamp) in trace__fprintf_entry_head()
1556 if (trace->show_duration) in trace__fprintf_entry_head()
1566 switch (event->header.type) { in trace__process_event()
1568 color_fprintf(trace->output, PERF_COLOR_RED, in trace__process_event()
1569 "LOST %" PRIu64 " events!\n", event->lost.lost); in trace__process_event()
1593 if (machine->kptr_restrict_warned) in trace__machine__resolve_kernel_addr()
1599 "Kernel samples will not be resolved.\n"); in trace__machine__resolve_kernel_addr()
1600 machine->kptr_restrict_warned = true; in trace__machine__resolve_kernel_addr()
1614 trace->host = machine__new_host(); in trace__symbols_init()
1615 if (trace->host == NULL) in trace__symbols_init()
1616 return -ENOMEM; in trace__symbols_init()
1618 err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr); in trace__symbols_init()
1622 err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target, in trace__symbols_init()
1623 evlist->core.threads, trace__tool_process, false, in trace__symbols_init()
1634 machine__exit(trace->host); in trace__symbols__exit()
1635 trace->host = NULL; in trace__symbols__exit()
1644 if (nr_args == 6 && sc->fmt && sc->fmt->nr_args != 0) in syscall__alloc_arg_fmts()
1645 nr_args = sc->fmt->nr_args; in syscall__alloc_arg_fmts()
1647 sc->arg_fmt = calloc(nr_args, sizeof(*sc->arg_fmt)); in syscall__alloc_arg_fmts()
1648 if (sc->arg_fmt == NULL) in syscall__alloc_arg_fmts()
1649 return -1; in syscall__alloc_arg_fmts()
1652 if (sc->fmt) in syscall__alloc_arg_fmts()
1653 sc->arg_fmt[idx] = sc->fmt->arg[idx]; in syscall__alloc_arg_fmts()
1656 sc->nr_args = nr_args; in syscall__alloc_arg_fmts()
1668 return strcmp(name, fmt->name); in syscall_arg_fmt__cmp()
1689 for (; field; field = field->next, ++arg) { in syscall_arg_fmt__init_array()
1692 if (arg->scnprintf) in syscall_arg_fmt__init_array()
1695 len = strlen(field->name); in syscall_arg_fmt__init_array()
1697 if (strcmp(field->type, "const char *") == 0 && in syscall_arg_fmt__init_array()
1698 ((len >= 4 && strcmp(field->name + len - 4, "name") == 0) || in syscall_arg_fmt__init_array()
1699 strstr(field->name, "path") != NULL)) in syscall_arg_fmt__init_array()
1700 arg->scnprintf = SCA_FILENAME; in syscall_arg_fmt__init_array()
1701 else if ((field->flags & TEP_FIELD_IS_POINTER) || strstr(field->name, "addr")) in syscall_arg_fmt__init_array()
1702 arg->scnprintf = SCA_PTR; in syscall_arg_fmt__init_array()
1703 else if (strcmp(field->type, "pid_t") == 0) in syscall_arg_fmt__init_array()
1704 arg->scnprintf = SCA_PID; in syscall_arg_fmt__init_array()
1705 else if (strcmp(field->type, "umode_t") == 0) in syscall_arg_fmt__init_array()
1706 arg->scnprintf = SCA_MODE_T; in syscall_arg_fmt__init_array()
1707 else if ((field->flags & TEP_FIELD_IS_ARRAY) && strstr(field->type, "char")) { in syscall_arg_fmt__init_array()
1708 arg->scnprintf = SCA_CHAR_ARRAY; in syscall_arg_fmt__init_array()
1709 arg->nr_entries = field->arraylen; in syscall_arg_fmt__init_array()
1710 } else if ((strcmp(field->type, "int") == 0 || in syscall_arg_fmt__init_array()
1711 strcmp(field->type, "unsigned int") == 0 || in syscall_arg_fmt__init_array()
1712 strcmp(field->type, "long") == 0) && in syscall_arg_fmt__init_array()
1713 len >= 2 && strcmp(field->name + len - 2, "fd") == 0) { in syscall_arg_fmt__init_array()
1716 * egrep 'field:.*fd;' .../format|sed -r 's/.*field:([a-z ]+) [a-z_]*fd.+/\1/g'|sort|uniq -c in syscall_arg_fmt__init_array()
1721 arg->scnprintf = SCA_FD; in syscall_arg_fmt__init_array()
1723 struct syscall_arg_fmt *fmt = syscall_arg_fmt__find_by_name(field->name); in syscall_arg_fmt__init_array()
1726 arg->scnprintf = fmt->scnprintf; in syscall_arg_fmt__init_array()
1727 arg->strtoul = fmt->strtoul; in syscall_arg_fmt__init_array()
1737 struct tep_format_field *last_field = syscall_arg_fmt__init_array(sc->arg_fmt, sc->args); in syscall__set_arg_fmts()
1740 sc->args_size = last_field->offset + last_field->size; in syscall__set_arg_fmts()
1749 const char *name = syscalltbl__name(trace->sctbl, id); in trace__read_syscall_info()
1752 if (trace->syscalls.table == NULL) { in trace__read_syscall_info()
1753 trace->syscalls.table = calloc(trace->sctbl->syscalls.max_id + 1, sizeof(*sc)); in trace__read_syscall_info()
1754 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1755 return -ENOMEM; in trace__read_syscall_info()
1758 if (id > trace->sctbl->syscalls.max_id || (id == 0 && trace->syscalls.table == NULL)) { in trace__read_syscall_info()
1760 struct syscall *table = realloc(trace->syscalls.table, (id + 1) * sizeof(*sc)); in trace__read_syscall_info()
1763 return -ENOMEM; in trace__read_syscall_info()
1766 if (trace->syscalls.table == NULL) in trace__read_syscall_info()
1769 …memset(table + trace->sctbl->syscalls.max_id + 1, 0, (id - trace->sctbl->syscalls.max_id) * sizeof… in trace__read_syscall_info()
1771 trace->syscalls.table = table; in trace__read_syscall_info()
1772 trace->sctbl->syscalls.max_id = id; in trace__read_syscall_info()
1775 sc = trace->syscalls.table + id; in trace__read_syscall_info()
1776 if (sc->nonexistent) in trace__read_syscall_info()
1780 sc->nonexistent = true; in trace__read_syscall_info()
1784 sc->name = name; in trace__read_syscall_info()
1785 sc->fmt = syscall_fmt__find(sc->name); in trace__read_syscall_info()
1787 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); in trace__read_syscall_info()
1788 sc->tp_format = trace_event__tp_format("syscalls", tp_name); in trace__read_syscall_info()
1790 if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) { in trace__read_syscall_info()
1791 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); in trace__read_syscall_info()
1792 sc->tp_format = trace_event__tp_format("syscalls", tp_name); in trace__read_syscall_info()
1795 if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? 6 : sc->tp_format->format.nr_fields)) in trace__read_syscall_info()
1796 return -ENOMEM; in trace__read_syscall_info()
1798 if (IS_ERR(sc->tp_format)) in trace__read_syscall_info()
1799 return PTR_ERR(sc->tp_format); in trace__read_syscall_info()
1801 sc->args = sc->tp_format->format.fields; in trace__read_syscall_info()
1807 if (sc->args && (!strcmp(sc->args->name, "__syscall_nr") || !strcmp(sc->args->name, "nr"))) { in trace__read_syscall_info()
1808 sc->args = sc->args->next; in trace__read_syscall_info()
1809 --sc->nr_args; in trace__read_syscall_info()
1812 sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit"); in trace__read_syscall_info()
1813 sc->is_open = !strcmp(name, "open") || !strcmp(name, "openat"); in trace__read_syscall_info()
1823 syscall_arg_fmt__init_array(fmt, evsel->tp_format->format.fields); in evsel__init_tp_arg_scnprintf()
1827 return -ENOMEM; in evsel__init_tp_arg_scnprintf()
1834 return *one - *another; in intcmp()
1842 size_t nr_used = 0, nr_allocated = strlist__nr_entries(trace->ev_qualifier); in trace__validate_ev_qualifier()
1844 trace->ev_qualifier_ids.entries = malloc(nr_allocated * in trace__validate_ev_qualifier()
1845 sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1847 if (trace->ev_qualifier_ids.entries == NULL) { in trace__validate_ev_qualifier()
1849 trace->output); in trace__validate_ev_qualifier()
1850 err = -EINVAL; in trace__validate_ev_qualifier()
1854 strlist__for_each_entry(pos, trace->ev_qualifier) { in trace__validate_ev_qualifier()
1855 const char *sc = pos->s; in trace__validate_ev_qualifier()
1856 int id = syscalltbl__id(trace->sctbl, sc), match_next = -1; in trace__validate_ev_qualifier()
1859 id = syscalltbl__strglobmatch_first(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1874 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1875 if (match_next == -1) in trace__validate_ev_qualifier()
1879 id = syscalltbl__strglobmatch_next(trace->sctbl, sc, &match_next); in trace__validate_ev_qualifier()
1886 entries = realloc(trace->ev_qualifier_ids.entries, in trace__validate_ev_qualifier()
1887 nr_allocated * sizeof(trace->ev_qualifier_ids.entries[0])); in trace__validate_ev_qualifier()
1889 err = -ENOMEM; in trace__validate_ev_qualifier()
1890 fputs("\nError:\t Not enough memory for parsing\n", trace->output); in trace__validate_ev_qualifier()
1893 trace->ev_qualifier_ids.entries = entries; in trace__validate_ev_qualifier()
1895 trace->ev_qualifier_ids.entries[nr_used++] = id; in trace__validate_ev_qualifier()
1899 trace->ev_qualifier_ids.nr = nr_used; in trace__validate_ev_qualifier()
1900 qsort(trace->ev_qualifier_ids.entries, nr_used, sizeof(int), intcmp); in trace__validate_ev_qualifier()
1906 zfree(&trace->ev_qualifier_ids.entries); in trace__validate_ev_qualifier()
1907 trace->ev_qualifier_ids.nr = 0; in trace__validate_ev_qualifier()
1915 if (trace->ev_qualifier_ids.nr == 0) in trace__syscall_enabled()
1918 in_ev_qualifier = bsearch(&id, trace->ev_qualifier_ids.entries, in trace__syscall_enabled()
1919 trace->ev_qualifier_ids.nr, sizeof(int), intcmp) != NULL; in trace__syscall_enabled()
1922 return !trace->not_ev_qualifier; in trace__syscall_enabled()
1924 return trace->not_ev_qualifier; in trace__syscall_enabled()
1929 * 8-byte unaligned accesses. args points to raw_data within the event
1930 * and raw_data is guaranteed to be 8-byte unaligned because it is
1938 unsigned char *p = arg->args + sizeof(unsigned long) * idx; in syscall_arg__val()
1947 if (sc->arg_fmt && sc->arg_fmt[arg->idx].name) in syscall__scnprintf_name()
1948 return scnprintf(bf, size, "%s: ", sc->arg_fmt[arg->idx].name); in syscall__scnprintf_name()
1950 return scnprintf(bf, size, "arg%d: ", arg->idx); in syscall__scnprintf_name()
1960 if (fmt && fmt->mask_val) in syscall_arg_fmt__mask_val()
1961 return fmt->mask_val(arg, val); in syscall_arg_fmt__mask_val()
1969 if (fmt && fmt->scnprintf) { in syscall_arg_fmt__scnprintf_val()
1970 arg->val = val; in syscall_arg_fmt__scnprintf_val()
1971 if (fmt->parm) in syscall_arg_fmt__scnprintf_val()
1972 arg->parm = fmt->parm; in syscall_arg_fmt__scnprintf_val()
1973 return fmt->scnprintf(bf, size, arg); in syscall_arg_fmt__scnprintf_val()
1995 .show_string_prefix = trace->show_string_prefix, in syscall__scnprintf_args()
2004 ttrace->ret_scnprintf = NULL; in syscall__scnprintf_args()
2006 if (sc->args != NULL) { in syscall__scnprintf_args()
2009 for (field = sc->args; field; in syscall__scnprintf_args()
2010 field = field->next, ++arg.idx, bit <<= 1) { in syscall__scnprintf_args()
2014 arg.fmt = &sc->arg_fmt[arg.idx]; in syscall__scnprintf_args()
2020 val = syscall_arg_fmt__mask_val(&sc->arg_fmt[arg.idx], &arg, val); in syscall__scnprintf_args()
2028 !trace->show_zeros && in syscall__scnprintf_args()
2029 !(sc->arg_fmt && in syscall__scnprintf_args()
2030 (sc->arg_fmt[arg.idx].show_zero || in syscall__scnprintf_args()
2031 sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAY || in syscall__scnprintf_args()
2032 sc->arg_fmt[arg.idx].scnprintf == SCA_STRARRAYS) && in syscall__scnprintf_args()
2033 sc->arg_fmt[arg.idx].parm)) in syscall__scnprintf_args()
2036 printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : ""); in syscall__scnprintf_args()
2038 if (trace->show_arg_names) in syscall__scnprintf_args()
2039 printed += scnprintf(bf + printed, size - printed, "%s: ", field->name); in syscall__scnprintf_args()
2041 printed += syscall_arg_fmt__scnprintf_val(&sc->arg_fmt[arg.idx], in syscall__scnprintf_args()
2042 bf + printed, size - printed, &arg, val); in syscall__scnprintf_args()
2044 } else if (IS_ERR(sc->tp_format)) { in syscall__scnprintf_args()
2050 while (arg.idx < sc->nr_args) { in syscall__scnprintf_args()
2055 printed += scnprintf(bf + printed, size - printed, ", "); in syscall__scnprintf_args()
2056 printed += syscall__scnprintf_name(sc, bf + printed, size - printed, &arg); in syscall__scnprintf_args()
2057 …printed += syscall_arg_fmt__scnprintf_val(&sc->arg_fmt[arg.idx], bf + printed, size - printed, &ar… in syscall__scnprintf_args()
2084 * grep "NR -1 " /t/trace_pipe
2090 fprintf(trace->output, "Invalid syscall %d id, skipping (%s, %" PRIu64 ") ...\n",
2096 err = -EINVAL;
2099 if (id > trace->sctbl->syscalls.max_id) {
2101 if (id >= trace->sctbl->syscalls.max_id) {
2113 if ((trace->syscalls.table == NULL || trace->syscalls.table[id].name == NULL) &&
2117 if (trace->syscalls.table[id].name == NULL) {
2118 if (trace->syscalls.table[id].nonexistent)
2123 return &trace->syscalls.table[id];
2128 …fprintf(trace->output, "Problems reading syscall %d: %d (%s)", id, -err, str_error_r(-err, sbuf, s…
2129 if (id <= trace->sctbl->syscalls.max_id && trace->syscalls.table[id].name != NULL)
2130 fprintf(trace->output, "(%s)", trace->syscalls.table[id].name);
2131 fputs(" information\n", trace->output);
2150 inode = intlist__findnew(ttrace->syscall_stats, id);
2154 stats = inode->priv;
2160 stats->nr_failures = 0;
2161 stats->max_errno = 0;
2162 stats->errnos = NULL;
2163 init_stats(&stats->stats);
2164 inode->priv = stats;
2167 if (ttrace->entry_time && sample->time > ttrace->entry_time)
2168 duration = sample->time - ttrace->entry_time;
2170 update_stats(&stats->stats, duration);
2173 ++stats->nr_failures;
2178 err = -err;
2179 if (err > stats->max_errno) {
2180 u32 *new_errnos = realloc(stats->errnos, err * sizeof(u32));
2183 memset(new_errnos + stats->max_errno, 0, (err - stats->max_errno) * sizeof(u32));
2186 thread__comm_str(thread), thread->pid_, thread->tid);
2190 stats->errnos = new_errnos;
2191 stats->max_errno = err;
2194 ++stats->errnos[err - 1];
2204 if (trace->failure_only || trace->current == NULL)
2207 ttrace = thread__priv(trace->current);
2209 if (!ttrace->entry_pending)
2212 …printed = trace__fprintf_entry_head(trace, trace->current, 0, false, ttrace->entry_time, trace->o…
2213 printed += len = fprintf(trace->output, "%s)", ttrace->entry_str);
2215 if (len < trace->args_alignment - 4)
2216 printed += fprintf(trace->output, "%-*s", trace->args_alignment - 4 - len, " ");
2218 printed += fprintf(trace->output, " ...\n");
2220 ttrace->entry_pending = false;
2221 ++trace->nr_events_printed;
2231 if (trace->print_sample) {
2232 double ts = (double)sample->time / NSEC_PER_MSEC;
2234 printed += fprintf(trace->output, "%22s %10.3f %s %d/%d [%d]\n",
2237 sample->pid, sample->tid, sample->cpu);
2251 * sc->args_size but always after the full raw_syscalls:sys_enter payload,
2254 * We'll revisit this later to pass s->args_size to the BPF augmenter
2260 int args_size = raw_augmented_args_size ?: sc->args_size;
2262 *augmented_args_size = sample->raw_size - args_size;
2264 augmented_args = sample->raw_data + args_size;
2277 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
2284 return -1;
2286 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2287 ttrace = thread__trace(thread, trace->output);
2295 if (ttrace->entry_str == NULL) {
2296 ttrace->entry_str = malloc(trace__entry_str_size);
2297 if (!ttrace->entry_str)
2301 if (!(trace->duration_filter || trace->summary_only || trace->min_stack))
2307 * syscall->args_size using each syscalls:sys_enter_NAME tracefs format file,
2313 if (evsel != trace->syscalls.events.sys_enter)
2314 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2315 ttrace->entry_time = sample->time;
2316 msg = ttrace->entry_str;
2317 printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name);
2319 printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed,
2322 if (sc->is_exit) {
2323 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
2326 trace__fprintf_entry_head(trace, thread, 0, false, ttrace->entry_time, trace->output);
2327 printed = fprintf(trace->output, "%s)", ttrace->entry_str);
2328 if (trace->args_alignment > printed)
2329 alignment = trace->args_alignment - printed;
2330 fprintf(trace->output, "%*s= ?\n", alignment, " ");
2333 ttrace->entry_pending = true;
2335 ttrace->filename.pending_open = false;
2338 if (trace->current != thread) {
2339 thread__put(trace->current);
2340 trace->current = thread__get(thread);
2353 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
2360 return -1;
2362 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2363 ttrace = thread__trace(thread, trace->output);
2372 …augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_sy…
2374 fprintf(trace->output, "%s", msg);
2386 int max_stack = evsel->core.attr.sample_max_stack ?
2387 evsel->core.attr.sample_max_stack :
2388 trace->max_stack;
2391 if (machine__resolve(trace->host, &al, sample) < 0)
2392 return -1;
2401 /* TODO: user-configurable print_opts */
2406 …intf_callchain(sample, 38, print_opts, &callchain_cursor, symbol_conf.bt_stop_list, trace->output);
2425 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1, callchain_ret = 0, printed = 0;
2426 int alignment = trace->args_alignment;
2431 return -1;
2433 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2434 ttrace = thread__trace(thread, trace->output);
2442 if (trace->summary)
2443 thread__update_stats(thread, ttrace, id, sample, ret, trace->errno_summary);
2445 if (!trace->fd_path_disabled && sc->is_open && ret >= 0 && ttrace->filename.pending_open) {
2446 trace__set_fd_pathname(thread, ret, ttrace->filename.name);
2447 ttrace->filename.pending_open = false;
2448 ++trace->stats.vfs_getname;
2451 if (ttrace->entry_time) {
2452 duration = sample->time - ttrace->entry_time;
2456 } else if (trace->duration_filter)
2459 if (sample->callchain) {
2462 if (callchain_cursor.nr < trace->min_stack)
2468 if (trace->summary_only || (ret >= 0 && trace->failure_only))
2471 …trace__fprintf_entry_head(trace, thread, duration, duration_calculated, ttrace->entry_time, trace-
2473 if (ttrace->entry_pending) {
2474 printed = fprintf(trace->output, "%s", ttrace->entry_str);
2476 printed += fprintf(trace->output, " ... [");
2477 color_fprintf(trace->output, PERF_COLOR_YELLOW, "continued");
2479 printed += fprintf(trace->output, "]: %s()", sc->name);
2485 alignment -= printed;
2489 fprintf(trace->output, ")%*s= ", alignment, " ");
2491 if (sc->fmt == NULL) {
2495 fprintf(trace->output, "%ld", ret);
2499 const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
2500 *e = errno_to_name(evsel, -ret);
2502 fprintf(trace->output, "-1 %s (%s)", e, emsg);
2504 } else if (ret == 0 && sc->fmt->timeout)
2505 fprintf(trace->output, "0 (Timeout)");
2506 else if (ttrace->ret_scnprintf) {
2513 ttrace->ret_scnprintf(bf, sizeof(bf), &arg);
2514 ttrace->ret_scnprintf = NULL;
2515 fprintf(trace->output, "%s", bf);
2516 } else if (sc->fmt->hexret)
2517 fprintf(trace->output, "%#lx", ret);
2518 else if (sc->fmt->errpid) {
2519 struct thread *child = machine__find_thread(trace->host, ret, ret);
2522 fprintf(trace->output, "%ld", ret);
2523 if (child->comm_set)
2524 fprintf(trace->output, " (%s)", thread__comm_str(child));
2530 fputc('\n', trace->output);
2533 * We only consider an 'event' for the sake of --max-events a non-filtered
2536 if (++trace->nr_events_printed == trace->max_events && trace->max_events != ULONG_MAX)
2544 ttrace->entry_pending = false;
2555 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2573 if (ttrace->filename.namelen < filename_len) {
2574 char *f = realloc(ttrace->filename.name, filename_len + 1);
2579 ttrace->filename.namelen = filename_len;
2580 ttrace->filename.name = f;
2583 strcpy(ttrace->filename.name, filename);
2584 ttrace->filename.pending_open = true;
2586 if (!ttrace->filename.ptr)
2589 entry_str_len = strlen(ttrace->entry_str);
2590 remaining_space = trace__entry_str_size - entry_str_len - 1; /* \0 */
2595 filename += filename_len - remaining_space;
2599 to_move = entry_str_len - ttrace->filename.entry_str_pos + 1; /* \0 */
2600 pos = ttrace->entry_str + ttrace->filename.entry_str_pos;
2604 ttrace->filename.ptr = 0;
2605 ttrace->filename.entry_str_pos = 0;
2618 struct thread *thread = machine__findnew_thread(trace->host,
2619 sample->pid,
2620 sample->tid);
2621 struct thread_trace *ttrace = thread__trace(thread, trace->output);
2626 ttrace->runtime_ms += runtime_ms;
2627 trace->runtime_ms += runtime_ms;
2633 fprintf(trace->output, "%s: comm=%s,pid=%u,runtime=%" PRIu64 ",vruntime=%" PRIu64 ")\n",
2634 evsel->name,
2669 binary__fprintf(sample->raw_data, sample->raw_size, 8,
2670 bpf_output__printer, NULL, trace->output);
2671 ++trace->nr_events_printed;
2679 struct tep_format_field *field = evsel->tp_format->format.fields;
2693 .show_string_prefix = trace->show_string_prefix,
2696 for (; field && arg; field = field->next, ++syscall_arg.idx, bit <<= 1, ++arg) {
2702 if (field->flags & TEP_FIELD_IS_ARRAY) {
2703 int offset = field->offset;
2705 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
2706 offset = format_field__intval(field, sample, evsel->needs_swap);
2711 val = (uintptr_t)(sample->raw_data + offset);
2713 val = format_field__intval(field, sample, evsel->needs_swap);
2726 !trace->show_zeros &&
2727 !((arg->show_zero ||
2728 arg->scnprintf == SCA_STRARRAY ||
2729 arg->scnprintf == SCA_STRARRAYS) &&
2730 arg->parm))
2733 printed += scnprintf(bf + printed, size - printed, "%s", printed ? ", " : "");
2739 if (1 || trace->show_arg_names)
2740 printed += scnprintf(bf + printed, size - printed, "%s: ", field->name);
2742 printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val);
2745 return printed + fprintf(trace->output, "%s", bf);
2760 if (evsel->disabled)
2763 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2765 if (sample->callchain) {
2768 if (callchain_cursor.nr < trace->min_stack)
2775 trace__fprintf_tstamp(trace, sample->time, trace->output);
2777 if (trace->trace_syscalls && trace->show_duration)
2778 fprintf(trace->output, "( ): ");
2781 trace__fprintf_comm_tid(trace, thread, trace->output);
2783 if (evsel == trace->syscalls.events.augmented) {
2788 fprintf(trace->output, "%s(", sc->name);
2790 fputc(')', trace->output);
2801 fprintf(trace->output, "%s(", evsel->name);
2805 } else if (evsel->tp_format) {
2806 if (strncmp(evsel->tp_format->name, "sys_enter_", 10) ||
2808 if (trace->libtraceevent_print) {
2809 event_format__fprintf(evsel->tp_format, sample->cpu,
2810 sample->raw_data, sample->raw_size,
2811 trace->output);
2819 fprintf(trace->output, ")\n");
2826 ++trace->nr_events_printed;
2828 if (evsel->max_events != ULONG_MAX && ++evsel->nr_events_printed == evsel->max_events) {
2842 if ((verbose > 0 || print_dso) && al->map)
2843 fprintf(f, "%s@", al->map->dso->long_name);
2845 if ((verbose > 0 || print_sym) && al->sym)
2846 fprintf(f, "%s+0x%" PRIx64, al->sym->name,
2847 al->addr - al->sym->start);
2848 else if (al->map)
2849 fprintf(f, "0x%" PRIx64, al->addr);
2851 fprintf(f, "0x%" PRIx64, sample->addr);
2863 int err = -1;
2866 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2868 if (sample->callchain) {
2871 if (callchain_cursor.nr < trace->min_stack)
2877 ttrace = thread__trace(thread, trace->output);
2881 if (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)
2882 ttrace->pfmaj++;
2884 ttrace->pfmin++;
2886 if (trace->summary_only)
2889 thread__find_symbol(thread, sample->cpumode, sample->ip, &al);
2891 trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
2893 fprintf(trace->output, "%sfault [",
2894 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ?
2897 print_location(trace->output, sample, &al, false, true);
2899 fprintf(trace->output, "] => ");
2901 thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
2904 thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
2912 print_location(trace->output, sample, &al, true, false);
2914 fprintf(trace->output, " (%c%c)\n", map_type, al.level);
2921 ++trace->nr_events_printed;
2935 * and don't use sample->time unconditionally, we may end up having
2941 if (trace->base_time == 0 && !trace->full_time &&
2942 (evsel->core.attr.sample_type & PERF_SAMPLE_TIME))
2943 trace->base_time = sample->time;
2956 tracepoint_handler handler = evsel->handler;
2958 thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2965 ++trace->nr_events;
2979 "-R",
2980 "-m", "1024",
2981 "-c", "1",
2985 const char * const sc_args[] = { "-e", };
2987 const char * const majpf_args[] = { "-e", "major-faults" };
2989 const char * const minpf_args[] = { "-e", "minor-faults" };
2991 int err = -1;
3005 if (trace->trace_syscalls) {
3009 /* event string may be different for older kernels - e.g., RHEL6 */
3020 rec_argv[j++] = "--filter";
3023 if (trace->trace_pgfaults & TRACE_PFMAJ)
3027 if (trace->trace_pgfaults & TRACE_PFMIN)
3065 evsel->handler = trace__vfs_getname;
3070 list_del_init(&evsel->core.node);
3071 evsel->evlist = NULL;
3093 evsel->handler = trace__pgfault;
3100 const u32 type = event->header.type;
3104 trace__process_event(trace, trace->host, event, sample);
3108 evsel = perf_evlist__id2evsel(trace->evlist, sample->id);
3110 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample->id);
3114 if (evswitch__discard(&trace->evswitch, evsel))
3119 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT &&
3120 sample->raw_data == NULL) {
3121 …fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
3122 evsel__name(evsel), sample->tid,
3123 sample->cpu, sample->raw_size);
3125 tracepoint_handler handler = evsel->handler;
3129 if (trace->nr_events_printed >= trace->max_events && trace->max_events != ULONG_MAX)
3135 int ret = -1;
3136 struct evlist *evlist = trace->evlist;
3153 evsel__config_callchain(sys_enter, &trace->opts, &callchain_param);
3154 evsel__config_callchain(sys_exit, &trace->opts, &callchain_param);
3159 if (callchain_param.enabled && !trace->kernel_syscallchains) {
3163 * debugging reasons using --kernel_syscall_callchains
3165 sys_exit->core.attr.exclude_callchain_kernel = 1;
3168 trace->syscalls.events.sys_enter = sys_enter;
3169 trace->syscalls.events.sys_exit = sys_exit;
3184 int err = -1;
3186 char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier,
3187 trace->ev_qualifier_ids.nr,
3188 trace->ev_qualifier_ids.entries);
3193 if (!evsel__append_tp_filter(trace->syscalls.events.sys_enter, filter)) {
3194 sys_exit = trace->syscalls.events.sys_exit;
3209 if (trace->bpf_obj == NULL)
3212 return bpf_object__find_map_by_name(trace->bpf_obj, name);
3217 trace->filter_pids.map = trace__find_bpf_map_by_name(trace, "pids_filtered");
3222 trace->syscalls.map = trace__find_bpf_map_by_name(trace, "syscalls");
3223 trace->syscalls.prog_array.sys_enter = trace__find_bpf_map_by_name(trace, "syscalls_sys_enter");
3224 trace->syscalls.prog_array.sys_exit = trace__find_bpf_map_by_name(trace, "syscalls_sys_exit");
3229 if (trace->bpf_obj == NULL)
3232 return bpf_object__find_program_by_title(trace->bpf_obj, name);
3242 scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name);
3246 if (sc->fmt && sc->fmt->alias) {
3247 …scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alia…
3263 prog_name, type, sc->name);
3265 return trace->syscalls.unaugmented_prog;
3275 …sc->bpf_prog.sys_enter = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3276 …sc->bpf_prog.sys_exit = trace__find_syscall_bpf_prog(trace, sc, sc->fmt ? sc->fmt->bpf_prog_name.…
3282 …return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_…
3288 …return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_p…
3299 for (; arg < sc->nr_args; ++arg) {
3300 entry->string_args_len[arg] = 0;
3301 if (sc->arg_fmt[arg].scnprintf == SCA_FILENAME) {
3302 /* Should be set like strace -s strsize */
3303 entry->string_args_len[arg] = PATH_MAX;
3308 entry->string_args_len[arg] = 0;
3312 int fd = bpf_map__fd(trace->syscalls.map);
3314 .enabled = !trace->not_ev_qualifier,
3319 for (i = 0; i < trace->ev_qualifier_ids.nr; ++i) {
3320 int key = trace->ev_qualifier_ids.entries[i];
3337 int fd = bpf_map__fd(trace->syscalls.map);
3343 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3359 if (trace->ev_qualifier_ids.nr)
3360 enabled = trace->not_ev_qualifier;
3373 for (field = sc->args; field; field = field->next) {
3374 if (field->flags & TEP_FIELD_IS_POINTER)
3381 for (id = 0; id < trace->sctbl->syscalls.nr_entries; ++id) {
3387 pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog)
3390 for (field = sc->args, candidate_field = pair->args;
3391 field && candidate_field; field = field->next, candidate_field = candidate_field->next) {
3392 bool is_pointer = field->flags & TEP_FIELD_IS_POINTER,
3393 candidate_is_pointer = candidate_field->flags & TEP_FIELD_IS_POINTER;
3408 if (strcmp(field->type, candidate_field->type))
3423 …for (candidate_field = candidate_field->next; candidate_field; candidate_field = candidate_field->…
3424 if (candidate_field->flags & TEP_FIELD_IS_POINTER)
3428 pair_prog = pair->bpf_prog.sys_enter;
3433 * program for a filtered syscall on a non-filtered one.
3439 …pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_ent…
3440 if (pair_prog == trace->syscalls.unaugmented_prog)
3444 pr_debug("Reusing \"%s\" BPF sys_enter augmenter for \"%s\"\n", pair->name, sc->name);
3455 int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter),
3456 map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit);
3459 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3481 * syscall with an augmenter so that we can auto-reuse it.
3506 for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
3511 if (sc == NULL || sc->bpf_prog.sys_enter == NULL)
3518 if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog)
3529 sc->bpf_prog.sys_enter = pair_prog;
3535 prog_fd = bpf_program__fd(sc->bpf_prog.sys_enter);
3549 evlist__remove(trace->evlist, trace->syscalls.events.augmented);
3550 evsel__delete(trace->syscalls.events.augmented);
3551 trace->syscalls.events.augmented = NULL;
3553 evlist__for_each_entry_safe(trace->evlist, tmp, evsel) {
3554 if (evsel->bpf_obj == trace->bpf_obj) {
3555 evlist__remove(trace->evlist, evsel);
3561 bpf_object__close(trace->bpf_obj);
3562 trace->bpf_obj = NULL;
3609 evlist__for_each_entry(trace->evlist, evsel) {
3610 if (evsel == trace->syscalls.events.augmented ||
3611 evsel->bpf_obj == trace->bpf_obj)
3622 if (trace->syscalls.map)
3624 if (trace->syscalls.events.sys_enter)
3653 struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]);
3656 struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid);
3662 strstarts(thread__comm_str(parent), "gnome-terminal")) {
3663 pids[nr++] = parent->tid;
3669 err = perf_evlist__append_tp_filter_pids(trace->evlist, nr, pids);
3670 if (!err && trace->filter_pids.map)
3671 err = bpf_map__set_filter_pids(trace->filter_pids.map, nr, pids);
3685 if (trace->filter_pids.nr > 0) {
3686 err = perf_evlist__append_tp_filter_pids(trace->evlist, trace->filter_pids.nr,
3687 trace->filter_pids.entries);
3688 if (!err && trace->filter_pids.map) {
3689 err = bpf_map__set_filter_pids(trace->filter_pids.map, trace->filter_pids.nr,
3690 trace->filter_pids.entries);
3692 } else if (perf_thread_map__pid(trace->evlist->core.threads, 0) == -1) {
3701 struct evlist *evlist = trace->evlist;
3707 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
3716 u64 first = ordered_events__first_time(&trace->oe.data);
3717 u64 flush = trace->oe.last - NSEC_PER_SEC;
3721 return ordered_events__flush_time(&trace->oe.data, flush);
3728 return !trace->sort_events ? 0 : __trace__flush_events(trace);
3735 if (!trace->sort_events)
3738 err = perf_evlist__parse_sample_timestamp(trace->evlist, event, &trace->oe.last);
3739 if (err && err != -1)
3742 err = ordered_events__queue(&trace->oe.data, event, trace->oe.last, 0);
3754 return __trace__deliver_event(trace, event->event);
3762 if (evsel->tp_format == NULL || fmt == NULL)
3765 for (field = evsel->tp_format->format.fields; field; field = field->next, ++fmt)
3766 if (strcmp(field->name, arg) == 0)
3774 char *tok, *left = evsel->filter, *new_filter = evsel->filter;
3803 int left_size = tok - left,
3804 right_size = right_end - right;
3807 while (isspace(left[left_size - 1]))
3808 --left_size;
3815 arg, evsel->name, evsel->filter);
3816 return -1;
3819 pr_debug2("trying to expand \"%s\" \"%.*s\" \"%.*s\" -> ",
3820 arg, (int)(right - tok), tok, right_size, right);
3822 if (fmt->strtoul) {
3825 .parm = fmt->parm,
3828 if (fmt->strtoul(right, right_size, &syscall_arg, &val)) {
3831 int expansion_offset = right - new_filter;
3838 return -1;
3840 if (new_filter != evsel->filter)
3846 right_size, right, arg, evsel->name, evsel->filter);
3847 return -1;
3851 arg, evsel->name, evsel->filter);
3852 return -1;
3861 if (new_filter != evsel->filter) {
3862 pr_debug("New filter for %s: %s\n", evsel->name, new_filter);
3872 struct evlist *evlist = trace->evlist;
3876 if (evsel->filter == NULL)
3881 return -1;
3890 struct evlist *evlist = trace->evlist;
3892 int err = -1, i;
3897 trace->live = true;
3899 if (!trace->raw_augmented_syscalls) {
3900 if (trace->trace_syscalls && trace__add_syscall_newtp(trace))
3903 if (trace->trace_syscalls)
3904 trace->vfs_getname = evlist__add_vfs_getname(evlist);
3907 if ((trace->trace_pgfaults & TRACE_PFMAJ)) {
3911 evsel__config_callchain(pgfault_maj, &trace->opts, &callchain_param);
3915 if ((trace->trace_pgfaults & TRACE_PFMIN)) {
3919 evsel__config_callchain(pgfault_min, &trace->opts, &callchain_param);
3923 if (trace->sched &&
3930 * trace -G A -e sched:*switch
3935 * trace -e sched:*switch -G A
3943 * trace -G A -e sched:*switch -G B
3949 * only for the evsels still without a cgroup, i.e. evsel->cgroup == NULL.
3951 if (trace->cgroup)
3952 evlist__set_default_cgroup(trace->evlist, trace->cgroup);
3954 err = perf_evlist__create_maps(evlist, &trace->opts.target);
3956 fprintf(trace->output, "Problems parsing the target to trace, check your options!\n");
3962 fprintf(trace->output, "Problems initializing symbol libraries!\n");
3966 perf_evlist__config(evlist, &trace->opts, &callchain_param);
3972 err = perf_evlist__prepare_workload(evlist, &trace->opts.target,
3975 fprintf(trace->output, "Couldn't run the workload!\n");
3998 if (trace->syscalls.map)
4001 if (trace->syscalls.prog_array.sys_enter)
4004 if (trace->ev_qualifier_ids.nr > 0) {
4009 if (trace->syscalls.events.sys_exit) {
4011 trace->syscalls.events.sys_exit->filter);
4018 * fd->pathname table and were ending up showing the last value set by
4026 trace->fd_path_disabled = !trace__syscall_enabled(trace, syscalltbl__id(trace->sctbl, "close"));
4035 if (trace->dump.map)
4036 bpf_map__fprintf(trace->dump.map, trace->output);
4038 err = evlist__mmap(evlist, trace->opts.mmap_pages);
4042 if (!target__none(&trace->opts.target) && !trace->opts.initial_delay)
4048 if (trace->opts.initial_delay) {
4049 usleep(trace->opts.initial_delay * 1000);
4053 trace->multiple_threads = perf_thread_map__pid(evlist->core.threads, 0) == -1 ||
4054 evlist->core.threads->nr > 1 ||
4055 evlist__first(evlist)->core.attr.inherit;
4058 * Now that we already used evsel->core.attr to ask the kernel to setup the
4059 * events, lets reuse evsel->core.attr.sample_max_stack as the limit in
4060 * trace__resolve_callchain(), allowing per-event max-stack settings
4061 * to override an explicitly set --max-stack global setting.
4065 evsel->core.attr.sample_max_stack == 0)
4066 evsel->core.attr.sample_max_stack = trace->max_stack;
4069 before = trace->nr_events;
4071 for (i = 0; i < evlist->core.nr_mmaps; i++) {
4075 md = &evlist->mmap[i];
4076 if (perf_mmap__read_init(&md->core) < 0)
4079 while ((event = perf_mmap__read_event(&md->core)) != NULL) {
4080 ++trace->nr_events;
4086 perf_mmap__consume(&md->core);
4096 perf_mmap__read_done(&md->core);
4099 if (trace->nr_events == before) {
4100 int timeout = done ? 100 : -1;
4116 thread__zput(trace->current);
4120 if (trace->sort_events)
4121 ordered_events__flush(&trace->oe.data, OE_FLUSH__FINAL);
4124 if (trace->summary)
4125 trace__fprintf_thread_summary(trace, trace->output);
4127 if (trace->show_tool_stats) {
4128 fprintf(trace->output, "Stats:\n "
4131 trace->stats.vfs_getname,
4132 trace->stats.proc_getname);
4140 cgroup__put(trace->cgroup);
4141 trace->evlist = NULL;
4142 trace->live = false;
4163 fprintf(trace->output, "%s\n", errbuf);
4167 fprintf(trace->output,
4169 evsel->filter, evsel__name(evsel), errno,
4174 fprintf(trace->output, "Not enough memory to run!\n");
4178 fprintf(trace->output, "errno=%d,%s\n", errno, strerror(errno));
4190 .force = trace->force,
4194 int err = -1;
4196 trace->tool.sample = trace__process_sample;
4197 trace->tool.mmap = perf_event__process_mmap;
4198 trace->tool.mmap2 = perf_event__process_mmap2;
4199 trace->tool.comm = perf_event__process_comm;
4200 trace->tool.exit = perf_event__process_exit;
4201 trace->tool.fork = perf_event__process_fork;
4202 trace->tool.attr = perf_event__process_attr;
4203 trace->tool.tracing_data = perf_event__process_tracing_data;
4204 trace->tool.build_id = perf_event__process_build_id;
4205 trace->tool.namespaces = perf_event__process_namespaces;
4207 trace->tool.ordered_events = true;
4208 trace->tool.ordering_requires_timestamps = true;
4211 trace->multiple_threads = true;
4213 session = perf_session__new(&data, false, &trace->tool);
4217 if (trace->opts.target.pid)
4218 symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
4220 if (trace->opts.target.tid)
4221 symbol_conf.tid_list_str = strdup(trace->opts.target.tid);
4223 if (symbol__init(&session->header.env) < 0)
4226 trace->host = &session->machines.host;
4232 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4236 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4246 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4249 evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
4258 evlist__for_each_entry(session->evlist, evsel) {
4259 if (evsel->core.attr.type == PERF_TYPE_SOFTWARE &&
4260 (evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MAJ ||
4261 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS_MIN ||
4262 evsel->core.attr.config == PERF_COUNT_SW_PAGE_FAULTS))
4263 evsel->handler = trace__pgfault;
4272 else if (trace->summary)
4273 trace__fprintf_thread_summary(trace, trace->output);
4290 DEFINE_RESORT_RB(syscall_stats, a->msecs > b->msecs,
4297 struct syscall_stats *stats = source->priv;
4299 entry->syscall = source->i;
4300 entry->stats = stats;
4301 entry->msecs = stats ? (u64)stats->stats.n * (avg_stats(&stats->stats) / NSEC_PER_MSEC) : 0;
4310 DECLARE_RESORT_RB_INTLIST(syscall_stats, ttrace->syscall_stats);
4317 …printed += fprintf(fp, " syscall calls errors total min avg max …
4319 …printed += fprintf(fp, " --------------- -------- ------ -------- --------- --------- ---------
4322 struct syscall_stats *stats = syscall_stats_entry->stats;
4324 double min = (double)(stats->stats.min) / NSEC_PER_MSEC;
4325 double max = (double)(stats->stats.max) / NSEC_PER_MSEC;
4326 double avg = avg_stats(&stats->stats); local
4328 u64 n = (u64)stats->stats.n;
4330 pct = avg ? 100.0 * stddev_stats(&stats->stats) / avg : 0.0;
4331 avg /= NSEC_PER_MSEC;
4333 sc = &trace->syscalls.table[syscall_stats_entry->syscall];
4334 printed += fprintf(fp, " %-15s", sc->name);
4336 n, stats->nr_failures, syscall_stats_entry->msecs, min, avg);
4339 if (trace->errno_summary && stats->nr_failures) {
4340 const char *arch_name = perf_env__arch(trace->host->env);
4343 for (e = 0; e < stats->max_errno; ++e) {
4344 if (stats->errnos[e] != 0)
4345 fprintf(fp, "\t\t\t\t%s: %d\n", arch_syscalls__strerrno(arch_name, e + 1), stats->errnos[e]);
4366 ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
4368 printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid);
4369 printed += fprintf(fp, "%lu events, ", ttrace->nr_events);
4371 if (ttrace->pfmaj)
4372 printed += fprintf(fp, ", %lu majfaults", ttrace->pfmaj);
4373 if (ttrace->pfmin)
4374 printed += fprintf(fp, ", %lu minfaults", ttrace->pfmin);
4375 if (trace->sched)
4376 printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms);
4387 return ttrace ? ttrace->nr_events : 0;
4390 DEFINE_RESORT_RB(threads, (thread__nr_events(a->thread->priv) < thread__nr_events(b->thread->priv)),
4394 entry->thread = rb_entry(nd, struct thread, rb_node);
4404 DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host, i);
4412 printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
4422 struct trace *trace = opt->value;
4424 trace->duration_filter = atof(str);
4431 int ret = -1;
4433 struct trace *trace = opt->value;
4441 return -1;
4443 i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
4444 trace->filter_pids.entries = calloc(i, sizeof(pid_t));
4446 if (trace->filter_pids.entries == NULL)
4449 trace->filter_pids.entries[0] = getpid();
4451 for (i = 1; i < trace->filter_pids.nr; ++i)
4452 trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
4472 trace->output = fopen(filename, "w");
4474 return trace->output == NULL ? -errno : 0;
4480 int *trace_pgfaults = opt->value;
4489 return -1;
4499 if (evsel->handler == NULL)
4500 evsel->handler = handler;
4514 if (strcmp(evsel->tp_format->format.fields->name, "__syscall_nr") == 0 ||
4515 strcmp(evsel->tp_format->format.fields->name, "nr") == 0)
4518 memcpy(fmt + skip, scfmt->arg, (evsel->tp_format->format.nr_fields - skip) * sizeof(*fmt));
4528 if (evsel->priv || !evsel->tp_format)
4531 if (strcmp(evsel->tp_format->system, "syscalls")) {
4537 return -1;
4539 if (!strncmp(evsel->tp_format->name, "sys_enter_", 10)) {
4542 if (__tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)))
4543 return -1;
4545 evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_enter_") - 1);
4546 } else if (!strncmp(evsel->tp_format->name, "sys_exit_", 9)) {
4549 if (__tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap))
4550 return -1;
4552 evsel__set_syscall_arg_fmt(evsel, evsel->tp_format->name + sizeof("sys_exit_") - 1);
4560 * XXX: Hackish, just splitting the combined -e+--event (syscalls
4562 * existing facilities unchanged (trace->ev_qualifier + parse_options()).
4570 struct trace *trace = (struct trace *)opt->value;
4573 int len = strlen(str) + 1, err = -1, list, idx;
4579 return -1;
4583 trace->not_ev_qualifier = true;
4591 if (syscalltbl__id(trace->sctbl, s) >= 0 ||
4592 syscalltbl__strglobmatch_first(trace->sctbl, s, &idx) >= 0) {
4600 s = fmt->name;
4628 trace->ev_qualifier = strlist__new(lists[1], &slist_config);
4629 if (trace->ev_qualifier == NULL) {
4630 fputs("Not enough memory to parse event qualifier", trace->output);
4636 trace->trace_syscalls = true;
4643 .value = &trace->evlist,
4656 struct trace *trace = opt->value;
4658 if (!list_empty(&trace->evlist->core.entries)) {
4660 .value = &trace->evlist,
4664 trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
4675 trace->perfconfig_events = strdup(value);
4676 if (trace->perfconfig_events == NULL) {
4678 return -1;
4681 trace->show_tstamp = perf_config_bool(var, value);
4683 trace->show_duration = perf_config_bool(var, value);
4685 trace->show_arg_names = perf_config_bool(var, value);
4686 if (!trace->show_arg_names)
4687 trace->show_zeros = true;
4690 if (!trace->show_arg_names && !new_show_zeros) {
4694 trace->show_zeros = new_show_zeros;
4696 trace->show_string_prefix = perf_config_bool(var, value);
4698 trace->opts.no_inherit = perf_config_bool(var, value);
4702 trace->args_alignment = args_alignment;
4705 trace->libtraceevent_print = true;
4707 trace->libtraceevent_print = false;
4717 "perf trace [<options>] -- <command> [<options>]",
4719 "perf trace record [<options>] -- <command> [<options>]",
4763 OPT_CALLBACK(0, "filter-pids", &trace, "CSV list of pids",
4765 OPT_BOOLEAN('a', "all-cpus", &trace.opts.target.system_wide,
4766 "system-wide collection from all CPUs"),
4769 OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
4771 OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
4780 OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"),
4790 OPT_BOOLEAN('S', "with-summary", &trace.summary,
4792 OPT_BOOLEAN(0, "errno-summary", &trace.errno_summary,
4793 "Show errno stats per syscall, use with -s or -S"),
4798 OPT_CALLBACK(0, "call-graph", &trace.opts,
4803 OPT_BOOLEAN(0, "kernel-syscall-graph", &trace.kernel_syscallchains,
4805 OPT_ULONG(0, "max-events", &trace.max_events,
4807 OPT_UINTEGER(0, "min-stack", &trace.min_stack,
4810 OPT_UINTEGER(0, "max-stack", &trace.max_stack,
4814 OPT_BOOLEAN(0, "sort-events", &trace.sort_events,
4816 OPT_BOOLEAN(0, "print-sample", &trace.print_sample,
4818 OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
4832 int err = -1;
4843 err = -ENOMEM;
4851 * global setting. If it fails we'll get something in 'perf trace -v'
4865 * already figured out if -e syscall_name, if not but if --event
4867 * tracepoint events, not in the strace-like syscall-name-based mode.
4869 * This is important because we need to check if strace-like mode is
4875 trace.evlist->core.nr_entries == 0 /* Was --events used? */) {
4879 * Now that we have --verbose figured out, lets see if we need to parse
4881 * BPF program fails, then we'll be able to use --verbose to see what went
4897 "cgroup monitoring only available in system-wide mode");
4916 if (evsel->bpf_obj == NULL) {
4921 trace.bpf_obj = evsel->bpf_obj;
4925 * explicit --syscalls, then assume we want all strace-like
4932 * strace-like syscall tracing is not set, then we need to trow
4937 * style of setting up the strace-like eBPF based syscall point
4947 * 'perf trace --config determinism.profile' mode, where for some
4952 * Also --config to specify an alternate .perfconfig file needs
4971 err = -1;
5007 if (trace.evlist->core.nr_entries > 0) {
5040 if (trace.syscalls.events.augmented->priv == NULL &&
5051 augmented->handler = trace__sys_enter;
5061 evsel->handler = trace__sys_enter;
5076 * don't look after the sc->args_size but
5081 * s->args_size to the BPF augmenter (now
5090 trace.raw_augmented_syscalls_args_size = (6 + 1) * sizeof(long) + sc->id.offset;
5092 evsel->handler = trace__sys_exit;
5098 return trace__record(&trace, argc-1, &argv[1]);
5100 /* Using just --errno-summary will trigger --summary */