Lines Matching +full:1 +full:br +full:- +full:100
1 // SPDX-License-Identifier: GPL-2.0
7 #include <subcmd/exec-cmd.h>
9 #include <subcmd/parse-options.h>
17 #include "util/trace-event.h"
31 #include "util/thread-stack.h"
32 #include "util/time-utils.h"
35 #include "util/mem-info.h"
47 #include "util/mem-events.h"
48 #include "util/dump-insn.h"
70 #include <traceevent/event-parse.h>
98 PERF_OUTPUT_COMM = 1ULL << 0,
99 PERF_OUTPUT_TID = 1ULL << 1,
100 PERF_OUTPUT_PID = 1ULL << 2,
101 PERF_OUTPUT_TIME = 1ULL << 3,
102 PERF_OUTPUT_CPU = 1ULL << 4,
103 PERF_OUTPUT_EVNAME = 1ULL << 5,
104 PERF_OUTPUT_TRACE = 1ULL << 6,
105 PERF_OUTPUT_IP = 1ULL << 7,
106 PERF_OUTPUT_SYM = 1ULL << 8,
107 PERF_OUTPUT_DSO = 1ULL << 9,
108 PERF_OUTPUT_ADDR = 1ULL << 10,
109 PERF_OUTPUT_SYMOFFSET = 1ULL << 11,
110 PERF_OUTPUT_SRCLINE = 1ULL << 12,
111 PERF_OUTPUT_PERIOD = 1ULL << 13,
112 PERF_OUTPUT_IREGS = 1ULL << 14,
113 PERF_OUTPUT_BRSTACK = 1ULL << 15,
114 PERF_OUTPUT_BRSTACKSYM = 1ULL << 16,
115 PERF_OUTPUT_DATA_SRC = 1ULL << 17,
116 PERF_OUTPUT_WEIGHT = 1ULL << 18,
117 PERF_OUTPUT_BPF_OUTPUT = 1ULL << 19,
118 PERF_OUTPUT_CALLINDENT = 1ULL << 20,
119 PERF_OUTPUT_INSN = 1ULL << 21,
120 PERF_OUTPUT_INSNLEN = 1ULL << 22,
121 PERF_OUTPUT_BRSTACKINSN = 1ULL << 23,
122 PERF_OUTPUT_BRSTACKOFF = 1ULL << 24,
123 PERF_OUTPUT_SYNTH = 1ULL << 25,
124 PERF_OUTPUT_PHYS_ADDR = 1ULL << 26,
125 PERF_OUTPUT_UREGS = 1ULL << 27,
126 PERF_OUTPUT_METRIC = 1ULL << 28,
127 PERF_OUTPUT_MISC = 1ULL << 29,
128 PERF_OUTPUT_SRCCODE = 1ULL << 30,
129 PERF_OUTPUT_IPC = 1ULL << 31,
130 PERF_OUTPUT_TOD = 1ULL << 32,
131 PERF_OUTPUT_DATA_PAGE_SIZE = 1ULL << 33,
132 PERF_OUTPUT_CODE_PAGE_SIZE = 1ULL << 34,
133 PERF_OUTPUT_INS_LAT = 1ULL << 35,
134 PERF_OUTPUT_BRSTACKINSNLEN = 1ULL << 36,
135 PERF_OUTPUT_MACHINE_PID = 1ULL << 37,
136 PERF_OUTPUT_VCPU = 1ULL << 38,
137 PERF_OUTPUT_CGROUP = 1ULL << 39,
138 PERF_OUTPUT_RETIRE_LAT = 1ULL << 40,
139 PERF_OUTPUT_DSOFF = 1ULL << 41,
140 PERF_OUTPUT_DISASM = 1ULL << 42,
141 PERF_OUTPUT_BRSTACKDISASM = 1ULL << 43,
142 PERF_OUTPUT_BRCNTR = 1ULL << 44,
195 {.str = "bpf-output", .field = PERF_OUTPUT_BPF_OUTPUT},
347 return (struct evsel_script *)evsel->priv; in evsel_script()
355 if (asprintf(&es->filename, "%s.%s.dump", data->file.path, evsel__name(evsel)) < 0) in evsel_script__new()
357 es->fp = fopen(es->filename, "w"); in evsel_script__new()
358 if (es->fp == NULL) in evsel_script__new()
364 zfree(&es->filename); in evsel_script__new()
372 zfree(&es->filename); in evsel_script__delete()
373 fclose(es->fp); in evsel_script__delete()
374 es->fp = NULL; in evsel_script__delete()
382 fstat(fileno(es->fp), &st); in evsel_script__fprintf()
384 st.st_size / 1024.0 / 1024.0, es->filename, es->samples); in evsel_script__fprintf()
424 #define PRINT_FIELD(x) (output[output_type(attr->type)].fields & PERF_OUTPUT_##x)
429 struct perf_event_attr *attr = &evsel->core.attr; in evsel__do_check_stype()
430 int type = output_type(attr->type); in evsel__do_check_stype()
433 if (attr->sample_type & sample_type) in evsel__do_check_stype()
443 return -1; in evsel__do_check_stype()
464 struct perf_event_attr *attr = &evsel->core.attr; in evsel__check_attr()
470 if (perf_header__has_feat(&session->header, HEADER_STAT)) in evsel__check_attr()
473 allow_user_set = perf_header__has_feat(&session->header, in evsel__check_attr()
477 !perf_session__has_traces(session, "record -R")) in evsel__check_attr()
478 return -EINVAL; in evsel__check_attr()
482 return -EINVAL; in evsel__check_attr()
487 return -EINVAL; in evsel__check_attr()
491 return -EINVAL; in evsel__check_attr()
495 return -EINVAL; in evsel__check_attr()
498 !(evsel->core.attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) { in evsel__check_attr()
502 return -EINVAL; in evsel__check_attr()
507 return -EINVAL; in evsel__check_attr()
510 !(evsel->core.attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) { in evsel__check_attr()
512 return -EINVAL; in evsel__check_attr()
517 return -EINVAL; in evsel__check_attr()
521 !(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_ANY)) { in evsel__check_attr()
522 pr_err("Display of branch stack assembler requested, but non all-branch filter set\n" in evsel__check_attr()
523 "Hint: run 'perf record -b ...'\n"); in evsel__check_attr()
524 return -EINVAL; in evsel__check_attr()
527 !(evlist__combined_branch_type(session->evlist) & PERF_SAMPLE_BRANCH_COUNTERS)) { in evsel__check_attr()
529 "Hint: run 'perf record -j any,counter ...'\n"); in evsel__check_attr()
530 return -EINVAL; in evsel__check_attr()
534 return -EINVAL; in evsel__check_attr()
538 return -EINVAL; in evsel__check_attr()
542 return -EINVAL; in evsel__check_attr()
546 return -EINVAL; in evsel__check_attr()
550 return -EINVAL; in evsel__check_attr()
554 return -EINVAL; in evsel__check_attr()
558 return -EINVAL; in evsel__check_attr()
562 return -EINVAL; in evsel__check_attr()
566 return -EINVAL; in evsel__check_attr()
570 pr_err("Hint: run 'perf record --all-cgroups ...'\n"); in evsel__check_attr()
571 return -EINVAL; in evsel__check_attr()
576 return -EINVAL; in evsel__check_attr()
583 unsigned int type = output_type(attr->type); in set_print_ip_opts()
613 if (output_type(evsel->core.attr.type) == (int)type) in find_first_output_type()
630 evsel = find_first_output_type(session->evlist, j); in perf_session__check_output_opt()
639 "Remove corresponding -F option to proceed.\n", in perf_session__check_output_opt()
641 return -1; in perf_session__check_output_opt()
646 return -1; in perf_session__check_output_opt()
655 set_print_ip_opts(&evsel->core.attr); in perf_session__check_output_opt()
663 evlist__for_each_entry(session->evlist, evsel) { in perf_session__check_output_opt()
682 evlist__for_each_entry(session->evlist, evsel) { in perf_session__check_output_opt()
683 if (evsel->core.attr.type != j) in perf_session__check_output_opt()
691 set_print_ip_opts(&evsel->core.attr); in perf_session__check_output_opt()
697 if (tod && !session->header.env.clock.enabled) { in perf_session__check_output_opt()
699 "Please record with -k/--clockid option.\n"); in perf_session__check_output_opt()
700 return -1; in perf_session__check_output_opt()
712 if (!regs || !regs->regs) in perf_sample__fprintf_regs()
715 printed += fprintf(fp, " ABI:%" PRIu64 " ", regs->abi); in perf_sample__fprintf_regs()
718 u64 val = regs->regs[i++]; in perf_sample__fprintf_regs()
742 env = &script->session->header.env; in tod_scnprintf()
743 if (!env->clock.enabled) { in tod_scnprintf()
748 clockid_ns = env->clock.clockid_ns; in tod_scnprintf()
749 tod_ns = env->clock.tod_ns; in tod_scnprintf()
752 tod_ns += timestamp - clockid_ns; in tod_scnprintf()
754 tod_ns -= clockid_ns - timestamp; in tod_scnprintf()
757 nsec = tod_ns - sec * NSEC_PER_SEC; in tod_scnprintf()
778 return perf_sample__fprintf_regs(&sample->intr_regs, in perf_sample__fprintf_iregs()
779 attr->sample_regs_intr, arch, fp); in perf_sample__fprintf_iregs()
785 return perf_sample__fprintf_regs(&sample->user_regs, in perf_sample__fprintf_uregs()
786 attr->sample_regs_user, arch, fp); in perf_sample__fprintf_uregs()
795 struct perf_event_attr *attr = &evsel->core.attr; in perf_sample__fprintf_start()
814 if (PRINT_FIELD(MACHINE_PID) && sample->machine_pid) in perf_sample__fprintf_start()
815 printed += fprintf(fp, "VM:%5d ", sample->machine_pid); in perf_sample__fprintf_start()
818 if (PRINT_FIELD(VCPU) && sample->machine_pid) in perf_sample__fprintf_start()
819 printed += fprintf(fp, "VCPU:%03d ", sample->vcpu); in perf_sample__fprintf_start()
822 const char *comm = thread ? thread__comm_str(thread) : ":-1"; in perf_sample__fprintf_start()
833 printed += fprintf(fp, "%7d/%-7d ", sample->pid, sample->tid); in perf_sample__fprintf_start()
835 printed += fprintf(fp, "%7d ", sample->pid); in perf_sample__fprintf_start()
837 printed += fprintf(fp, "%7d ", sample->tid); in perf_sample__fprintf_start()
841 printed += fprintf(fp, "%3d ", sample->cpu); in perf_sample__fprintf_start()
843 printed += fprintf(fp, "[%03d] ", sample->cpu); in perf_sample__fprintf_start()
850 (sample->misc & PERF_RECORD_MISC_##m) == PERF_RECORD_MISC_##m in perf_sample__fprintf_start()
877 if (sample->misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT) in perf_sample__fprintf_start()
886 ret += fprintf(fp, "%*s", 6 - ret, " "); in perf_sample__fprintf_start()
891 tod_scnprintf(script, tstr, sizeof(tstr), sample->time); in perf_sample__fprintf_start()
896 u64 t = sample->time; in perf_sample__fprintf_start()
899 initial_time = sample->time; in perf_sample__fprintf_start()
900 t = sample->time - initial_time; in perf_sample__fprintf_start()
903 t = sample->time - previous_time; in perf_sample__fprintf_start()
907 previous_time = sample->time; in perf_sample__fprintf_start()
911 nsecs -= secs * NSEC_PER_SEC; in perf_sample__fprintf_start()
926 mispred_str(struct branch_entry *br) in mispred_str() argument
928 if (!(br->flags.mispred || br->flags.predicted)) in mispred_str()
929 return '-'; in mispred_str()
931 return br->flags.predicted ? 'P' : 'M'; in mispred_str()
934 static int print_bstack_flags(FILE *fp, struct branch_entry *br) in print_bstack_flags() argument
937 mispred_str(br), in print_bstack_flags()
938 br->flags.in_tx ? 'X' : '-', in print_bstack_flags()
939 br->flags.abort ? 'A' : '-', in print_bstack_flags()
940 br->flags.cycles, in print_bstack_flags()
941 get_branch_type(br), in print_bstack_flags()
942 br->flags.spec ? branch_spec_desc(br->flags.spec) : "-"); in print_bstack_flags()
949 struct branch_stack *br = sample->branch_stack; in perf_sample__fprintf_brstack() local
954 if (!(br && br->nr)) in perf_sample__fprintf_brstack()
957 for (i = 0; i < br->nr; i++) { in perf_sample__fprintf_brstack()
967 thread__find_map_fb(thread, sample->cpumode, from, &alf); in perf_sample__fprintf_brstack()
968 thread__find_map_fb(thread, sample->cpumode, to, &alt); in perf_sample__fprintf_brstack()
988 struct branch_stack *br = sample->branch_stack; in perf_sample__fprintf_brstacksym() local
993 if (!(br && br->nr)) in perf_sample__fprintf_brstacksym()
996 for (i = 0; i < br->nr; i++) { in perf_sample__fprintf_brstacksym()
1004 thread__find_symbol_fb(thread, sample->cpumode, from, &alf); in perf_sample__fprintf_brstacksym()
1005 thread__find_symbol_fb(thread, sample->cpumode, to, &alt); in perf_sample__fprintf_brstacksym()
1026 struct branch_stack *br = sample->branch_stack; in perf_sample__fprintf_brstackoff() local
1031 if (!(br && br->nr)) in perf_sample__fprintf_brstackoff()
1034 for (i = 0; i < br->nr; i++) { in perf_sample__fprintf_brstackoff()
1042 if (thread__find_map_fb(thread, sample->cpumode, from, &alf) && in perf_sample__fprintf_brstackoff()
1046 if (thread__find_map_fb(thread, sample->cpumode, to, &alt) && in perf_sample__fprintf_brstackoff()
1091 pr_debug("\tblock %" PRIx64 "-%" PRIx64 " transfers between kernel and user\n", start, end); in grab_bb()
1092 return -ENXIO; in grab_bb()
1095 if (end - start > MAXBB - MAXINSN) { in grab_bb()
1097 pr_debug("\tbrstack does not reach to final jump (%" PRIx64 "-%" PRIx64 ")\n", start, end); in grab_bb()
1099 …pr_debug("\tblock %" PRIx64 "-%" PRIx64 " (%" PRIu64 ") too long to dump\n", start, end, end - sta… in grab_bb()
1105 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); in grab_bb()
1108 if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR) { in grab_bb()
1109 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); in grab_bb()
1113 /* Load maps to ensure dso->is_64_bit has been updated */ in grab_bb()
1118 end - start + MAXINSN); in grab_bb()
1122 pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n", in grab_bb()
1149 state->srcfile && in map__fprintf_srccode()
1150 !strcmp(state->srcfile, srcfile) && in map__fprintf_srccode()
1151 state->line == line) { in map__fprintf_srccode()
1160 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); in map__fprintf_srccode()
1163 state->srcfile = srcfile; in map__fprintf_srccode()
1164 state->line = line; in map__fprintf_srccode()
1198 int printed = fprintf_insn_asm(x->machine, x->thread, x->cpumode, x->is64bit, in any_dump_insn()
1212 printed += fprintf(fp, "%*s", padding - printed, ""); in add_padding()
1237 thread__find_map(thread, x->cpumode, ip, &al); in ip__fprintf_jump()
1248 mask = (1L << width) - 1; in ip__fprintf_jump()
1250 evlist__for_each_entry_from(evsel->evlist, pos) { in ip__fprintf_jump()
1251 if (!(pos->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS)) in ip__fprintf_jump()
1259 printed += fprintf(fp, "%s", pos->abbr_name); in ip__fprintf_jump()
1261 printed += fprintf(fp, "%s %d ", pos->name, num); in ip__fprintf_jump()
1267 en->flags.predicted ? " PRED" : "", in ip__fprintf_jump()
1268 en->flags.mispred ? " MISPRED" : "", in ip__fprintf_jump()
1269 en->flags.in_tx ? " INTX" : "", in ip__fprintf_jump()
1270 en->flags.abort ? " ABORT" : ""); in ip__fprintf_jump()
1271 if (en->flags.cycles) { in ip__fprintf_jump()
1272 *total_cycles += en->flags.cycles; in ip__fprintf_jump()
1273 printed += fprintf(fp, " %d cycles [%d]", en->flags.cycles, *total_cycles); in ip__fprintf_jump()
1275 printed += fprintf(fp, " %.2f IPC", (float)insn / en->flags.cycles); in ip__fprintf_jump()
1291 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) in ip__fprintf_sym()
1302 if (al.addr < al.sym->end) in ip__fprintf_sym()
1303 off = al.addr - al.sym->start; in ip__fprintf_sym()
1305 off = al.addr - map__start(al.map) - al.sym->start; in ip__fprintf_sym()
1306 printed += fprintf(fp, "\t%s", al.sym->name); in ip__fprintf_sym()
1327 struct branch_stack *br = sample->branch_stack; in perf_sample__fprintf_brstackinsn() local
1338 if (!(br && br->nr)) in perf_sample__fprintf_brstackinsn()
1340 nr = br->nr; in perf_sample__fprintf_brstackinsn()
1341 if (max_blocks && nr > max_blocks + 1) in perf_sample__fprintf_brstackinsn()
1342 nr = max_blocks + 1; in perf_sample__fprintf_brstackinsn()
1346 x.cpu = sample->cpu; in perf_sample__fprintf_brstackinsn()
1348 if (PRINT_FIELD(BRCNTR) && sample->branch_stack_cntr) in perf_sample__fprintf_brstackinsn()
1349 br_cntr = sample->branch_stack_cntr[nr - 1]; in perf_sample__fprintf_brstackinsn()
1354 len = grab_bb(buffer, entries[nr-1].from, in perf_sample__fprintf_brstackinsn()
1355 entries[nr-1].from, in perf_sample__fprintf_brstackinsn()
1358 printed += ip__fprintf_sym(entries[nr - 1].from, thread, in perf_sample__fprintf_brstackinsn()
1360 printed += ip__fprintf_jump(entries[nr - 1].from, &entries[nr - 1], in perf_sample__fprintf_brstackinsn()
1364 printed += print_srccode(thread, x.cpumode, entries[nr - 1].from); in perf_sample__fprintf_brstackinsn()
1368 for (i = nr - 2; i >= 0; i--) { in perf_sample__fprintf_brstackinsn()
1370 pr_debug("%d: %" PRIx64 "-%" PRIx64 "\n", i, in perf_sample__fprintf_brstackinsn()
1373 start = entries[i + 1].to; in perf_sample__fprintf_brstackinsn()
1378 if (len == -ENXIO && i > 0) { in perf_sample__fprintf_brstackinsn()
1379 end = entries[--i].from; in perf_sample__fprintf_brstackinsn()
1380 pr_debug("\tpatching up to %" PRIx64 "-%" PRIx64 "\n", start, end); in perf_sample__fprintf_brstackinsn()
1392 if (PRINT_FIELD(BRCNTR) && sample->branch_stack_cntr) in perf_sample__fprintf_brstackinsn()
1393 br_cntr = sample->branch_stack_cntr[i]; in perf_sample__fprintf_brstackinsn()
1394 printed += ip__fprintf_jump(ip, &entries[i], &x, buffer + off, len - off, ++insn, fp, in perf_sample__fprintf_brstackinsn()
1402 printed += any_dump_insn(attr, &x, ip, buffer + off, len - off, &ilen, fp); in perf_sample__fprintf_brstackinsn()
1413 if (off != end - start) in perf_sample__fprintf_brstackinsn()
1421 if (entries[0].from == sample->ip) in perf_sample__fprintf_brstackinsn()
1435 end = sample->ip; in perf_sample__fprintf_brstackinsn()
1444 len = grab_bb(buffer, sample->ip, sample->ip, in perf_sample__fprintf_brstackinsn()
1449 printed += fprintf(fp, "\t%016" PRIx64 "\t", sample->ip); in perf_sample__fprintf_brstackinsn()
1450 printed += any_dump_insn(attr, &x, sample->ip, buffer, len, &ilen, fp); in perf_sample__fprintf_brstackinsn()
1455 print_srccode(thread, x.cpumode, sample->ip); in perf_sample__fprintf_brstackinsn()
1458 for (off = 0; off <= end - start; off += ilen) { in perf_sample__fprintf_brstackinsn()
1461 printed += any_dump_insn(attr, &x, start + off, buffer + off, len - off, &ilen, fp); in perf_sample__fprintf_brstackinsn()
1467 if ((attr->branch_sample_type == 0 || attr->branch_sample_type & PERF_SAMPLE_BRANCH_ANY) in perf_sample__fprintf_brstackinsn()
1468 && arch_is_uncond_branch(buffer + off, len - off, x.is64bit) in perf_sample__fprintf_brstackinsn()
1469 && start + off != sample->ip) { in perf_sample__fprintf_brstackinsn()
1488 int printed = fprintf(fp, "%16" PRIx64, sample->addr); in perf_sample__fprintf_addr()
1518 struct perf_event_attr *attr = &evsel->core.attr; in resolve_branch_sym()
1521 if (sample->flags & (PERF_IP_FLAG_CALL | PERF_IP_FLAG_TRACE_BEGIN)) { in resolve_branch_sym()
1523 if (!addr_al->thread) in resolve_branch_sym()
1525 if (addr_al->sym) in resolve_branch_sym()
1526 name = addr_al->sym->name; in resolve_branch_sym()
1528 *ip = sample->addr; in resolve_branch_sym()
1530 *ip = sample->addr; in resolve_branch_sym()
1532 } else if (sample->flags & (PERF_IP_FLAG_RETURN | PERF_IP_FLAG_TRACE_END)) { in resolve_branch_sym()
1533 if (al->sym) in resolve_branch_sym()
1534 name = al->sym->name; in resolve_branch_sym()
1536 *ip = sample->ip; in resolve_branch_sym()
1548 struct perf_event_attr *attr = &evsel->core.attr; in perf_sample__fprintf_callindent()
1549 size_t depth = thread_stack__depth(thread, sample->cpu); in perf_sample__fprintf_callindent()
1560 if (thread__ts(thread) && sample->flags & PERF_IP_FLAG_RETURN) in perf_sample__fprintf_callindent()
1561 depth += 1; in perf_sample__fprintf_callindent()
1567 dlen += map__fprintf_dsoname(al->map, fp); in perf_sample__fprintf_callindent()
1583 if (len > spacing || (len && len < spacing - 52)) in perf_sample__fprintf_callindent()
1587 len += fprintf(fp, "%*s", spacing - len, ""); in perf_sample__fprintf_callindent()
1601 if (sample->insn_len == 0 && native_arch) in script_fetch_insn()
1617 printed += fprintf(fp, " ilen: %d", sample->insn_len); in perf_sample__fprintf_insn()
1618 if (PRINT_FIELD(INSN) && sample->insn_len) { in perf_sample__fprintf_insn()
1622 if (PRINT_FIELD(DISASM) && sample->insn_len) { in perf_sample__fprintf_insn()
1637 if (!PRINT_FIELD(IPC) || !sample->cyc_cnt || !sample->insn_cnt) in perf_sample__fprintf_ipc()
1640 ipc = (sample->insn_cnt * 100) / sample->cyc_cnt; in perf_sample__fprintf_ipc()
1643 ipc / 100, ipc % 100, sample->insn_cnt, sample->cyc_cnt); in perf_sample__fprintf_ipc()
1653 struct perf_event_attr *attr = &evsel->core.attr; in perf_sample__fprintf_bts()
1654 unsigned int type = output_type(attr->type); in perf_sample__fprintf_bts()
1666 if (symbol_conf.use_callchain && sample->callchain) { in perf_sample__fprintf_bts()
1668 if (thread__resolve_callchain(al->thread, cursor, evsel, in perf_sample__fprintf_bts()
1688 ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) && in perf_sample__fprintf_bts()
1697 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp); in perf_sample__fprintf_bts()
1702 int ret = map__fprintf_srccode(al->map, al->addr, stdout, in perf_sample__fprintf_bts()
1764 return snprintf(str, sz, "%-15s%6s", name, xs); in perf_sample__sprintf_flags()
1769 return snprintf(str, sz, "tr strt %-7s%6s", name, xs); in perf_sample__sprintf_flags()
1775 return snprintf(str, sz, "tr end %-7s%6s", name, xs); in perf_sample__sprintf_flags()
1778 for (i = 0; i < n; i++, flags >>= 1) { in perf_sample__sprintf_flags()
1779 if ((flags & 1) && pos < sz) in perf_sample__sprintf_flags()
1782 for (; i < 32; i++, flags >>= 1) { in perf_sample__sprintf_flags()
1783 if ((flags & 1) && pos < sz) in perf_sample__sprintf_flags()
1797 return fprintf(fp, " %-21s ", str); in perf_sample__fprintf_flags()
1819 printed += fprintf(fp, "%17s", !printer_data->line_no ? "BPF output:" : in sample__fprintf_bpf_output()
1835 if (printer_data->hit_nul && ch) in sample__fprintf_bpf_output()
1836 printer_data->is_printable = false; in sample__fprintf_bpf_output()
1841 if (!printer_data->is_printable) in sample__fprintf_bpf_output()
1845 printer_data->hit_nul = true; in sample__fprintf_bpf_output()
1847 printer_data->is_printable = false; in sample__fprintf_bpf_output()
1857 printer_data->line_no++; in sample__fprintf_bpf_output()
1869 unsigned int nr_bytes = sample->raw_size; in perf_sample__fprintf_bpf_output()
1871 int printed = binary__fprintf(sample->raw_data, nr_bytes, 8, in perf_sample__fprintf_bpf_output()
1875 printed += fprintf(fp, "%17s \"%s\"\n", "BPF string:", (char *)(sample->raw_data)); in perf_sample__fprintf_bpf_output()
1883 return fprintf(fp, "%*s", spacing - len, ""); in perf_sample__fprintf_spacing()
1917 char str[sizeof(u64) + 1] = ""; in perf_sample__fprintf_synth_ptwrite()
1924 val = le64_to_cpu(data->payload); in perf_sample__fprintf_synth_ptwrite()
1930 data->ip, val, str); in perf_sample__fprintf_synth_ptwrite()
1943 data->hints, data->extensions); in perf_sample__fprintf_synth_mwait()
1955 len = fprintf(fp, " hw: %u cstate: %u sub-cstate: %u ", in perf_sample__fprintf_synth_pwre()
1956 data->hw, data->cstate, data->subcstate); in perf_sample__fprintf_synth_pwre()
1968 len = fprintf(fp, " IP: %u ", data->ip); in perf_sample__fprintf_synth_exstop()
1981 data->deepest_cstate, data->last_cstate, in perf_sample__fprintf_synth_pwrx()
1982 data->wake_reason); in perf_sample__fprintf_synth_pwrx()
1995 freq = (le32_to_cpu(data->freq) + 500) / 1000; in perf_sample__fprintf_synth_cbr()
1996 len = fprintf(fp, " cbr: %2u freq: %4u MHz ", data->cbr, freq); in perf_sample__fprintf_synth_cbr()
1997 if (data->max_nonturbo) { in perf_sample__fprintf_synth_cbr()
1998 percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10; in perf_sample__fprintf_synth_cbr()
2012 len = fprintf(fp, " psb offs: %#" PRIx64, data->offset); in perf_sample__fprintf_synth_psb()
2030 s = cfe[data->type]; in perf_sample__fprintf_synth_evt()
2033 s, data->ip, data->vector); in perf_sample__fprintf_synth_evt()
2036 data->type, data->ip, data->vector); in perf_sample__fprintf_synth_evt()
2038 for (i = 0; i < data->evd_cnt; i++) { in perf_sample__fprintf_synth_evt()
2039 unsigned int et = data->evd[i].evd_type & 0x3f; in perf_sample__fprintf_synth_evt()
2044 s, data->evd[i].payload); in perf_sample__fprintf_synth_evt()
2047 et, data->evd[i].payload); in perf_sample__fprintf_synth_evt()
2061 len = fprintf(fp, " IFLAG: %d->%d %s branch", !data->iflag, data->iflag, in perf_sample__fprintf_synth_iflag_chg()
2062 data->via_branch ? "via" : "non"); in perf_sample__fprintf_synth_iflag_chg()
2069 switch (evsel->core.attr.config) { in perf_sample__fprintf_synth()
2112 char decode[100]; in data_src__fprintf()
2113 char out[100]; in data_src__fprintf()
2118 return -ENOMEM; in data_src__fprintf()
2120 mem_info__data_src(mi)->val = data_src; in data_src__fprintf()
2121 perf_script__meminfo_scnprintf(decode, 100, mi); in data_src__fprintf()
2124 len = scnprintf(out, 100, "%16" PRIx64 " %s", data_src, decode); in data_src__fprintf()
2128 return fprintf(fp, "%-*s", maxlen, out); in data_src__fprintf()
2147 perf_sample__fprintf_start(NULL, mctx->sample, mctx->thread, mctx->evsel, in script_print_metric()
2148 PERF_RECORD_SAMPLE, mctx->fp); in script_print_metric()
2149 fputs("\tmetric: ", mctx->fp); in script_print_metric()
2151 color_fprintf(mctx->fp, color, fmt, val); in script_print_metric()
2154 fprintf(mctx->fp, " %s\n", unit); in script_print_metric()
2162 perf_sample__fprintf_start(NULL, mctx->sample, mctx->thread, mctx->evsel, in script_new_line()
2163 PERF_RECORD_SAMPLE, mctx->fp); in script_new_line()
2164 fputs("\tmetric: ", mctx->fp); in script_new_line()
2188 if (!evsel->stats) in perf_sample__fprint_metric()
2189 evlist__alloc_stats(&stat_config, script->session->evlist, /*alloc_raw=*/false); in perf_sample__fprint_metric()
2190 if (evsel_script(leader)->gnum++ == 0) in perf_sample__fprint_metric()
2192 val = sample->period * evsel->scale; in perf_sample__fprint_metric()
2193 evsel_script(evsel)->val = val; in perf_sample__fprint_metric()
2194 if (evsel_script(leader)->gnum == leader->core.nr_members) { in perf_sample__fprint_metric()
2197 evsel_script(ev2)->val, in perf_sample__fprint_metric()
2198 sample->cpu, in perf_sample__fprint_metric()
2202 evsel_script(leader)->gnum = 0; in perf_sample__fprint_metric()
2212 int depth = thread_stack__depth(thread, sample->cpu); in show_event()
2254 struct thread *thread = al->thread; in process_event()
2255 struct perf_event_attr *attr = &evsel->core.attr; in process_event()
2256 unsigned int type = output_type(attr->type); in process_event()
2257 struct evsel_script *es = evsel->priv; in process_event()
2258 FILE *fp = es->fp; in process_event()
2260 const char *arch = perf_env__arch(machine->env); in process_event()
2265 ++es->samples; in process_event()
2271 fprintf(fp, "%10" PRIu64 " ", sample->period); in process_event()
2276 if (!script->name_width) in process_event()
2277 script->name_width = evlist__max_name_len(script->session->evlist); in process_event()
2279 fprintf(fp, "%*s: ", script->name_width, evname ?: "[unknown]"); in process_event()
2283 perf_sample__fprintf_flags(sample->flags, fp); in process_event()
2290 if (PRINT_FIELD(TRACE) && sample->raw_data) { in process_event()
2291 event_format__fprintf(evsel->tp_format, sample->cpu, in process_event()
2292 sample->raw_data, sample->raw_size, fp); in process_event()
2295 if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH)) in process_event()
2302 data_src__fprintf(sample->data_src, fp); in process_event()
2305 fprintf(fp, "%16" PRIu64, sample->weight); in process_event()
2308 fprintf(fp, "%16" PRIu16, sample->ins_lat); in process_event()
2311 fprintf(fp, "%16" PRIu16, sample->retire_lat); in process_event()
2315 struct cgroup *cgrp = cgroup__find(machine->env, in process_event()
2316 sample->cgroup); in process_event()
2318 cgrp_name = cgrp->name; in process_event()
2327 if (script->stitch_lbr) in process_event()
2328 thread__set_lbr_stitch_enable(al->thread, true); in process_event()
2330 if (symbol_conf.use_callchain && sample->callchain) { in process_event()
2332 if (thread__resolve_callchain(al->thread, cursor, evsel, in process_event()
2360 fprintf(fp, "%16" PRIx64, sample->phys_addr); in process_event()
2363 fprintf(fp, " %s", get_page_size_name(sample->data_page_size, str)); in process_event()
2366 fprintf(fp, " %s", get_page_size_name(sample->code_page_size, str)); in process_event()
2373 if (map__fprintf_srccode(al->map, al->addr, stdout, in process_event()
2389 int nthreads = perf_thread_map__nr(counter->core.threads); in __process_stat()
2397 header_printed = 1; in __process_stat()
2404 counts = perf_counts(counter->counts, idx, thread); in __process_stat()
2408 perf_thread_map__pid(counter->core.threads, thread), in __process_stat()
2409 counts->val, in __process_stat()
2410 counts->ena, in __process_stat()
2411 counts->run, in __process_stat()
2420 if (scripting_ops && scripting_ops->process_stat) in process_stat()
2421 scripting_ops->process_stat(&stat_config, counter, tstamp); in process_stat()
2428 if (scripting_ops && scripting_ops->process_stat_interval) in process_stat_interval()
2429 scripting_ops->process_stat_interval(tstamp); in process_stat_interval()
2442 return scripting_ops ? scripting_ops->flush_script() : 0; in flush_scripting()
2449 return scripting_ops ? scripting_ops->stop_script() : 0; in cleanup_scripting()
2454 if (cpu_list && sample->cpu != (u32)-1) in filter_cpu()
2455 return !test_bit(sample->cpu, cpu_bitmap); in filter_cpu()
2481 if (perf_time__ranges_skip_sample(scr->ptime_range, scr->range_num, in process_sample_event()
2482 sample->time)) { in process_sample_event()
2487 if (sample->time < last_timestamp) { in process_sample_event()
2490 sample->time); in process_sample_event()
2493 last_timestamp = sample->time; in process_sample_event()
2502 event->header.type); in process_sample_event()
2503 ret = -1; in process_sample_event()
2513 if (evswitch__discard(&scr->evswitch, evsel)) in process_sample_event()
2526 if ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) && in process_sample_event()
2527 sample_addr_correlates_sym(&evsel->core.attr)) { in process_sample_event()
2532 scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); in process_sample_event()
2543 // Used when scr->per_event_dump is not set
2562 if (!evsel->priv) { in process_attr()
2563 if (scr->per_event_dump) { in process_attr()
2564 evsel->priv = evsel_script__new(evsel, scr->session->data); in process_attr()
2565 if (!evsel->priv) in process_attr()
2566 return -ENOMEM; in process_attr()
2569 evsel->priv = &es_stdout; in process_attr()
2573 if (evsel->core.attr.type >= PERF_TYPE_MAX && in process_attr()
2574 evsel->core.attr.type != PERF_TYPE_SYNTH) in process_attr()
2578 if (pos->core.attr.type == evsel->core.attr.type && pos != evsel) in process_attr()
2582 if (evsel->core.attr.sample_type) { in process_attr()
2583 err = evsel__check_attr(evsel, scr->session); in process_attr()
2593 callchain_param_setup(sample_type, perf_env__arch((*pevlist)->env)); in process_attr()
2601 int type = output_type(evsel->core.attr.type); in process_attr()
2608 set_print_ip_opts(&evsel->core.attr); in process_attr()
2619 struct perf_session *session = script->session; in print_event_with_time()
2620 struct evsel *evsel = evlist__id2evsel(session->evlist, sample->id); in print_event_with_time()
2623 if (evsel && !evsel->core.attr.sample_id_all) { in print_event_with_time()
2624 sample->cpu = 0; in print_event_with_time()
2625 sample->time = timestamp; in print_event_with_time()
2626 sample->pid = pid; in print_event_with_time()
2627 sample->tid = tid; in print_event_with_time()
2633 if (tid != -1) in print_event_with_time()
2638 event->header.type, stdout); in print_event_with_time()
2661 return -1; in process_comm_event()
2663 return print_event(tool, event, sample, machine, event->comm.pid, in process_comm_event()
2664 event->comm.tid); in process_comm_event()
2673 return -1; in process_namespaces_event()
2675 return print_event(tool, event, sample, machine, event->namespaces.pid, in process_namespaces_event()
2676 event->namespaces.tid); in process_namespaces_event()
2685 return -1; in process_cgroup_event()
2687 return print_event(tool, event, sample, machine, sample->pid, in process_cgroup_event()
2688 sample->tid); in process_cgroup_event()
2697 return -1; in process_fork_event()
2700 event->fork.pid, event->fork.tid, in process_fork_event()
2701 event->fork.time); in process_fork_event()
2709 if (print_event_with_time(tool, event, sample, machine, event->fork.pid, in process_exit_event()
2710 event->fork.tid, event->fork.time)) in process_exit_event()
2711 return -1; in process_exit_event()
2722 return -1; in process_mmap_event()
2724 return print_event(tool, event, sample, machine, event->mmap.pid, in process_mmap_event()
2725 event->mmap.tid); in process_mmap_event()
2734 return -1; in process_mmap2_event()
2736 return print_event(tool, event, sample, machine, event->mmap2.pid, in process_mmap2_event()
2737 event->mmap2.tid); in process_mmap2_event()
2748 return -1; in process_switch_event()
2750 if (scripting_ops && scripting_ops->process_switch && !filter_cpu(sample)) in process_switch_event()
2751 scripting_ops->process_switch(event, sample, machine); in process_switch_event()
2753 if (!script->show_switch_events) in process_switch_event()
2756 return print_event(tool, event, sample, machine, sample->pid, in process_switch_event()
2757 sample->tid); in process_switch_event()
2763 if (scripting_ops && scripting_ops->process_auxtrace_error) { in process_auxtrace_error()
2764 scripting_ops->process_auxtrace_error(session, event); in process_auxtrace_error()
2777 return print_event(tool, event, sample, machine, sample->pid, in process_lost_event()
2778 sample->tid); in process_lost_event()
2787 if (scripting_ops && scripting_ops->process_throttle) in process_throttle_event()
2788 scripting_ops->process_throttle(event, sample, machine); in process_throttle_event()
2809 return -1; in process_bpf_events()
2811 return print_event(tool, event, sample, machine, sample->pid, in process_bpf_events()
2812 sample->tid); in process_bpf_events()
2821 return -1; in process_text_poke_events()
2823 return print_event(tool, event, sample, machine, sample->pid, in process_text_poke_events()
2824 sample->tid); in process_text_poke_events()
2829 session_done = 1; in sig_handler()
2834 struct evlist *evlist = script->session->evlist; in perf_script__fclose_per_event_dump()
2838 if (!evsel->priv) in perf_script__fclose_per_event_dump()
2840 evsel_script__delete(evsel->priv); in perf_script__fclose_per_event_dump()
2841 evsel->priv = NULL; in perf_script__fclose_per_event_dump()
2849 evlist__for_each_entry(script->session->evlist, evsel) { in perf_script__fopen_per_event_dump()
2857 if (evsel->priv != NULL) in perf_script__fopen_per_event_dump()
2860 evsel->priv = evsel_script__new(evsel, script->session->data); in perf_script__fopen_per_event_dump()
2861 if (evsel->priv == NULL) in perf_script__fopen_per_event_dump()
2869 return -1; in perf_script__fopen_per_event_dump()
2876 if (script->per_event_dump) in perf_script__setup_per_event_dump()
2881 evlist__for_each_entry(script->session->evlist, evsel) in perf_script__setup_per_event_dump()
2882 evsel->priv = &es_stdout; in perf_script__setup_per_event_dump()
2891 evlist__for_each_entry(script->session->evlist, evsel) { in perf_script__exit_per_event_dump_stats()
2892 struct evsel_script *es = evsel->priv; in perf_script__exit_per_event_dump_stats()
2896 evsel->priv = NULL; in perf_script__exit_per_event_dump_stats()
2902 perf_thread_map__put(script->threads); in perf_script__exit()
2903 perf_cpu_map__put(script->cpus); in perf_script__exit()
2913 if (script->show_task_events) { in __cmd_script()
2914 script->tool.comm = process_comm_event; in __cmd_script()
2915 script->tool.fork = process_fork_event; in __cmd_script()
2916 script->tool.exit = process_exit_event; in __cmd_script()
2918 if (script->show_mmap_events) { in __cmd_script()
2919 script->tool.mmap = process_mmap_event; in __cmd_script()
2920 script->tool.mmap2 = process_mmap2_event; in __cmd_script()
2922 if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) in __cmd_script()
2923 script->tool.context_switch = process_switch_event; in __cmd_script()
2924 if (scripting_ops && scripting_ops->process_auxtrace_error) in __cmd_script()
2925 script->tool.auxtrace_error = process_auxtrace_error; in __cmd_script()
2926 if (script->show_namespace_events) in __cmd_script()
2927 script->tool.namespaces = process_namespaces_event; in __cmd_script()
2928 if (script->show_cgroup_events) in __cmd_script()
2929 script->tool.cgroup = process_cgroup_event; in __cmd_script()
2930 if (script->show_lost_events) in __cmd_script()
2931 script->tool.lost = process_lost_event; in __cmd_script()
2932 if (script->show_round_events) { in __cmd_script()
2933 script->tool.ordered_events = false; in __cmd_script()
2934 script->tool.finished_round = process_finished_round_event; in __cmd_script()
2936 if (script->show_bpf_events) { in __cmd_script()
2937 script->tool.ksymbol = process_bpf_events; in __cmd_script()
2938 script->tool.bpf = process_bpf_events; in __cmd_script()
2940 if (script->show_text_poke_events) { in __cmd_script()
2941 script->tool.ksymbol = process_bpf_events; in __cmd_script()
2942 script->tool.text_poke = process_text_poke_events; in __cmd_script()
2947 return -1; in __cmd_script()
2950 ret = perf_session__process_events(script->session); in __cmd_script()
2952 if (script->per_event_dump) in __cmd_script()
2972 struct script_spec *s = malloc(sizeof(*s) + strlen(spec) + 1); in script_spec__new()
2975 strcpy(s->spec, spec); in script_spec__new()
2976 s->ops = ops; in script_spec__new()
2984 list_add_tail(&s->node, &script_specs); in script_spec__add()
2992 if (strcasecmp(s->spec, spec) == 0) in script_spec__find()
3003 return -1; in script_spec_register()
3007 return -1; in script_spec_register()
3020 return s->ops; in script_spec__lookup()
3029 "perf script -s [spec:]script.[spec]):\n\n"); in list_available_languages()
3032 fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); in list_available_languages()
3059 exec_path, scripting_ops->dirname, script); in find_script()
3082 len = script - str; in parse_scriptname()
3085 return -1; in parse_scriptname()
3092 return -1; in parse_scriptname()
3100 return -1; in parse_scriptname()
3105 return -1; in parse_scriptname()
3124 int type = -1; in parse_output_fields()
3128 return -ENOMEM; in parse_output_fields()
3152 rc = -EINVAL; in parse_output_fields()
3160 /* Don't override defaults for +- */ in parse_output_fields()
3161 if (strchr(tok, '+') || strchr(tok, '-')) in parse_output_fields()
3173 rc = -EINVAL; in parse_output_fields()
3177 /* Don't override defaults for +- */ in parse_output_fields()
3178 if (strchr(str, '+') || strchr(str, '-')) in parse_output_fields()
3198 } else if (*tok == '-') { in parse_output_fields()
3219 rc = -EINVAL; in parse_output_fields()
3225 rc = -EINVAL; in parse_output_fields()
3230 if (type == -1) { in parse_output_fields()
3257 rc = -EINVAL; in parse_output_fields()
3278 fprintf(stderr, "Cannot mix +-field with overridden fields\n"); in parse_output_fields()
3279 rc = -EINVAL; in parse_output_fields()
3287 if ((lang_dirent->d_type == DT_DIR || \
3288 (lang_dirent->d_type == DT_UNKNOWN && \
3290 (strcmp(lang_dirent->d_name, ".")) && \
3291 (strcmp(lang_dirent->d_name, "..")))
3295 if (script_dirent->d_type != DT_DIR && \
3296 (script_dirent->d_type != DT_UNKNOWN || \
3300 #define RECORD_SUFFIX "-record"
3301 #define REPORT_SUFFIX "-report"
3317 s->name = strdup(name); in script_desc__new()
3324 zfree(&s->name); in script_desc__delete()
3325 zfree(&s->half_liner); in script_desc__delete()
3326 zfree(&s->args); in script_desc__delete()
3332 list_add_tail(&s->node, &script_descs); in script_desc__add()
3340 if (strcasecmp(s->name, name) == 0) in script_desc__find()
3367 p = str + strlen(str) - suffix_len; in ends_with()
3382 return -1; in read_script_info()
3395 if (strlen(p) && p[strlen(p) - 1] == '\n') in read_script_info()
3396 p[strlen(p) - 1] = '\0'; in read_script_info()
3400 desc->half_liner = strdup(skip_spaces(p)); in read_script_info()
3406 desc->args = strdup(skip_spaces(p)); in read_script_info()
3420 script_root = strdup(script_dirent->d_name); in get_script_root()
3447 exit(-1); in list_available_scripts()
3463 exit(-1); in list_available_scripts()
3468 lang_dirent->d_name); in list_available_scripts()
3478 lang_path, script_dirent->d_name); in list_available_scripts()
3487 sprintf(first_half, "%s %s", desc->name, in list_available_scripts()
3488 desc->args ? desc->args : ""); in list_available_scripts()
3489 fprintf(stdout, " %-36s %s\n", first_half, in list_available_scripts()
3490 desc->half_liner ? desc->half_liner : ""); in list_available_scripts()
3504 return -1; in add_dlarg()
3506 a = realloc(dlargv, sizeof(dlargv[0]) * (dlargc + 1)); in add_dlarg()
3509 return -1; in add_dlarg()
3520 while (dlargc--) in free_dlarg()
3526 * Some scripts specify the required events in their "xxx-record" file,
3528 * mentioned in the "xxx-record".
3530 * Fixme: All existing "xxx-record" are all in good formats "-e event ",
3543 scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname); in check_ev_match()
3547 return -1; in check_ev_match()
3555 p = strstr(p, "-e"); in check_ev_match()
3565 snprintf(evname, len + 1, "%s", p); in check_ev_match()
3568 evlist__for_each_entry(session->evlist, pos) { in check_ev_match()
3570 match = 1; in check_ev_match()
3577 return -1; in check_ev_match()
3587 * Return -1 if none is found, otherwise the actual scripts number.
3616 return -1; in find_scripts()
3621 lang_dirent->d_name); in find_scripts()
3637 if (strstr(script_dirent->d_name, "top.")) in find_scripts()
3643 script_dirent->d_name); in find_scripts()
3644 temp = strchr(script_dirent->d_name, '.'); in find_scripts()
3646 (temp - script_dirent->d_name) + 1, in find_scripts()
3647 "%s", script_dirent->d_name); in find_scripts()
3680 lang_dirent->d_name); in get_script_path()
3691 lang_path, script_dirent->d_name); in get_script_path()
3720 if (!desc->args) in has_required_arg()
3723 for (p = desc->args; *p; p++) in has_required_arg()
3738 return -1; in have_cmd()
3753 struct perf_session *session = script->session; in script__setup_sample_type()
3754 u64 sample_type = evlist__combined_sample_type(session->evlist); in script__setup_sample_type()
3756 callchain_param_setup(sample_type, perf_env__arch(session->machines.host.env)); in script__setup_sample_type()
3758 if (script->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) { in script__setup_sample_type()
3759 pr_warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" in script__setup_sample_type()
3760 "Please apply --call-graph lbr when recording.\n"); in script__setup_sample_type()
3761 script->stitch_lbr = false; in script__setup_sample_type()
3768 struct perf_record_stat_round *round = &event->stat_round; in process_stat_round_event()
3771 evlist__for_each_entry(session->evlist, counter) { in process_stat_round_event()
3773 process_stat(counter, round->time); in process_stat_round_event()
3776 process_stat_interval(round->time); in process_stat_round_event()
3783 perf_event__read_stat_config(&stat_config, &event->stat_config); in process_stat_config_event()
3786 * Aggregation modes are not used since post-processing scripts are in process_stat_config_event()
3796 struct evlist *evlist = script->session->evlist; in set_maps()
3798 if (!script->cpus || !script->threads) in set_maps()
3801 if (WARN_ONCE(script->allocated, "stats double allocation\n")) in set_maps()
3802 return -EINVAL; in set_maps()
3804 perf_evlist__set_maps(&evlist->core, script->cpus, script->threads); in set_maps()
3807 return -ENOMEM; in set_maps()
3809 script->allocated = true; in set_maps()
3817 const struct perf_tool *tool = session->tool; in process_thread_map_event()
3823 if (script->threads) { in process_thread_map_event()
3828 script->threads = thread_map__new_event(&event->thread_map); in process_thread_map_event()
3829 if (!script->threads) in process_thread_map_event()
3830 return -ENOMEM; in process_thread_map_event()
3839 const struct perf_tool *tool = session->tool; in process_cpu_map_event()
3845 if (script->cpus) { in process_cpu_map_event()
3850 script->cpus = cpu_map__new_data(&event->cpu_map.data); in process_cpu_map_event()
3851 if (!script->cpus) in process_cpu_map_event()
3852 return -ENOMEM; in process_cpu_map_event()
3860 if (event->feat.feat_id < HEADER_LAST_FEATURE) in process_feature_event()
3872 const struct perf_tool *tool = session->tool; in perf_script__process_auxtrace_info()
3887 const char *fields = "+insn,-event,-period"; in parse_insn_trace()
3892 fields = "+disasm,-event,-period"; in parse_insn_trace()
3895 return -EINVAL; in parse_insn_trace()
3912 if (isatty(1)) in parse_xed()
3913 force_pager("xed -F insn: -A -64 | less"); in parse_xed()
3915 force_pager("xed -F insn: -A -64"); in parse_xed()
3923 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0); in parse_call_trace()
3934 parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent,+flags", 0); in parse_callret_trace()
3964 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, in cmd_script()
3966 OPT_BOOLEAN(0, "dump-unsorted-raw-trace", &unsorted_dump, in cmd_script()
3974 OPT_CALLBACK_NOOPT(0, "list-dlfilters", NULL, NULL, "list available dlfilters", in cmd_script()
3979 OPT_STRING('g', "gen-script", &generate_script_lang, "lang", in cmd_script()
3980 "generate perf-script.xx script in specified language"), in cmd_script()
3985 OPT_BOOLEAN('d', "debug-mode", &debug_mode, in cmd_script()
3988 OPT_BOOLEAN(0, "header-only", &header_only, "Show only data header."), in cmd_script()
3993 OPT_BOOLEAN('G', "hide-call-graph", &no_callchain, in cmd_script()
4000 "+field to add and -field to remove." in cmd_script()
4004 "brstacksym,flags,data_src,weight,bpf-output,brstackinsn," in cmd_script()
4010 OPT_BOOLEAN('a', "all-cpus", &system_wide, in cmd_script()
4011 "system-wide collection from all CPUs"), in cmd_script()
4016 OPT_INTEGER(0, "addr-range", &symbol_conf.addr_range, in cmd_script()
4017 "Use with -S to list traced records within address range"), in cmd_script()
4018 OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, "raw|disasm", in cmd_script()
4022 OPT_CALLBACK_OPTARG(0, "call-trace", &itrace_synth_opts, NULL, NULL, in cmd_script()
4024 OPT_CALLBACK_OPTARG(0, "call-ret-trace", &itrace_synth_opts, NULL, NULL, in cmd_script()
4026 OPT_STRING(0, "graph-function", &symbol_conf.graph_function, "symbol[,symbol...]", in cmd_script()
4027 "Only print symbols and callees with --call-trace/--call-ret-trace"), in cmd_script()
4028 OPT_STRING(0, "stop-bt", &symbol_conf.bt_stop_list_str, "symbol[,symbol...]", in cmd_script()
4037 OPT_UINTEGER(0, "max-stack", &scripting_max_stack, in cmd_script()
4043 OPT_BOOLEAN('I', "show-info", &show_full_info, in cmd_script()
4045 OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path, in cmd_script()
4047 OPT_BOOLEAN('\0', "show-task-events", &script.show_task_events, in cmd_script()
4049 OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, in cmd_script()
4051 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, in cmd_script()
4053 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, in cmd_script()
4055 OPT_BOOLEAN('\0', "show-cgroup-events", &script.show_cgroup_events, in cmd_script()
4057 OPT_BOOLEAN('\0', "show-lost-events", &script.show_lost_events, in cmd_script()
4059 OPT_BOOLEAN('\0', "show-round-events", &script.show_round_events, in cmd_script()
4061 OPT_BOOLEAN('\0', "show-bpf-events", &script.show_bpf_events, in cmd_script()
4063 OPT_BOOLEAN('\0', "show-text-poke-events", &script.show_text_poke_events, in cmd_script()
4065 OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump, in cmd_script()
4068 OPT_INTEGER(0, "max-blocks", &max_blocks, in cmd_script()
4075 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, in cmd_script()
4079 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, in cmd_script()
4096 OPT_BOOLEAN(0, "guest-code", &symbol_conf.guest_code, in cmd_script()
4098 OPT_BOOLEAN('\0', "stitch-lbr", &script.stitch_lbr, in cmd_script()
4106 "perf script [<options>] record <script> [<record-options>] <command>", in cmd_script()
4107 "perf script [<options>] report <script> [script-args]", in cmd_script()
4108 "perf script [<options>] <script> [<record-options>] <command>", in cmd_script()
4109 "perf script [<options>] <top-script> [script-args]", in cmd_script()
4138 return -1; in cmd_script()
4140 if (argc > 1 && strlen(argv[0]) > 2 && strstarts("record", argv[0])) { in cmd_script()
4141 rec_script_path = get_script_path(argv[1], RECORD_SUFFIX); in cmd_script()
4146 if (argc > 1 && strlen(argv[0]) > 2 && strstarts("report", argv[0])) { in cmd_script()
4147 rep_script_path = get_script_path(argv[1], REPORT_SUFFIX); in cmd_script()
4151 "(see 'perf script -l' for listing)\n"); in cmd_script()
4152 return -1; in cmd_script()
4158 "reltime and deltatime - the two don't get along well. " in cmd_script()
4159 "Please limit to --reltime or --deltatime.\n"); in cmd_script()
4160 return -1; in cmd_script()
4181 argc -= 1; in cmd_script()
4182 argv += 1; in cmd_script()
4187 " script -l for available scripts.\n", argv[0]); in cmd_script()
4191 rep_args = argc - 1; in cmd_script()
4196 rec_args = (argc - 1) - rep_args; in cmd_script()
4200 "\n\n See perf script -l for available " in cmd_script()
4207 return -1; in cmd_script()
4213 return -1; in cmd_script()
4219 dup2(live_pipe[1], 1); in cmd_script()
4225 if (have_cmd(argc - rep_args, &argv[rep_args]) != 0) { in cmd_script()
4226 err = -1; in cmd_script()
4234 err = -ENOMEM; in cmd_script()
4241 __argv[j++] = "-a"; in cmd_script()
4242 __argv[j++] = "-q"; in cmd_script()
4243 __argv[j++] = "-o"; in cmd_script()
4244 __argv[j++] = "-"; in cmd_script()
4245 for (i = rep_args + 1; i < argc; i++) in cmd_script()
4251 exit(-1); in cmd_script()
4255 close(live_pipe[1]); in cmd_script()
4260 err = -ENOMEM; in cmd_script()
4267 for (i = 1; i < rep_args + 1; i++) in cmd_script()
4269 __argv[j++] = "-i"; in cmd_script()
4270 __argv[j++] = "-"; in cmd_script()
4275 exit(-1); in cmd_script()
4289 if (have_cmd(argc - 1, &argv[1]) != 0) { in cmd_script()
4290 err = -1; in cmd_script()
4298 err = -ENOMEM; in cmd_script()
4305 __argv[j++] = "-a"; in cmd_script()
4312 exit(-1); in cmd_script()
4318 return -1; in cmd_script()
4367 if (symbol__init(&session->header.env) < 0) in cmd_script()
4373 } else if (session->header.env.arch) { in cmd_script()
4374 if (!strcmp(uts.machine, session->header.env.arch)) in cmd_script()
4377 !strcmp(session->header.env.arch, "i386")) in cmd_script()
4388 session->itrace_synth_opts = &itrace_synth_opts; in cmd_script()
4403 if (session->tevent.pevent && in cmd_script()
4404 tep_set_function_resolver(session->tevent.pevent, in cmd_script()
4406 &session->machines.host) < 0) { in cmd_script()
4408 err = -1; in cmd_script()
4419 err = -EINVAL; in cmd_script()
4425 err = -errno; in cmd_script()
4437 fprintf(stderr, "zero-sized file, nothing to do!\n"); in cmd_script()
4444 err = -ENOENT; in cmd_script()
4448 err = scripting_ops->generate_script(session->tevent.pevent, in cmd_script()
4449 "perf-script"); in cmd_script()
4451 err = scripting_ops->generate_script(NULL, "perf-script"); in cmd_script()
4461 err = scripting_ops->start_script(script_name, argc, argv, session); in cmd_script()
4487 err = evswitch__init(&script.evswitch, session->evlist, stderr); in cmd_script()
4491 if (zstd_init(&(session->zstd_data), 0) < 0) in cmd_script()
4507 zstd_fini(&(session->zstd_data)); in cmd_script()
4508 evlist__free_stats(session->evlist); in cmd_script()