1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/kernel.h>
6 #include <linux/zalloc.h>
11 #include <sys/types.h>
13 #include <perf/cpumap.h>
15 #include "map_symbol.h"
25 #include "perf_regs.h"
29 #include "thread-stack.h"
30 #include "sample-raw.h"
33 #include "ui/progress.h"
35 #include "arch/common.h"
37 #include <internal/lib.h>
39 #ifdef HAVE_ZSTD_SUPPORT
40 static int perf_session__process_compressed_event(struct perf_session *session,
41 union perf_event *event, u64 file_offset)
44 size_t decomp_size, src_size;
45 u64 decomp_last_rem = 0;
46 size_t mmap_len, decomp_len = session->header.env.comp_mmap_len;
47 struct decomp *decomp, *decomp_last = session->decomp_last;
50 decomp_last_rem = decomp_last->size - decomp_last->head;
51 decomp_len += decomp_last_rem;
54 mmap_len = sizeof(struct decomp) + decomp_len;
55 decomp = mmap(NULL, mmap_len, PROT_READ|PROT_WRITE,
56 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
57 if (decomp == MAP_FAILED) {
58 pr_err("Couldn't allocate memory for decompression\n");
62 decomp->file_pos = file_offset;
63 decomp->mmap_len = mmap_len;
66 if (decomp_last_rem) {
67 memcpy(decomp->data, &(decomp_last->data[decomp_last->head]), decomp_last_rem);
68 decomp->size = decomp_last_rem;
71 src = (void *)event + sizeof(struct perf_record_compressed);
72 src_size = event->pack.header.size - sizeof(struct perf_record_compressed);
74 decomp_size = zstd_decompress_stream(&(session->zstd_data), src, src_size,
75 &(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem);
77 munmap(decomp, mmap_len);
78 pr_err("Couldn't decompress data\n");
82 decomp->size += decomp_size;
84 if (session->decomp == NULL) {
85 session->decomp = decomp;
86 session->decomp_last = decomp;
88 session->decomp_last->next = decomp;
89 session->decomp_last = decomp;
92 pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size);
96 #else /* !HAVE_ZSTD_SUPPORT */
97 #define perf_session__process_compressed_event perf_session__process_compressed_event_stub
100 static int perf_session__deliver_event(struct perf_session *session,
101 union perf_event *event,
102 struct perf_tool *tool,
105 static int perf_session__open(struct perf_session *session, int repipe_fd)
107 struct perf_data *data = session->data;
109 if (perf_session__read_header(session, repipe_fd) < 0) {
110 pr_err("incompatible file format (rerun with -v to learn more)\n");
114 if (perf_data__is_pipe(data))
117 if (perf_header__has_feat(&session->header, HEADER_STAT))
120 if (!evlist__valid_sample_type(session->evlist)) {
121 pr_err("non matching sample_type\n");
125 if (!evlist__valid_sample_id_all(session->evlist)) {
126 pr_err("non matching sample_id_all\n");
130 if (!evlist__valid_read_format(session->evlist)) {
131 pr_err("non matching read_format\n");
138 void perf_session__set_id_hdr_size(struct perf_session *session)
140 u16 id_hdr_size = evlist__id_hdr_size(session->evlist);
142 machines__set_id_hdr_size(&session->machines, id_hdr_size);
145 int perf_session__create_kernel_maps(struct perf_session *session)
147 int ret = machine__create_kernel_maps(&session->machines.host);
150 ret = machines__create_guest_kernel_maps(&session->machines);
154 static void perf_session__destroy_kernel_maps(struct perf_session *session)
156 machines__destroy_kernel_maps(&session->machines);
159 static bool perf_session__has_comm_exec(struct perf_session *session)
163 evlist__for_each_entry(session->evlist, evsel) {
164 if (evsel->core.attr.comm_exec)
171 static void perf_session__set_comm_exec(struct perf_session *session)
173 bool comm_exec = perf_session__has_comm_exec(session);
175 machines__set_comm_exec(&session->machines, comm_exec);
178 static int ordered_events__deliver_event(struct ordered_events *oe,
179 struct ordered_event *event)
181 struct perf_session *session = container_of(oe, struct perf_session,
184 return perf_session__deliver_event(session, event->event,
185 session->tool, event->file_offset);
188 struct perf_session *__perf_session__new(struct perf_data *data,
189 bool repipe, int repipe_fd,
190 struct perf_tool *tool)
193 struct perf_session *session = zalloc(sizeof(*session));
198 session->repipe = repipe;
199 session->tool = tool;
200 INIT_LIST_HEAD(&session->auxtrace_index);
201 machines__init(&session->machines);
202 ordered_events__init(&session->ordered_events,
203 ordered_events__deliver_event, NULL);
205 perf_env__init(&session->header.env);
207 ret = perf_data__open(data);
211 session->data = data;
213 if (perf_data__is_read(data)) {
214 ret = perf_session__open(session, repipe_fd);
219 * set session attributes that are present in perf.data
220 * but not in pipe-mode.
222 if (!data->is_pipe) {
223 perf_session__set_id_hdr_size(session);
224 perf_session__set_comm_exec(session);
227 evlist__init_trace_event_sample_raw(session->evlist);
229 /* Open the directory data. */
231 ret = perf_data__open_dir(data);
236 if (!symbol_conf.kallsyms_name &&
237 !symbol_conf.vmlinux_name)
238 symbol_conf.kallsyms_name = perf_data__kallsyms_name(data);
241 session->machines.host.env = &perf_env;
244 session->machines.host.single_address_space =
245 perf_env__single_address_space(session->machines.host.env);
247 if (!data || perf_data__is_write(data)) {
249 * In O_RDONLY mode this will be performed when reading the
250 * kernel MMAP event, in perf_event__process_mmap().
252 if (perf_session__create_kernel_maps(session) < 0)
253 pr_warning("Cannot read kernel map\n");
257 * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is
258 * processed, so evlist__sample_id_all is not meaningful here.
260 if ((!data || !data->is_pipe) && tool && tool->ordering_requires_timestamps &&
261 tool->ordered_events && !evlist__sample_id_all(session->evlist)) {
262 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
263 tool->ordered_events = false;
269 perf_session__delete(session);
274 static void perf_session__delete_threads(struct perf_session *session)
276 machine__delete_threads(&session->machines.host);
279 static void perf_session__release_decomp_events(struct perf_session *session)
281 struct decomp *next, *decomp;
283 next = session->decomp;
289 mmap_len = decomp->mmap_len;
290 munmap(decomp, mmap_len);
294 void perf_session__delete(struct perf_session *session)
298 auxtrace__free(session);
299 auxtrace_index__free(&session->auxtrace_index);
300 perf_session__destroy_kernel_maps(session);
301 perf_session__delete_threads(session);
302 perf_session__release_decomp_events(session);
303 perf_env__exit(&session->header.env);
304 machines__exit(&session->machines);
306 if (perf_data__is_read(session->data))
307 evlist__delete(session->evlist);
308 perf_data__close(session->data);
310 trace_event__cleanup(&session->tevent);
314 static int process_event_synth_tracing_data_stub(struct perf_session *session
316 union perf_event *event
319 dump_printf(": unhandled!\n");
323 static int process_event_synth_attr_stub(struct perf_tool *tool __maybe_unused,
324 union perf_event *event __maybe_unused,
325 struct evlist **pevlist
328 dump_printf(": unhandled!\n");
332 static int process_event_synth_event_update_stub(struct perf_tool *tool __maybe_unused,
333 union perf_event *event __maybe_unused,
334 struct evlist **pevlist
338 perf_event__fprintf_event_update(event, stdout);
340 dump_printf(": unhandled!\n");
344 static int process_event_sample_stub(struct perf_tool *tool __maybe_unused,
345 union perf_event *event __maybe_unused,
346 struct perf_sample *sample __maybe_unused,
347 struct evsel *evsel __maybe_unused,
348 struct machine *machine __maybe_unused)
350 dump_printf(": unhandled!\n");
354 static int process_event_stub(struct perf_tool *tool __maybe_unused,
355 union perf_event *event __maybe_unused,
356 struct perf_sample *sample __maybe_unused,
357 struct machine *machine __maybe_unused)
359 dump_printf(": unhandled!\n");
363 static int process_finished_round_stub(struct perf_tool *tool __maybe_unused,
364 union perf_event *event __maybe_unused,
365 struct ordered_events *oe __maybe_unused)
367 dump_printf(": unhandled!\n");
371 static int process_finished_round(struct perf_tool *tool,
372 union perf_event *event,
373 struct ordered_events *oe);
375 static int skipn(int fd, off_t n)
381 ret = read(fd, buf, min(n, (off_t)sizeof(buf)));
390 static s64 process_event_auxtrace_stub(struct perf_session *session __maybe_unused,
391 union perf_event *event)
393 dump_printf(": unhandled!\n");
394 if (perf_data__is_pipe(session->data))
395 skipn(perf_data__fd(session->data), event->auxtrace.size);
396 return event->auxtrace.size;
399 static int process_event_op2_stub(struct perf_session *session __maybe_unused,
400 union perf_event *event __maybe_unused)
402 dump_printf(": unhandled!\n");
408 int process_event_thread_map_stub(struct perf_session *session __maybe_unused,
409 union perf_event *event __maybe_unused)
412 perf_event__fprintf_thread_map(event, stdout);
414 dump_printf(": unhandled!\n");
419 int process_event_cpu_map_stub(struct perf_session *session __maybe_unused,
420 union perf_event *event __maybe_unused)
423 perf_event__fprintf_cpu_map(event, stdout);
425 dump_printf(": unhandled!\n");
430 int process_event_stat_config_stub(struct perf_session *session __maybe_unused,
431 union perf_event *event __maybe_unused)
434 perf_event__fprintf_stat_config(event, stdout);
436 dump_printf(": unhandled!\n");
440 static int process_stat_stub(struct perf_session *perf_session __maybe_unused,
441 union perf_event *event)
444 perf_event__fprintf_stat(event, stdout);
446 dump_printf(": unhandled!\n");
450 static int process_stat_round_stub(struct perf_session *perf_session __maybe_unused,
451 union perf_event *event)
454 perf_event__fprintf_stat_round(event, stdout);
456 dump_printf(": unhandled!\n");
460 static int process_event_time_conv_stub(struct perf_session *perf_session __maybe_unused,
461 union perf_event *event)
464 perf_event__fprintf_time_conv(event, stdout);
466 dump_printf(": unhandled!\n");
470 static int perf_session__process_compressed_event_stub(struct perf_session *session __maybe_unused,
471 union perf_event *event __maybe_unused,
472 u64 file_offset __maybe_unused)
474 dump_printf(": unhandled!\n");
478 void perf_tool__fill_defaults(struct perf_tool *tool)
480 if (tool->sample == NULL)
481 tool->sample = process_event_sample_stub;
482 if (tool->mmap == NULL)
483 tool->mmap = process_event_stub;
484 if (tool->mmap2 == NULL)
485 tool->mmap2 = process_event_stub;
486 if (tool->comm == NULL)
487 tool->comm = process_event_stub;
488 if (tool->namespaces == NULL)
489 tool->namespaces = process_event_stub;
490 if (tool->cgroup == NULL)
491 tool->cgroup = process_event_stub;
492 if (tool->fork == NULL)
493 tool->fork = process_event_stub;
494 if (tool->exit == NULL)
495 tool->exit = process_event_stub;
496 if (tool->lost == NULL)
497 tool->lost = perf_event__process_lost;
498 if (tool->lost_samples == NULL)
499 tool->lost_samples = perf_event__process_lost_samples;
500 if (tool->aux == NULL)
501 tool->aux = perf_event__process_aux;
502 if (tool->itrace_start == NULL)
503 tool->itrace_start = perf_event__process_itrace_start;
504 if (tool->context_switch == NULL)
505 tool->context_switch = perf_event__process_switch;
506 if (tool->ksymbol == NULL)
507 tool->ksymbol = perf_event__process_ksymbol;
508 if (tool->bpf == NULL)
509 tool->bpf = perf_event__process_bpf;
510 if (tool->text_poke == NULL)
511 tool->text_poke = perf_event__process_text_poke;
512 if (tool->read == NULL)
513 tool->read = process_event_sample_stub;
514 if (tool->throttle == NULL)
515 tool->throttle = process_event_stub;
516 if (tool->unthrottle == NULL)
517 tool->unthrottle = process_event_stub;
518 if (tool->attr == NULL)
519 tool->attr = process_event_synth_attr_stub;
520 if (tool->event_update == NULL)
521 tool->event_update = process_event_synth_event_update_stub;
522 if (tool->tracing_data == NULL)
523 tool->tracing_data = process_event_synth_tracing_data_stub;
524 if (tool->build_id == NULL)
525 tool->build_id = process_event_op2_stub;
526 if (tool->finished_round == NULL) {
527 if (tool->ordered_events)
528 tool->finished_round = process_finished_round;
530 tool->finished_round = process_finished_round_stub;
532 if (tool->id_index == NULL)
533 tool->id_index = process_event_op2_stub;
534 if (tool->auxtrace_info == NULL)
535 tool->auxtrace_info = process_event_op2_stub;
536 if (tool->auxtrace == NULL)
537 tool->auxtrace = process_event_auxtrace_stub;
538 if (tool->auxtrace_error == NULL)
539 tool->auxtrace_error = process_event_op2_stub;
540 if (tool->thread_map == NULL)
541 tool->thread_map = process_event_thread_map_stub;
542 if (tool->cpu_map == NULL)
543 tool->cpu_map = process_event_cpu_map_stub;
544 if (tool->stat_config == NULL)
545 tool->stat_config = process_event_stat_config_stub;
546 if (tool->stat == NULL)
547 tool->stat = process_stat_stub;
548 if (tool->stat_round == NULL)
549 tool->stat_round = process_stat_round_stub;
550 if (tool->time_conv == NULL)
551 tool->time_conv = process_event_time_conv_stub;
552 if (tool->feature == NULL)
553 tool->feature = process_event_op2_stub;
554 if (tool->compressed == NULL)
555 tool->compressed = perf_session__process_compressed_event;
558 static void swap_sample_id_all(union perf_event *event, void *data)
560 void *end = (void *) event + event->header.size;
561 int size = end - data;
563 BUG_ON(size % sizeof(u64));
564 mem_bswap_64(data, size);
567 static void perf_event__all64_swap(union perf_event *event,
568 bool sample_id_all __maybe_unused)
570 struct perf_event_header *hdr = &event->header;
571 mem_bswap_64(hdr + 1, event->header.size - sizeof(*hdr));
574 static void perf_event__comm_swap(union perf_event *event, bool sample_id_all)
576 event->comm.pid = bswap_32(event->comm.pid);
577 event->comm.tid = bswap_32(event->comm.tid);
580 void *data = &event->comm.comm;
582 data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
583 swap_sample_id_all(event, data);
587 static void perf_event__mmap_swap(union perf_event *event,
590 event->mmap.pid = bswap_32(event->mmap.pid);
591 event->mmap.tid = bswap_32(event->mmap.tid);
592 event->mmap.start = bswap_64(event->mmap.start);
593 event->mmap.len = bswap_64(event->mmap.len);
594 event->mmap.pgoff = bswap_64(event->mmap.pgoff);
597 void *data = &event->mmap.filename;
599 data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
600 swap_sample_id_all(event, data);
604 static void perf_event__mmap2_swap(union perf_event *event,
607 event->mmap2.pid = bswap_32(event->mmap2.pid);
608 event->mmap2.tid = bswap_32(event->mmap2.tid);
609 event->mmap2.start = bswap_64(event->mmap2.start);
610 event->mmap2.len = bswap_64(event->mmap2.len);
611 event->mmap2.pgoff = bswap_64(event->mmap2.pgoff);
613 if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) {
614 event->mmap2.maj = bswap_32(event->mmap2.maj);
615 event->mmap2.min = bswap_32(event->mmap2.min);
616 event->mmap2.ino = bswap_64(event->mmap2.ino);
617 event->mmap2.ino_generation = bswap_64(event->mmap2.ino_generation);
621 void *data = &event->mmap2.filename;
623 data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
624 swap_sample_id_all(event, data);
627 static void perf_event__task_swap(union perf_event *event, bool sample_id_all)
629 event->fork.pid = bswap_32(event->fork.pid);
630 event->fork.tid = bswap_32(event->fork.tid);
631 event->fork.ppid = bswap_32(event->fork.ppid);
632 event->fork.ptid = bswap_32(event->fork.ptid);
633 event->fork.time = bswap_64(event->fork.time);
636 swap_sample_id_all(event, &event->fork + 1);
639 static void perf_event__read_swap(union perf_event *event, bool sample_id_all)
641 event->read.pid = bswap_32(event->read.pid);
642 event->read.tid = bswap_32(event->read.tid);
643 event->read.value = bswap_64(event->read.value);
644 event->read.time_enabled = bswap_64(event->read.time_enabled);
645 event->read.time_running = bswap_64(event->read.time_running);
646 event->read.id = bswap_64(event->read.id);
649 swap_sample_id_all(event, &event->read + 1);
652 static void perf_event__aux_swap(union perf_event *event, bool sample_id_all)
654 event->aux.aux_offset = bswap_64(event->aux.aux_offset);
655 event->aux.aux_size = bswap_64(event->aux.aux_size);
656 event->aux.flags = bswap_64(event->aux.flags);
659 swap_sample_id_all(event, &event->aux + 1);
662 static void perf_event__itrace_start_swap(union perf_event *event,
665 event->itrace_start.pid = bswap_32(event->itrace_start.pid);
666 event->itrace_start.tid = bswap_32(event->itrace_start.tid);
669 swap_sample_id_all(event, &event->itrace_start + 1);
672 static void perf_event__switch_swap(union perf_event *event, bool sample_id_all)
674 if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) {
675 event->context_switch.next_prev_pid =
676 bswap_32(event->context_switch.next_prev_pid);
677 event->context_switch.next_prev_tid =
678 bswap_32(event->context_switch.next_prev_tid);
682 swap_sample_id_all(event, &event->context_switch + 1);
685 static void perf_event__text_poke_swap(union perf_event *event, bool sample_id_all)
687 event->text_poke.addr = bswap_64(event->text_poke.addr);
688 event->text_poke.old_len = bswap_16(event->text_poke.old_len);
689 event->text_poke.new_len = bswap_16(event->text_poke.new_len);
692 size_t len = sizeof(event->text_poke.old_len) +
693 sizeof(event->text_poke.new_len) +
694 event->text_poke.old_len +
695 event->text_poke.new_len;
696 void *data = &event->text_poke.old_len;
698 data += PERF_ALIGN(len, sizeof(u64));
699 swap_sample_id_all(event, data);
703 static void perf_event__throttle_swap(union perf_event *event,
706 event->throttle.time = bswap_64(event->throttle.time);
707 event->throttle.id = bswap_64(event->throttle.id);
708 event->throttle.stream_id = bswap_64(event->throttle.stream_id);
711 swap_sample_id_all(event, &event->throttle + 1);
714 static void perf_event__namespaces_swap(union perf_event *event,
719 event->namespaces.pid = bswap_32(event->namespaces.pid);
720 event->namespaces.tid = bswap_32(event->namespaces.tid);
721 event->namespaces.nr_namespaces = bswap_64(event->namespaces.nr_namespaces);
723 for (i = 0; i < event->namespaces.nr_namespaces; i++) {
724 struct perf_ns_link_info *ns = &event->namespaces.link_info[i];
726 ns->dev = bswap_64(ns->dev);
727 ns->ino = bswap_64(ns->ino);
731 swap_sample_id_all(event, &event->namespaces.link_info[i]);
734 static void perf_event__cgroup_swap(union perf_event *event, bool sample_id_all)
736 event->cgroup.id = bswap_64(event->cgroup.id);
739 void *data = &event->cgroup.path;
741 data += PERF_ALIGN(strlen(data) + 1, sizeof(u64));
742 swap_sample_id_all(event, data);
746 static u8 revbyte(u8 b)
748 int rev = (b >> 4) | ((b & 0xf) << 4);
749 rev = ((rev & 0xcc) >> 2) | ((rev & 0x33) << 2);
750 rev = ((rev & 0xaa) >> 1) | ((rev & 0x55) << 1);
755 * XXX this is hack in attempt to carry flags bitfield
756 * through endian village. ABI says:
758 * Bit-fields are allocated from right to left (least to most significant)
759 * on little-endian implementations and from left to right (most to least
760 * significant) on big-endian implementations.
762 * The above seems to be byte specific, so we need to reverse each
763 * byte of the bitfield. 'Internet' also says this might be implementation
764 * specific and we probably need proper fix and carry perf_event_attr
765 * bitfield flags in separate data file FEAT_ section. Thought this seems
768 static void swap_bitfield(u8 *p, unsigned len)
772 for (i = 0; i < len; i++) {
778 /* exported for swapping attributes in file header */
779 void perf_event__attr_swap(struct perf_event_attr *attr)
781 attr->type = bswap_32(attr->type);
782 attr->size = bswap_32(attr->size);
784 #define bswap_safe(f, n) \
785 (attr->size > (offsetof(struct perf_event_attr, f) + \
786 sizeof(attr->f) * (n)))
787 #define bswap_field(f, sz) \
789 if (bswap_safe(f, 0)) \
790 attr->f = bswap_##sz(attr->f); \
792 #define bswap_field_16(f) bswap_field(f, 16)
793 #define bswap_field_32(f) bswap_field(f, 32)
794 #define bswap_field_64(f) bswap_field(f, 64)
796 bswap_field_64(config);
797 bswap_field_64(sample_period);
798 bswap_field_64(sample_type);
799 bswap_field_64(read_format);
800 bswap_field_32(wakeup_events);
801 bswap_field_32(bp_type);
802 bswap_field_64(bp_addr);
803 bswap_field_64(bp_len);
804 bswap_field_64(branch_sample_type);
805 bswap_field_64(sample_regs_user);
806 bswap_field_32(sample_stack_user);
807 bswap_field_32(aux_watermark);
808 bswap_field_16(sample_max_stack);
809 bswap_field_32(aux_sample_size);
812 * After read_format are bitfields. Check read_format because
813 * we are unable to use offsetof on bitfield.
815 if (bswap_safe(read_format, 1))
816 swap_bitfield((u8 *) (&attr->read_format + 1),
818 #undef bswap_field_64
819 #undef bswap_field_32
824 static void perf_event__hdr_attr_swap(union perf_event *event,
825 bool sample_id_all __maybe_unused)
829 perf_event__attr_swap(&event->attr.attr);
831 size = event->header.size;
832 size -= (void *)&event->attr.id - (void *)event;
833 mem_bswap_64(event->attr.id, size);
836 static void perf_event__event_update_swap(union perf_event *event,
837 bool sample_id_all __maybe_unused)
839 event->event_update.type = bswap_64(event->event_update.type);
840 event->event_update.id = bswap_64(event->event_update.id);
843 static void perf_event__event_type_swap(union perf_event *event,
844 bool sample_id_all __maybe_unused)
846 event->event_type.event_type.event_id =
847 bswap_64(event->event_type.event_type.event_id);
850 static void perf_event__tracing_data_swap(union perf_event *event,
851 bool sample_id_all __maybe_unused)
853 event->tracing_data.size = bswap_32(event->tracing_data.size);
856 static void perf_event__auxtrace_info_swap(union perf_event *event,
857 bool sample_id_all __maybe_unused)
861 event->auxtrace_info.type = bswap_32(event->auxtrace_info.type);
863 size = event->header.size;
864 size -= (void *)&event->auxtrace_info.priv - (void *)event;
865 mem_bswap_64(event->auxtrace_info.priv, size);
868 static void perf_event__auxtrace_swap(union perf_event *event,
869 bool sample_id_all __maybe_unused)
871 event->auxtrace.size = bswap_64(event->auxtrace.size);
872 event->auxtrace.offset = bswap_64(event->auxtrace.offset);
873 event->auxtrace.reference = bswap_64(event->auxtrace.reference);
874 event->auxtrace.idx = bswap_32(event->auxtrace.idx);
875 event->auxtrace.tid = bswap_32(event->auxtrace.tid);
876 event->auxtrace.cpu = bswap_32(event->auxtrace.cpu);
879 static void perf_event__auxtrace_error_swap(union perf_event *event,
880 bool sample_id_all __maybe_unused)
882 event->auxtrace_error.type = bswap_32(event->auxtrace_error.type);
883 event->auxtrace_error.code = bswap_32(event->auxtrace_error.code);
884 event->auxtrace_error.cpu = bswap_32(event->auxtrace_error.cpu);
885 event->auxtrace_error.pid = bswap_32(event->auxtrace_error.pid);
886 event->auxtrace_error.tid = bswap_32(event->auxtrace_error.tid);
887 event->auxtrace_error.fmt = bswap_32(event->auxtrace_error.fmt);
888 event->auxtrace_error.ip = bswap_64(event->auxtrace_error.ip);
889 if (event->auxtrace_error.fmt)
890 event->auxtrace_error.time = bswap_64(event->auxtrace_error.time);
893 static void perf_event__thread_map_swap(union perf_event *event,
894 bool sample_id_all __maybe_unused)
898 event->thread_map.nr = bswap_64(event->thread_map.nr);
900 for (i = 0; i < event->thread_map.nr; i++)
901 event->thread_map.entries[i].pid = bswap_64(event->thread_map.entries[i].pid);
904 static void perf_event__cpu_map_swap(union perf_event *event,
905 bool sample_id_all __maybe_unused)
907 struct perf_record_cpu_map_data *data = &event->cpu_map.data;
908 struct cpu_map_entries *cpus;
909 struct perf_record_record_cpu_map *mask;
912 data->type = bswap_16(data->type);
914 switch (data->type) {
915 case PERF_CPU_MAP__CPUS:
916 cpus = (struct cpu_map_entries *)data->data;
918 cpus->nr = bswap_16(cpus->nr);
920 for (i = 0; i < cpus->nr; i++)
921 cpus->cpu[i] = bswap_16(cpus->cpu[i]);
923 case PERF_CPU_MAP__MASK:
924 mask = (struct perf_record_record_cpu_map *)data->data;
926 mask->nr = bswap_16(mask->nr);
927 mask->long_size = bswap_16(mask->long_size);
929 switch (mask->long_size) {
930 case 4: mem_bswap_32(&mask->mask, mask->nr); break;
931 case 8: mem_bswap_64(&mask->mask, mask->nr); break;
933 pr_err("cpu_map swap: unsupported long size\n");
940 static void perf_event__stat_config_swap(union perf_event *event,
941 bool sample_id_all __maybe_unused)
945 size = bswap_64(event->stat_config.nr) * sizeof(event->stat_config.data[0]);
946 size += 1; /* nr item itself */
947 mem_bswap_64(&event->stat_config.nr, size);
950 static void perf_event__stat_swap(union perf_event *event,
951 bool sample_id_all __maybe_unused)
953 event->stat.id = bswap_64(event->stat.id);
954 event->stat.thread = bswap_32(event->stat.thread);
955 event->stat.cpu = bswap_32(event->stat.cpu);
956 event->stat.val = bswap_64(event->stat.val);
957 event->stat.ena = bswap_64(event->stat.ena);
958 event->stat.run = bswap_64(event->stat.run);
961 static void perf_event__stat_round_swap(union perf_event *event,
962 bool sample_id_all __maybe_unused)
964 event->stat_round.type = bswap_64(event->stat_round.type);
965 event->stat_round.time = bswap_64(event->stat_round.time);
968 static void perf_event__time_conv_swap(union perf_event *event,
969 bool sample_id_all __maybe_unused)
971 event->time_conv.time_shift = bswap_64(event->time_conv.time_shift);
972 event->time_conv.time_mult = bswap_64(event->time_conv.time_mult);
973 event->time_conv.time_zero = bswap_64(event->time_conv.time_zero);
975 if (event_contains(event->time_conv, time_cycles)) {
976 event->time_conv.time_cycles = bswap_64(event->time_conv.time_cycles);
977 event->time_conv.time_mask = bswap_64(event->time_conv.time_mask);
981 typedef void (*perf_event__swap_op)(union perf_event *event,
984 static perf_event__swap_op perf_event__swap_ops[] = {
985 [PERF_RECORD_MMAP] = perf_event__mmap_swap,
986 [PERF_RECORD_MMAP2] = perf_event__mmap2_swap,
987 [PERF_RECORD_COMM] = perf_event__comm_swap,
988 [PERF_RECORD_FORK] = perf_event__task_swap,
989 [PERF_RECORD_EXIT] = perf_event__task_swap,
990 [PERF_RECORD_LOST] = perf_event__all64_swap,
991 [PERF_RECORD_READ] = perf_event__read_swap,
992 [PERF_RECORD_THROTTLE] = perf_event__throttle_swap,
993 [PERF_RECORD_UNTHROTTLE] = perf_event__throttle_swap,
994 [PERF_RECORD_SAMPLE] = perf_event__all64_swap,
995 [PERF_RECORD_AUX] = perf_event__aux_swap,
996 [PERF_RECORD_ITRACE_START] = perf_event__itrace_start_swap,
997 [PERF_RECORD_LOST_SAMPLES] = perf_event__all64_swap,
998 [PERF_RECORD_SWITCH] = perf_event__switch_swap,
999 [PERF_RECORD_SWITCH_CPU_WIDE] = perf_event__switch_swap,
1000 [PERF_RECORD_NAMESPACES] = perf_event__namespaces_swap,
1001 [PERF_RECORD_CGROUP] = perf_event__cgroup_swap,
1002 [PERF_RECORD_TEXT_POKE] = perf_event__text_poke_swap,
1003 [PERF_RECORD_HEADER_ATTR] = perf_event__hdr_attr_swap,
1004 [PERF_RECORD_HEADER_EVENT_TYPE] = perf_event__event_type_swap,
1005 [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,
1006 [PERF_RECORD_HEADER_BUILD_ID] = NULL,
1007 [PERF_RECORD_ID_INDEX] = perf_event__all64_swap,
1008 [PERF_RECORD_AUXTRACE_INFO] = perf_event__auxtrace_info_swap,
1009 [PERF_RECORD_AUXTRACE] = perf_event__auxtrace_swap,
1010 [PERF_RECORD_AUXTRACE_ERROR] = perf_event__auxtrace_error_swap,
1011 [PERF_RECORD_THREAD_MAP] = perf_event__thread_map_swap,
1012 [PERF_RECORD_CPU_MAP] = perf_event__cpu_map_swap,
1013 [PERF_RECORD_STAT_CONFIG] = perf_event__stat_config_swap,
1014 [PERF_RECORD_STAT] = perf_event__stat_swap,
1015 [PERF_RECORD_STAT_ROUND] = perf_event__stat_round_swap,
1016 [PERF_RECORD_EVENT_UPDATE] = perf_event__event_update_swap,
1017 [PERF_RECORD_TIME_CONV] = perf_event__time_conv_swap,
1018 [PERF_RECORD_HEADER_MAX] = NULL,
1022 * When perf record finishes a pass on every buffers, it records this pseudo
1024 * We record the max timestamp t found in the pass n.
1025 * Assuming these timestamps are monotonic across cpus, we know that if
1026 * a buffer still has events with timestamps below t, they will be all
1027 * available and then read in the pass n + 1.
1028 * Hence when we start to read the pass n + 2, we can safely flush every
1029 * events with timestamps below t.
1031 * ============ PASS n =================
1034 * cnt1 timestamps | cnt2 timestamps
1037 * - | 4 <--- max recorded
1039 * ============ PASS n + 1 ==============
1042 * cnt1 timestamps | cnt2 timestamps
1045 * 5 | 7 <---- max recorded
1047 * Flush every events below timestamp 4
1049 * ============ PASS n + 2 ==============
1052 * cnt1 timestamps | cnt2 timestamps
1057 * Flush every events below timestamp 7
1060 static int process_finished_round(struct perf_tool *tool __maybe_unused,
1061 union perf_event *event __maybe_unused,
1062 struct ordered_events *oe)
1065 fprintf(stdout, "\n");
1066 return ordered_events__flush(oe, OE_FLUSH__ROUND);
1069 int perf_session__queue_event(struct perf_session *s, union perf_event *event,
1070 u64 timestamp, u64 file_offset)
1072 return ordered_events__queue(&s->ordered_events, event, timestamp, file_offset);
1075 static void callchain__lbr_callstack_printf(struct perf_sample *sample)
1077 struct ip_callchain *callchain = sample->callchain;
1078 struct branch_stack *lbr_stack = sample->branch_stack;
1079 struct branch_entry *entries = perf_sample__branch_entries(sample);
1080 u64 kernel_callchain_nr = callchain->nr;
1083 for (i = 0; i < kernel_callchain_nr; i++) {
1084 if (callchain->ips[i] == PERF_CONTEXT_USER)
1088 if ((i != kernel_callchain_nr) && lbr_stack->nr) {
1091 * LBR callstack can only get user call chain,
1092 * i is kernel call chain number,
1093 * 1 is PERF_CONTEXT_USER.
1095 * The user call chain is stored in LBR registers.
1096 * LBR are pair registers. The caller is stored
1097 * in "from" register, while the callee is stored
1099 * For example, there is a call stack
1100 * "A"->"B"->"C"->"D".
1101 * The LBR registers will be recorded like
1102 * "C"->"D", "B"->"C", "A"->"B".
1103 * So only the first "to" register and all "from"
1104 * registers are needed to construct the whole stack.
1106 total_nr = i + 1 + lbr_stack->nr + 1;
1107 kernel_callchain_nr = i + 1;
1109 printf("... LBR call chain: nr:%" PRIu64 "\n", total_nr);
1111 for (i = 0; i < kernel_callchain_nr; i++)
1112 printf("..... %2d: %016" PRIx64 "\n",
1113 i, callchain->ips[i]);
1115 printf("..... %2d: %016" PRIx64 "\n",
1116 (int)(kernel_callchain_nr), entries[0].to);
1117 for (i = 0; i < lbr_stack->nr; i++)
1118 printf("..... %2d: %016" PRIx64 "\n",
1119 (int)(i + kernel_callchain_nr + 1), entries[i].from);
1123 static void callchain__printf(struct evsel *evsel,
1124 struct perf_sample *sample)
1127 struct ip_callchain *callchain = sample->callchain;
1129 if (evsel__has_branch_callstack(evsel))
1130 callchain__lbr_callstack_printf(sample);
1132 printf("... FP chain: nr:%" PRIu64 "\n", callchain->nr);
1134 for (i = 0; i < callchain->nr; i++)
1135 printf("..... %2d: %016" PRIx64 "\n",
1136 i, callchain->ips[i]);
1139 static void branch_stack__printf(struct perf_sample *sample, bool callstack)
1141 struct branch_entry *entries = perf_sample__branch_entries(sample);
1144 printf("%s: nr:%" PRIu64 "\n",
1145 !callstack ? "... branch stack" : "... branch callstack",
1146 sample->branch_stack->nr);
1148 for (i = 0; i < sample->branch_stack->nr; i++) {
1149 struct branch_entry *e = &entries[i];
1152 printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %s%s%s%s %x\n",
1154 (unsigned short)e->flags.cycles,
1155 e->flags.mispred ? "M" : " ",
1156 e->flags.predicted ? "P" : " ",
1157 e->flags.abort ? "A" : " ",
1158 e->flags.in_tx ? "T" : " ",
1159 (unsigned)e->flags.reserved);
1161 printf("..... %2"PRIu64": %016" PRIx64 "\n",
1162 i, i > 0 ? e->from : e->to);
1167 static void regs_dump__printf(u64 mask, u64 *regs)
1169 unsigned rid, i = 0;
1171 for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
1172 u64 val = regs[i++];
1174 printf(".... %-5s 0x%016" PRIx64 "\n",
1175 perf_reg_name(rid), val);
1179 static const char *regs_abi[] = {
1180 [PERF_SAMPLE_REGS_ABI_NONE] = "none",
1181 [PERF_SAMPLE_REGS_ABI_32] = "32-bit",
1182 [PERF_SAMPLE_REGS_ABI_64] = "64-bit",
1185 static inline const char *regs_dump_abi(struct regs_dump *d)
1187 if (d->abi > PERF_SAMPLE_REGS_ABI_64)
1190 return regs_abi[d->abi];
1193 static void regs__printf(const char *type, struct regs_dump *regs)
1195 u64 mask = regs->mask;
1197 printf("... %s regs: mask 0x%" PRIx64 " ABI %s\n",
1200 regs_dump_abi(regs));
1202 regs_dump__printf(mask, regs->regs);
1205 static void regs_user__printf(struct perf_sample *sample)
1207 struct regs_dump *user_regs = &sample->user_regs;
1209 if (user_regs->regs)
1210 regs__printf("user", user_regs);
1213 static void regs_intr__printf(struct perf_sample *sample)
1215 struct regs_dump *intr_regs = &sample->intr_regs;
1217 if (intr_regs->regs)
1218 regs__printf("intr", intr_regs);
1221 static void stack_user__printf(struct stack_dump *dump)
1223 printf("... ustack: size %" PRIu64 ", offset 0x%x\n",
1224 dump->size, dump->offset);
1227 static void evlist__print_tstamp(struct evlist *evlist, union perf_event *event, struct perf_sample *sample)
1229 u64 sample_type = __evlist__combined_sample_type(evlist);
1231 if (event->header.type != PERF_RECORD_SAMPLE &&
1232 !evlist__sample_id_all(evlist)) {
1233 fputs("-1 -1 ", stdout);
1237 if ((sample_type & PERF_SAMPLE_CPU))
1238 printf("%u ", sample->cpu);
1240 if (sample_type & PERF_SAMPLE_TIME)
1241 printf("%" PRIu64 " ", sample->time);
1244 static void sample_read__printf(struct perf_sample *sample, u64 read_format)
1246 printf("... sample_read:\n");
1248 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
1249 printf("...... time enabled %016" PRIx64 "\n",
1250 sample->read.time_enabled);
1252 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
1253 printf("...... time running %016" PRIx64 "\n",
1254 sample->read.time_running);
1256 if (read_format & PERF_FORMAT_GROUP) {
1259 printf(".... group nr %" PRIu64 "\n", sample->read.group.nr);
1261 for (i = 0; i < sample->read.group.nr; i++) {
1262 struct sample_read_value *value;
1264 value = &sample->read.group.values[i];
1265 printf("..... id %016" PRIx64
1266 ", value %016" PRIx64 "\n",
1267 value->id, value->value);
1270 printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n",
1271 sample->read.one.id, sample->read.one.value);
1274 static void dump_event(struct evlist *evlist, union perf_event *event,
1275 u64 file_offset, struct perf_sample *sample)
1280 printf("\n%#" PRIx64 " [%#x]: event: %d\n",
1281 file_offset, event->header.size, event->header.type);
1284 if (event->header.type == PERF_RECORD_SAMPLE && evlist->trace_event_sample_raw)
1285 evlist->trace_event_sample_raw(evlist, event, sample);
1288 evlist__print_tstamp(evlist, event, sample);
1290 printf("%#" PRIx64 " [%#x]: PERF_RECORD_%s", file_offset,
1291 event->header.size, perf_event__name(event->header.type));
1294 char *get_page_size_name(u64 size, char *str)
1296 if (!size || !unit_number__scnprintf(str, PAGE_SIZE_NAME_LEN, size))
1297 snprintf(str, PAGE_SIZE_NAME_LEN, "%s", "N/A");
1302 static void dump_sample(struct evsel *evsel, union perf_event *event,
1303 struct perf_sample *sample)
1306 char str[PAGE_SIZE_NAME_LEN];
1311 printf("(IP, 0x%x): %d/%d: %#" PRIx64 " period: %" PRIu64 " addr: %#" PRIx64 "\n",
1312 event->header.misc, sample->pid, sample->tid, sample->ip,
1313 sample->period, sample->addr);
1315 sample_type = evsel->core.attr.sample_type;
1317 if (evsel__has_callchain(evsel))
1318 callchain__printf(evsel, sample);
1320 if (evsel__has_br_stack(evsel))
1321 branch_stack__printf(sample, evsel__has_branch_callstack(evsel));
1323 if (sample_type & PERF_SAMPLE_REGS_USER)
1324 regs_user__printf(sample);
1326 if (sample_type & PERF_SAMPLE_REGS_INTR)
1327 regs_intr__printf(sample);
1329 if (sample_type & PERF_SAMPLE_STACK_USER)
1330 stack_user__printf(&sample->user_stack);
1332 if (sample_type & PERF_SAMPLE_WEIGHT_TYPE) {
1333 printf("... weight: %" PRIu64 "", sample->weight);
1334 if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
1335 printf(",0x%"PRIx16"", sample->ins_lat);
1336 printf(",0x%"PRIx16"", sample->p_stage_cyc);
1341 if (sample_type & PERF_SAMPLE_DATA_SRC)
1342 printf(" . data_src: 0x%"PRIx64"\n", sample->data_src);
1344 if (sample_type & PERF_SAMPLE_PHYS_ADDR)
1345 printf(" .. phys_addr: 0x%"PRIx64"\n", sample->phys_addr);
1347 if (sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)
1348 printf(" .. data page size: %s\n", get_page_size_name(sample->data_page_size, str));
1350 if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)
1351 printf(" .. code page size: %s\n", get_page_size_name(sample->code_page_size, str));
1353 if (sample_type & PERF_SAMPLE_TRANSACTION)
1354 printf("... transaction: %" PRIx64 "\n", sample->transaction);
1356 if (sample_type & PERF_SAMPLE_READ)
1357 sample_read__printf(sample, evsel->core.attr.read_format);
1360 static void dump_read(struct evsel *evsel, union perf_event *event)
1362 struct perf_record_read *read_event = &event->read;
1368 printf(": %d %d %s %" PRI_lu64 "\n", event->read.pid, event->read.tid,
1369 evsel__name(evsel), event->read.value);
1374 read_format = evsel->core.attr.read_format;
1376 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
1377 printf("... time enabled : %" PRI_lu64 "\n", read_event->time_enabled);
1379 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
1380 printf("... time running : %" PRI_lu64 "\n", read_event->time_running);
1382 if (read_format & PERF_FORMAT_ID)
1383 printf("... id : %" PRI_lu64 "\n", read_event->id);
1386 static struct machine *machines__find_for_cpumode(struct machines *machines,
1387 union perf_event *event,
1388 struct perf_sample *sample)
1391 ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
1392 (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) {
1395 if (event->header.type == PERF_RECORD_MMAP
1396 || event->header.type == PERF_RECORD_MMAP2)
1397 pid = event->mmap.pid;
1401 return machines__find_guest(machines, pid);
1404 return &machines->host;
1407 static int deliver_sample_value(struct evlist *evlist,
1408 struct perf_tool *tool,
1409 union perf_event *event,
1410 struct perf_sample *sample,
1411 struct sample_read_value *v,
1412 struct machine *machine)
1414 struct perf_sample_id *sid = evlist__id2sid(evlist, v->id);
1415 struct evsel *evsel;
1419 sample->period = v->value - sid->period;
1420 sid->period = v->value;
1423 if (!sid || sid->evsel == NULL) {
1424 ++evlist->stats.nr_unknown_id;
1429 * There's no reason to deliver sample
1430 * for zero period, bail out.
1432 if (!sample->period)
1435 evsel = container_of(sid->evsel, struct evsel, core);
1436 return tool->sample(tool, event, sample, evsel, machine);
1439 static int deliver_sample_group(struct evlist *evlist,
1440 struct perf_tool *tool,
1441 union perf_event *event,
1442 struct perf_sample *sample,
1443 struct machine *machine)
1448 for (i = 0; i < sample->read.group.nr; i++) {
1449 ret = deliver_sample_value(evlist, tool, event, sample,
1450 &sample->read.group.values[i],
1459 static int evlist__deliver_sample(struct evlist *evlist, struct perf_tool *tool,
1460 union perf_event *event, struct perf_sample *sample,
1461 struct evsel *evsel, struct machine *machine)
1463 /* We know evsel != NULL. */
1464 u64 sample_type = evsel->core.attr.sample_type;
1465 u64 read_format = evsel->core.attr.read_format;
1467 /* Standard sample delivery. */
1468 if (!(sample_type & PERF_SAMPLE_READ))
1469 return tool->sample(tool, event, sample, evsel, machine);
1471 /* For PERF_SAMPLE_READ we have either single or group mode. */
1472 if (read_format & PERF_FORMAT_GROUP)
1473 return deliver_sample_group(evlist, tool, event, sample,
1476 return deliver_sample_value(evlist, tool, event, sample,
1477 &sample->read.one, machine);
1480 static int machines__deliver_event(struct machines *machines,
1481 struct evlist *evlist,
1482 union perf_event *event,
1483 struct perf_sample *sample,
1484 struct perf_tool *tool, u64 file_offset)
1486 struct evsel *evsel;
1487 struct machine *machine;
1489 dump_event(evlist, event, file_offset, sample);
1491 evsel = evlist__id2evsel(evlist, sample->id);
1493 machine = machines__find_for_cpumode(machines, event, sample);
1495 switch (event->header.type) {
1496 case PERF_RECORD_SAMPLE:
1497 if (evsel == NULL) {
1498 ++evlist->stats.nr_unknown_id;
1501 dump_sample(evsel, event, sample);
1502 if (machine == NULL) {
1503 ++evlist->stats.nr_unprocessable_samples;
1506 return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
1507 case PERF_RECORD_MMAP:
1508 return tool->mmap(tool, event, sample, machine);
1509 case PERF_RECORD_MMAP2:
1510 if (event->header.misc & PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT)
1511 ++evlist->stats.nr_proc_map_timeout;
1512 return tool->mmap2(tool, event, sample, machine);
1513 case PERF_RECORD_COMM:
1514 return tool->comm(tool, event, sample, machine);
1515 case PERF_RECORD_NAMESPACES:
1516 return tool->namespaces(tool, event, sample, machine);
1517 case PERF_RECORD_CGROUP:
1518 return tool->cgroup(tool, event, sample, machine);
1519 case PERF_RECORD_FORK:
1520 return tool->fork(tool, event, sample, machine);
1521 case PERF_RECORD_EXIT:
1522 return tool->exit(tool, event, sample, machine);
1523 case PERF_RECORD_LOST:
1524 if (tool->lost == perf_event__process_lost)
1525 evlist->stats.total_lost += event->lost.lost;
1526 return tool->lost(tool, event, sample, machine);
1527 case PERF_RECORD_LOST_SAMPLES:
1528 if (tool->lost_samples == perf_event__process_lost_samples)
1529 evlist->stats.total_lost_samples += event->lost_samples.lost;
1530 return tool->lost_samples(tool, event, sample, machine);
1531 case PERF_RECORD_READ:
1532 dump_read(evsel, event);
1533 return tool->read(tool, event, sample, evsel, machine);
1534 case PERF_RECORD_THROTTLE:
1535 return tool->throttle(tool, event, sample, machine);
1536 case PERF_RECORD_UNTHROTTLE:
1537 return tool->unthrottle(tool, event, sample, machine);
1538 case PERF_RECORD_AUX:
1539 if (tool->aux == perf_event__process_aux) {
1540 if (event->aux.flags & PERF_AUX_FLAG_TRUNCATED)
1541 evlist->stats.total_aux_lost += 1;
1542 if (event->aux.flags & PERF_AUX_FLAG_PARTIAL)
1543 evlist->stats.total_aux_partial += 1;
1544 if (event->aux.flags & PERF_AUX_FLAG_COLLISION)
1545 evlist->stats.total_aux_collision += 1;
1547 return tool->aux(tool, event, sample, machine);
1548 case PERF_RECORD_ITRACE_START:
1549 return tool->itrace_start(tool, event, sample, machine);
1550 case PERF_RECORD_SWITCH:
1551 case PERF_RECORD_SWITCH_CPU_WIDE:
1552 return tool->context_switch(tool, event, sample, machine);
1553 case PERF_RECORD_KSYMBOL:
1554 return tool->ksymbol(tool, event, sample, machine);
1555 case PERF_RECORD_BPF_EVENT:
1556 return tool->bpf(tool, event, sample, machine);
1557 case PERF_RECORD_TEXT_POKE:
1558 return tool->text_poke(tool, event, sample, machine);
1560 ++evlist->stats.nr_unknown_events;
1565 static int perf_session__deliver_event(struct perf_session *session,
1566 union perf_event *event,
1567 struct perf_tool *tool,
1570 struct perf_sample sample;
1571 int ret = evlist__parse_sample(session->evlist, event, &sample);
1574 pr_err("Can't parse sample, err = %d\n", ret);
1578 ret = auxtrace__process_event(session, event, &sample, tool);
1584 ret = machines__deliver_event(&session->machines, session->evlist,
1585 event, &sample, tool, file_offset);
1587 if (dump_trace && sample.aux_sample.size)
1588 auxtrace__dump_auxtrace_sample(session, &sample);
1593 static s64 perf_session__process_user_event(struct perf_session *session,
1594 union perf_event *event,
1597 struct ordered_events *oe = &session->ordered_events;
1598 struct perf_tool *tool = session->tool;
1599 struct perf_sample sample = { .time = 0, };
1600 int fd = perf_data__fd(session->data);
1603 if (event->header.type != PERF_RECORD_COMPRESSED ||
1604 tool->compressed == perf_session__process_compressed_event_stub)
1605 dump_event(session->evlist, event, file_offset, &sample);
1607 /* These events are processed right away */
1608 switch (event->header.type) {
1609 case PERF_RECORD_HEADER_ATTR:
1610 err = tool->attr(tool, event, &session->evlist);
1612 perf_session__set_id_hdr_size(session);
1613 perf_session__set_comm_exec(session);
1616 case PERF_RECORD_EVENT_UPDATE:
1617 return tool->event_update(tool, event, &session->evlist);
1618 case PERF_RECORD_HEADER_EVENT_TYPE:
1620 * Deprecated, but we need to handle it for sake
1621 * of old data files create in pipe mode.
1624 case PERF_RECORD_HEADER_TRACING_DATA:
1626 * Setup for reading amidst mmap, but only when we
1627 * are in 'file' mode. The 'pipe' fd is in proper
1630 if (!perf_data__is_pipe(session->data))
1631 lseek(fd, file_offset, SEEK_SET);
1632 return tool->tracing_data(session, event);
1633 case PERF_RECORD_HEADER_BUILD_ID:
1634 return tool->build_id(session, event);
1635 case PERF_RECORD_FINISHED_ROUND:
1636 return tool->finished_round(tool, event, oe);
1637 case PERF_RECORD_ID_INDEX:
1638 return tool->id_index(session, event);
1639 case PERF_RECORD_AUXTRACE_INFO:
1640 return tool->auxtrace_info(session, event);
1641 case PERF_RECORD_AUXTRACE:
1642 /* setup for reading amidst mmap */
1643 lseek(fd, file_offset + event->header.size, SEEK_SET);
1644 return tool->auxtrace(session, event);
1645 case PERF_RECORD_AUXTRACE_ERROR:
1646 perf_session__auxtrace_error_inc(session, event);
1647 return tool->auxtrace_error(session, event);
1648 case PERF_RECORD_THREAD_MAP:
1649 return tool->thread_map(session, event);
1650 case PERF_RECORD_CPU_MAP:
1651 return tool->cpu_map(session, event);
1652 case PERF_RECORD_STAT_CONFIG:
1653 return tool->stat_config(session, event);
1654 case PERF_RECORD_STAT:
1655 return tool->stat(session, event);
1656 case PERF_RECORD_STAT_ROUND:
1657 return tool->stat_round(session, event);
1658 case PERF_RECORD_TIME_CONV:
1659 session->time_conv = event->time_conv;
1660 return tool->time_conv(session, event);
1661 case PERF_RECORD_HEADER_FEATURE:
1662 return tool->feature(session, event);
1663 case PERF_RECORD_COMPRESSED:
1664 err = tool->compressed(session, event, file_offset);
1666 dump_event(session->evlist, event, file_offset, &sample);
1673 int perf_session__deliver_synth_event(struct perf_session *session,
1674 union perf_event *event,
1675 struct perf_sample *sample)
1677 struct evlist *evlist = session->evlist;
1678 struct perf_tool *tool = session->tool;
1680 events_stats__inc(&evlist->stats, event->header.type);
1682 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
1683 return perf_session__process_user_event(session, event, 0);
1685 return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0);
1688 static void event_swap(union perf_event *event, bool sample_id_all)
1690 perf_event__swap_op swap;
1692 swap = perf_event__swap_ops[event->header.type];
1694 swap(event, sample_id_all);
1697 int perf_session__peek_event(struct perf_session *session, off_t file_offset,
1698 void *buf, size_t buf_sz,
1699 union perf_event **event_ptr,
1700 struct perf_sample *sample)
1702 union perf_event *event;
1703 size_t hdr_sz, rest;
1706 if (session->one_mmap && !session->header.needs_swap) {
1707 event = file_offset - session->one_mmap_offset +
1708 session->one_mmap_addr;
1709 goto out_parse_sample;
1712 if (perf_data__is_pipe(session->data))
1715 fd = perf_data__fd(session->data);
1716 hdr_sz = sizeof(struct perf_event_header);
1718 if (buf_sz < hdr_sz)
1721 if (lseek(fd, file_offset, SEEK_SET) == (off_t)-1 ||
1722 readn(fd, buf, hdr_sz) != (ssize_t)hdr_sz)
1725 event = (union perf_event *)buf;
1727 if (session->header.needs_swap)
1728 perf_event_header__bswap(&event->header);
1730 if (event->header.size < hdr_sz || event->header.size > buf_sz)
1734 rest = event->header.size - hdr_sz;
1736 if (readn(fd, buf, rest) != (ssize_t)rest)
1739 if (session->header.needs_swap)
1740 event_swap(event, evlist__sample_id_all(session->evlist));
1744 if (sample && event->header.type < PERF_RECORD_USER_TYPE_START &&
1745 evlist__parse_sample(session->evlist, event, sample))
1753 int perf_session__peek_events(struct perf_session *session, u64 offset,
1754 u64 size, peek_events_cb_t cb, void *data)
1756 u64 max_offset = offset + size;
1757 char buf[PERF_SAMPLE_MAX_SIZE];
1758 union perf_event *event;
1762 err = perf_session__peek_event(session, offset, buf,
1763 PERF_SAMPLE_MAX_SIZE, &event,
1768 err = cb(session, event, offset, data);
1772 offset += event->header.size;
1773 if (event->header.type == PERF_RECORD_AUXTRACE)
1774 offset += event->auxtrace.size;
1776 } while (offset < max_offset);
1781 static s64 perf_session__process_event(struct perf_session *session,
1782 union perf_event *event, u64 file_offset)
1784 struct evlist *evlist = session->evlist;
1785 struct perf_tool *tool = session->tool;
1788 if (session->header.needs_swap)
1789 event_swap(event, evlist__sample_id_all(evlist));
1791 if (event->header.type >= PERF_RECORD_HEADER_MAX)
1794 events_stats__inc(&evlist->stats, event->header.type);
1796 if (event->header.type >= PERF_RECORD_USER_TYPE_START)
1797 return perf_session__process_user_event(session, event, file_offset);
1799 if (tool->ordered_events) {
1800 u64 timestamp = -1ULL;
1802 ret = evlist__parse_sample_timestamp(evlist, event, ×tamp);
1803 if (ret && ret != -1)
1806 ret = perf_session__queue_event(session, event, timestamp, file_offset);
1811 return perf_session__deliver_event(session, event, tool, file_offset);
1814 void perf_event_header__bswap(struct perf_event_header *hdr)
1816 hdr->type = bswap_32(hdr->type);
1817 hdr->misc = bswap_16(hdr->misc);
1818 hdr->size = bswap_16(hdr->size);
1821 struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
1823 return machine__findnew_thread(&session->machines.host, -1, pid);
1826 int perf_session__register_idle_thread(struct perf_session *session)
1828 struct thread *thread = machine__idle_thread(&session->machines.host);
1830 /* machine__idle_thread() got the thread, so put it */
1831 thread__put(thread);
1832 return thread ? 0 : -1;
1836 perf_session__warn_order(const struct perf_session *session)
1838 const struct ordered_events *oe = &session->ordered_events;
1839 struct evsel *evsel;
1840 bool should_warn = true;
1842 evlist__for_each_entry(session->evlist, evsel) {
1843 if (evsel->core.attr.write_backward)
1844 should_warn = false;
1849 if (oe->nr_unordered_events != 0)
1850 ui__warning("%u out of order events recorded.\n", oe->nr_unordered_events);
1853 static void perf_session__warn_about_errors(const struct perf_session *session)
1855 const struct events_stats *stats = &session->evlist->stats;
1857 if (session->tool->lost == perf_event__process_lost &&
1858 stats->nr_events[PERF_RECORD_LOST] != 0) {
1859 ui__warning("Processed %d events and lost %d chunks!\n\n"
1860 "Check IO/CPU overload!\n\n",
1861 stats->nr_events[0],
1862 stats->nr_events[PERF_RECORD_LOST]);
1865 if (session->tool->lost_samples == perf_event__process_lost_samples) {
1868 drop_rate = (double)stats->total_lost_samples /
1869 (double) (stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples);
1870 if (drop_rate > 0.05) {
1871 ui__warning("Processed %" PRIu64 " samples and lost %3.2f%%!\n\n",
1872 stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples,
1877 if (session->tool->aux == perf_event__process_aux &&
1878 stats->total_aux_lost != 0) {
1879 ui__warning("AUX data lost %" PRIu64 " times out of %u!\n\n",
1880 stats->total_aux_lost,
1881 stats->nr_events[PERF_RECORD_AUX]);
1884 if (session->tool->aux == perf_event__process_aux &&
1885 stats->total_aux_partial != 0) {
1886 bool vmm_exclusive = false;
1888 (void)sysfs__read_bool("module/kvm_intel/parameters/vmm_exclusive",
1891 ui__warning("AUX data had gaps in it %" PRIu64 " times out of %u!\n\n"
1892 "Are you running a KVM guest in the background?%s\n\n",
1893 stats->total_aux_partial,
1894 stats->nr_events[PERF_RECORD_AUX],
1896 "\nReloading kvm_intel module with vmm_exclusive=0\n"
1897 "will reduce the gaps to only guest's timeslices." :
1901 if (session->tool->aux == perf_event__process_aux &&
1902 stats->total_aux_collision != 0) {
1903 ui__warning("AUX data detected collision %" PRIu64 " times out of %u!\n\n",
1904 stats->total_aux_collision,
1905 stats->nr_events[PERF_RECORD_AUX]);
1908 if (stats->nr_unknown_events != 0) {
1909 ui__warning("Found %u unknown events!\n\n"
1910 "Is this an older tool processing a perf.data "
1911 "file generated by a more recent tool?\n\n"
1912 "If that is not the case, consider "
1913 "reporting to linux-kernel@vger.kernel.org.\n\n",
1914 stats->nr_unknown_events);
1917 if (stats->nr_unknown_id != 0) {
1918 ui__warning("%u samples with id not present in the header\n",
1919 stats->nr_unknown_id);
1922 if (stats->nr_invalid_chains != 0) {
1923 ui__warning("Found invalid callchains!\n\n"
1924 "%u out of %u events were discarded for this reason.\n\n"
1925 "Consider reporting to linux-kernel@vger.kernel.org.\n\n",
1926 stats->nr_invalid_chains,
1927 stats->nr_events[PERF_RECORD_SAMPLE]);
1930 if (stats->nr_unprocessable_samples != 0) {
1931 ui__warning("%u unprocessable samples recorded.\n"
1932 "Do you have a KVM guest running and not using 'perf kvm'?\n",
1933 stats->nr_unprocessable_samples);
1936 perf_session__warn_order(session);
1938 events_stats__auxtrace_error_warn(stats);
1940 if (stats->nr_proc_map_timeout != 0) {
1941 ui__warning("%d map information files for pre-existing threads were\n"
1942 "not processed, if there are samples for addresses they\n"
1943 "will not be resolved, you may find out which are these\n"
1944 "threads by running with -v and redirecting the output\n"
1946 "The time limit to process proc map is too short?\n"
1947 "Increase it by --proc-map-timeout\n",
1948 stats->nr_proc_map_timeout);
1952 static int perf_session__flush_thread_stack(struct thread *thread,
1953 void *p __maybe_unused)
1955 return thread_stack__flush(thread);
1958 static int perf_session__flush_thread_stacks(struct perf_session *session)
1960 return machines__for_each_thread(&session->machines,
1961 perf_session__flush_thread_stack,
1965 volatile int session_done;
1967 static int __perf_session__process_decomp_events(struct perf_session *session);
1969 static int __perf_session__process_pipe_events(struct perf_session *session)
1971 struct ordered_events *oe = &session->ordered_events;
1972 struct perf_tool *tool = session->tool;
1973 union perf_event *event;
1974 uint32_t size, cur_size = 0;
1981 perf_tool__fill_defaults(tool);
1984 cur_size = sizeof(union perf_event);
1986 buf = malloc(cur_size);
1989 ordered_events__set_copy_on_queue(oe, true);
1992 err = perf_data__read(session->data, event,
1993 sizeof(struct perf_event_header));
1998 pr_err("failed to read event header\n");
2002 if (session->header.needs_swap)
2003 perf_event_header__bswap(&event->header);
2005 size = event->header.size;
2006 if (size < sizeof(struct perf_event_header)) {
2007 pr_err("bad event header size\n");
2011 if (size > cur_size) {
2012 void *new = realloc(buf, size);
2014 pr_err("failed to allocate memory to read event\n");
2022 p += sizeof(struct perf_event_header);
2024 if (size - sizeof(struct perf_event_header)) {
2025 err = perf_data__read(session->data, p,
2026 size - sizeof(struct perf_event_header));
2029 pr_err("unexpected end of event stream\n");
2033 pr_err("failed to read event data\n");
2038 if ((skip = perf_session__process_event(session, event, head)) < 0) {
2039 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
2040 head, event->header.size, event->header.type);
2050 err = __perf_session__process_decomp_events(session);
2054 if (!session_done())
2057 /* do the final flush for ordered samples */
2058 err = ordered_events__flush(oe, OE_FLUSH__FINAL);
2061 err = auxtrace__flush_events(session, tool);
2064 err = perf_session__flush_thread_stacks(session);
2068 perf_session__warn_about_errors(session);
2069 ordered_events__free(&session->ordered_events);
2070 auxtrace__free_events(session);
2074 static union perf_event *
2075 prefetch_event(char *buf, u64 head, size_t mmap_size,
2076 bool needs_swap, union perf_event *error)
2078 union perf_event *event;
2081 * Ensure we have enough space remaining to read
2082 * the size of the event in the headers.
2084 if (head + sizeof(event->header) > mmap_size)
2087 event = (union perf_event *)(buf + head);
2089 perf_event_header__bswap(&event->header);
2091 if (head + event->header.size <= mmap_size)
2094 /* We're not fetching the event so swap back again */
2096 perf_event_header__bswap(&event->header);
2098 pr_debug("%s: head=%#" PRIx64 " event->header_size=%#x, mmap_size=%#zx:"
2099 " fuzzed or compressed perf.data?\n",__func__, head, event->header.size, mmap_size);
2104 static union perf_event *
2105 fetch_mmaped_event(u64 head, size_t mmap_size, char *buf, bool needs_swap)
2107 return prefetch_event(buf, head, mmap_size, needs_swap, ERR_PTR(-EINVAL));
2110 static union perf_event *
2111 fetch_decomp_event(u64 head, size_t mmap_size, char *buf, bool needs_swap)
2113 return prefetch_event(buf, head, mmap_size, needs_swap, NULL);
2116 static int __perf_session__process_decomp_events(struct perf_session *session)
2120 struct decomp *decomp = session->decomp_last;
2125 while (decomp->head < decomp->size && !session_done()) {
2126 union perf_event *event = fetch_decomp_event(decomp->head, decomp->size, decomp->data,
2127 session->header.needs_swap);
2132 size = event->header.size;
2134 if (size < sizeof(struct perf_event_header) ||
2135 (skip = perf_session__process_event(session, event, decomp->file_pos)) < 0) {
2136 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
2137 decomp->file_pos + decomp->head, event->header.size, event->header.type);
2144 decomp->head += size;
2151 * On 64bit we can mmap the data file in one go. No need for tiny mmap
2152 * slices. On 32bit we use 32MB.
2154 #if BITS_PER_LONG == 64
2155 #define MMAP_SIZE ULLONG_MAX
2158 #define MMAP_SIZE (32 * 1024 * 1024ULL)
2159 #define NUM_MMAPS 128
2164 typedef s64 (*reader_cb_t)(struct perf_session *session,
2165 union perf_event *event,
2172 reader_cb_t process;
2173 bool in_place_update;
2177 reader__process_events(struct reader *rd, struct perf_session *session,
2178 struct ui_progress *prog)
2180 u64 data_size = rd->data_size;
2181 u64 head, page_offset, file_offset, file_pos, size;
2182 int err = 0, mmap_prot, mmap_flags, map_idx = 0;
2184 char *buf, *mmaps[NUM_MMAPS];
2185 union perf_event *event;
2188 page_offset = page_size * (rd->data_offset / page_size);
2189 file_offset = page_offset;
2190 head = rd->data_offset - page_offset;
2192 ui_progress__init_size(prog, data_size, "Processing events...");
2194 data_size += rd->data_offset;
2196 mmap_size = MMAP_SIZE;
2197 if (mmap_size > data_size) {
2198 mmap_size = data_size;
2199 session->one_mmap = true;
2202 memset(mmaps, 0, sizeof(mmaps));
2204 mmap_prot = PROT_READ;
2205 mmap_flags = MAP_SHARED;
2207 if (rd->in_place_update) {
2208 mmap_prot |= PROT_WRITE;
2209 } else if (session->header.needs_swap) {
2210 mmap_prot |= PROT_WRITE;
2211 mmap_flags = MAP_PRIVATE;
2214 buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, rd->fd,
2216 if (buf == MAP_FAILED) {
2217 pr_err("failed to mmap file\n");
2221 mmaps[map_idx] = buf;
2222 map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1);
2223 file_pos = file_offset + head;
2224 if (session->one_mmap) {
2225 session->one_mmap_addr = buf;
2226 session->one_mmap_offset = file_offset;
2230 event = fetch_mmaped_event(head, mmap_size, buf, session->header.needs_swap);
2232 return PTR_ERR(event);
2235 if (mmaps[map_idx]) {
2236 munmap(mmaps[map_idx], mmap_size);
2237 mmaps[map_idx] = NULL;
2240 page_offset = page_size * (head / page_size);
2241 file_offset += page_offset;
2242 head -= page_offset;
2246 size = event->header.size;
2250 if (size < sizeof(struct perf_event_header) ||
2251 (skip = rd->process(session, event, file_pos)) < 0) {
2252 pr_err("%#" PRIx64 " [%#x]: failed to process type: %d [%s]\n",
2253 file_offset + head, event->header.size,
2254 event->header.type, strerror(-skip));
2265 err = __perf_session__process_decomp_events(session);
2269 ui_progress__update(prog, size);
2274 if (file_pos < data_size)
2281 static s64 process_simple(struct perf_session *session,
2282 union perf_event *event,
2285 return perf_session__process_event(session, event, file_offset);
2288 static int __perf_session__process_events(struct perf_session *session)
2290 struct reader rd = {
2291 .fd = perf_data__fd(session->data),
2292 .data_size = session->header.data_size,
2293 .data_offset = session->header.data_offset,
2294 .process = process_simple,
2295 .in_place_update = session->data->in_place_update,
2297 struct ordered_events *oe = &session->ordered_events;
2298 struct perf_tool *tool = session->tool;
2299 struct ui_progress prog;
2302 perf_tool__fill_defaults(tool);
2304 if (rd.data_size == 0)
2307 ui_progress__init_size(&prog, rd.data_size, "Processing events...");
2309 err = reader__process_events(&rd, session, &prog);
2312 /* do the final flush for ordered samples */
2313 err = ordered_events__flush(oe, OE_FLUSH__FINAL);
2316 err = auxtrace__flush_events(session, tool);
2319 err = perf_session__flush_thread_stacks(session);
2321 ui_progress__finish();
2323 perf_session__warn_about_errors(session);
2325 * We may switching perf.data output, make ordered_events
2328 ordered_events__reinit(&session->ordered_events);
2329 auxtrace__free_events(session);
2330 session->one_mmap = false;
2334 int perf_session__process_events(struct perf_session *session)
2336 if (perf_session__register_idle_thread(session) < 0)
2339 if (perf_data__is_pipe(session->data))
2340 return __perf_session__process_pipe_events(session);
2342 return __perf_session__process_events(session);
2345 bool perf_session__has_traces(struct perf_session *session, const char *msg)
2347 struct evsel *evsel;
2349 evlist__for_each_entry(session->evlist, evsel) {
2350 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT)
2354 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
2358 int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u64 addr)
2361 struct ref_reloc_sym *ref;
2364 ref = zalloc(sizeof(struct ref_reloc_sym));
2368 ref->name = strdup(symbol_name);
2369 if (ref->name == NULL) {
2374 bracket = strchr(ref->name, ']');
2380 kmap = map__kmap(map);
2382 kmap->ref_reloc_sym = ref;
2387 size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp)
2389 return machines__fprintf_dsos(&session->machines, fp);
2392 size_t perf_session__fprintf_dsos_buildid(struct perf_session *session, FILE *fp,
2393 bool (skip)(struct dso *dso, int parm), int parm)
2395 return machines__fprintf_dsos_buildid(&session->machines, fp, skip, parm);
2398 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp,
2402 const char *msg = "";
2404 if (perf_header__has_feat(&session->header, HEADER_AUXTRACE))
2405 msg = " (excludes AUX area (e.g. instruction trace) decoded / synthesized events)";
2407 ret = fprintf(fp, "\nAggregated stats:%s\n", msg);
2409 ret += events_stats__fprintf(&session->evlist->stats, fp, skip_empty);
2413 size_t perf_session__fprintf(struct perf_session *session, FILE *fp)
2416 * FIXME: Here we have to actually print all the machines in this
2417 * session, not just the host...
2419 return machine__fprintf(&session->machines.host, fp);
2422 struct evsel *perf_session__find_first_evtype(struct perf_session *session,
2427 evlist__for_each_entry(session->evlist, pos) {
2428 if (pos->core.attr.type == type)
2434 int perf_session__cpu_bitmap(struct perf_session *session,
2435 const char *cpu_list, unsigned long *cpu_bitmap)
2438 struct perf_cpu_map *map;
2439 int nr_cpus = min(session->header.env.nr_cpus_avail, MAX_NR_CPUS);
2441 for (i = 0; i < PERF_TYPE_MAX; ++i) {
2442 struct evsel *evsel;
2444 evsel = perf_session__find_first_evtype(session, i);
2448 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_CPU)) {
2449 pr_err("File does not contain CPU events. "
2450 "Remove -C option to proceed.\n");
2455 map = perf_cpu_map__new(cpu_list);
2457 pr_err("Invalid cpu_list\n");
2461 for (i = 0; i < map->nr; i++) {
2462 int cpu = map->map[i];
2464 if (cpu >= nr_cpus) {
2465 pr_err("Requested CPU %d too large. "
2466 "Consider raising MAX_NR_CPUS\n", cpu);
2467 goto out_delete_map;
2470 set_bit(cpu, cpu_bitmap);
2476 perf_cpu_map__put(map);
2480 void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
2483 if (session == NULL || fp == NULL)
2486 fprintf(fp, "# ========\n");
2487 perf_header__fprintf_info(session, fp, full);
2488 fprintf(fp, "# ========\n#\n");
2491 int perf_event__process_id_index(struct perf_session *session,
2492 union perf_event *event)
2494 struct evlist *evlist = session->evlist;
2495 struct perf_record_id_index *ie = &event->id_index;
2496 size_t i, nr, max_nr;
2498 max_nr = (ie->header.size - sizeof(struct perf_record_id_index)) /
2499 sizeof(struct id_index_entry);
2505 fprintf(stdout, " nr: %zu\n", nr);
2507 for (i = 0; i < nr; i++) {
2508 struct id_index_entry *e = &ie->entries[i];
2509 struct perf_sample_id *sid;
2512 fprintf(stdout, " ... id: %"PRI_lu64, e->id);
2513 fprintf(stdout, " idx: %"PRI_lu64, e->idx);
2514 fprintf(stdout, " cpu: %"PRI_ld64, e->cpu);
2515 fprintf(stdout, " tid: %"PRI_ld64"\n", e->tid);
2518 sid = evlist__id2sid(evlist, e->id);