1 #include <linux/types.h>
11 #include "thread_map.h"
12 #include "symbol/kallsyms.h"
14 static const char *perf_event__names[] = {
16 [PERF_RECORD_MMAP] = "MMAP",
17 [PERF_RECORD_MMAP2] = "MMAP2",
18 [PERF_RECORD_LOST] = "LOST",
19 [PERF_RECORD_COMM] = "COMM",
20 [PERF_RECORD_EXIT] = "EXIT",
21 [PERF_RECORD_THROTTLE] = "THROTTLE",
22 [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE",
23 [PERF_RECORD_FORK] = "FORK",
24 [PERF_RECORD_READ] = "READ",
25 [PERF_RECORD_SAMPLE] = "SAMPLE",
26 [PERF_RECORD_AUX] = "AUX",
27 [PERF_RECORD_ITRACE_START] = "ITRACE_START",
28 [PERF_RECORD_HEADER_ATTR] = "ATTR",
29 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
30 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
31 [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID",
32 [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND",
33 [PERF_RECORD_ID_INDEX] = "ID_INDEX",
34 [PERF_RECORD_AUXTRACE_INFO] = "AUXTRACE_INFO",
35 [PERF_RECORD_AUXTRACE] = "AUXTRACE",
36 [PERF_RECORD_AUXTRACE_ERROR] = "AUXTRACE_ERROR",
39 const char *perf_event__name(unsigned int id)
41 if (id >= ARRAY_SIZE(perf_event__names))
43 if (!perf_event__names[id])
45 return perf_event__names[id];
48 static struct perf_sample synth_sample = {
58 * Assumes that the first 4095 bytes of /proc/pid/stat contains
59 * the comm, tgid and ppid.
61 static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
62 pid_t *tgid, pid_t *ppid)
64 char filename[PATH_MAX];
68 char *nl, *name, *tgids, *ppids;
73 snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
75 fd = open(filename, O_RDONLY);
77 pr_debug("couldn't open %s\n", filename);
81 n = read(fd, bf, sizeof(bf) - 1);
84 pr_warning("Couldn't get COMM, tigd and ppid for pid %d\n",
90 name = strstr(bf, "Name:");
91 tgids = strstr(bf, "Tgid:");
92 ppids = strstr(bf, "PPid:");
95 name += 5; /* strlen("Name:") */
97 while (*name && isspace(*name))
100 nl = strchr(name, '\n');
107 memcpy(comm, name, size);
110 pr_debug("Name: string not found for pid %d\n", pid);
114 tgids += 5; /* strlen("Tgid:") */
117 pr_debug("Tgid: string not found for pid %d\n", pid);
121 ppids += 5; /* strlen("PPid:") */
124 pr_debug("PPid: string not found for pid %d\n", pid);
130 static int perf_event__prepare_comm(union perf_event *event, pid_t pid,
131 struct machine *machine,
132 pid_t *tgid, pid_t *ppid)
138 memset(&event->comm, 0, sizeof(event->comm));
140 if (machine__is_host(machine)) {
141 if (perf_event__get_comm_ids(pid, event->comm.comm,
142 sizeof(event->comm.comm),
147 *tgid = machine->pid;
153 event->comm.pid = *tgid;
154 event->comm.header.type = PERF_RECORD_COMM;
156 size = strlen(event->comm.comm) + 1;
157 size = PERF_ALIGN(size, sizeof(u64));
158 memset(event->comm.comm + size, 0, machine->id_hdr_size);
159 event->comm.header.size = (sizeof(event->comm) -
160 (sizeof(event->comm.comm) - size) +
161 machine->id_hdr_size);
162 event->comm.tid = pid;
167 static pid_t perf_event__synthesize_comm(struct perf_tool *tool,
168 union perf_event *event, pid_t pid,
169 perf_event__handler_t process,
170 struct machine *machine)
174 if (perf_event__prepare_comm(event, pid, machine, &tgid, &ppid) != 0)
177 if (process(tool, event, &synth_sample, machine) != 0)
183 static int perf_event__synthesize_fork(struct perf_tool *tool,
184 union perf_event *event,
185 pid_t pid, pid_t tgid, pid_t ppid,
186 perf_event__handler_t process,
187 struct machine *machine)
189 memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
192 * for main thread set parent to ppid from status file. For other
193 * threads set parent pid to main thread. ie., assume main thread
194 * spawns all threads in a process
197 event->fork.ppid = ppid;
198 event->fork.ptid = ppid;
200 event->fork.ppid = tgid;
201 event->fork.ptid = tgid;
203 event->fork.pid = tgid;
204 event->fork.tid = pid;
205 event->fork.header.type = PERF_RECORD_FORK;
207 event->fork.header.size = (sizeof(event->fork) + machine->id_hdr_size);
209 if (process(tool, event, &synth_sample, machine) != 0)
215 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
216 union perf_event *event,
217 pid_t pid, pid_t tgid,
218 perf_event__handler_t process,
219 struct machine *machine,
222 char filename[PATH_MAX];
226 if (machine__is_default_guest(machine))
229 snprintf(filename, sizeof(filename), "%s/proc/%d/maps",
230 machine->root_dir, pid);
232 fp = fopen(filename, "r");
235 * We raced with a task exiting - just return:
237 pr_debug("couldn't open %s\n", filename);
241 event->header.type = PERF_RECORD_MMAP2;
246 char execname[PATH_MAX];
247 char anonstr[] = "//anon";
252 if (fgets(bf, sizeof(bf), fp) == NULL)
255 /* ensure null termination since stack will be reused. */
256 strcpy(execname, "");
258 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
259 n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %x:%x %u %s\n",
260 &event->mmap2.start, &event->mmap2.len, prot,
261 &event->mmap2.pgoff, &event->mmap2.maj,
266 * Anon maps don't have the execname.
271 event->mmap2.ino = (u64)ino;
274 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
276 if (machine__is_host(machine))
277 event->header.misc = PERF_RECORD_MISC_USER;
279 event->header.misc = PERF_RECORD_MISC_GUEST_USER;
281 /* map protection and flags bits */
282 event->mmap2.prot = 0;
283 event->mmap2.flags = 0;
285 event->mmap2.prot |= PROT_READ;
287 event->mmap2.prot |= PROT_WRITE;
289 event->mmap2.prot |= PROT_EXEC;
292 event->mmap2.flags |= MAP_SHARED;
294 event->mmap2.flags |= MAP_PRIVATE;
296 if (prot[2] != 'x') {
297 if (!mmap_data || prot[0] != 'r')
300 event->header.misc |= PERF_RECORD_MISC_MMAP_DATA;
303 if (!strcmp(execname, ""))
304 strcpy(execname, anonstr);
306 size = strlen(execname) + 1;
307 memcpy(event->mmap2.filename, execname, size);
308 size = PERF_ALIGN(size, sizeof(u64));
309 event->mmap2.len -= event->mmap.start;
310 event->mmap2.header.size = (sizeof(event->mmap2) -
311 (sizeof(event->mmap2.filename) - size));
312 memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
313 event->mmap2.header.size += machine->id_hdr_size;
314 event->mmap2.pid = tgid;
315 event->mmap2.tid = pid;
317 if (process(tool, event, &synth_sample, machine) != 0) {
327 int perf_event__synthesize_modules(struct perf_tool *tool,
328 perf_event__handler_t process,
329 struct machine *machine)
333 struct map_groups *kmaps = &machine->kmaps;
334 union perf_event *event = zalloc((sizeof(event->mmap) +
335 machine->id_hdr_size));
337 pr_debug("Not enough memory synthesizing mmap event "
338 "for kernel modules\n");
342 event->header.type = PERF_RECORD_MMAP;
345 * kernel uses 0 for user space maps, see kernel/perf_event.c
348 if (machine__is_host(machine))
349 event->header.misc = PERF_RECORD_MISC_KERNEL;
351 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
353 for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]);
354 nd; nd = rb_next(nd)) {
356 struct map *pos = rb_entry(nd, struct map, rb_node);
358 if (pos->dso->kernel)
361 size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
362 event->mmap.header.type = PERF_RECORD_MMAP;
363 event->mmap.header.size = (sizeof(event->mmap) -
364 (sizeof(event->mmap.filename) - size));
365 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
366 event->mmap.header.size += machine->id_hdr_size;
367 event->mmap.start = pos->start;
368 event->mmap.len = pos->end - pos->start;
369 event->mmap.pid = machine->pid;
371 memcpy(event->mmap.filename, pos->dso->long_name,
372 pos->dso->long_name_len + 1);
373 if (process(tool, event, &synth_sample, machine) != 0) {
383 static int __event__synthesize_thread(union perf_event *comm_event,
384 union perf_event *mmap_event,
385 union perf_event *fork_event,
387 perf_event__handler_t process,
388 struct perf_tool *tool,
389 struct machine *machine, bool mmap_data)
391 char filename[PATH_MAX];
393 struct dirent dirent, *next;
397 /* special case: only send one comm event using passed in pid */
399 tgid = perf_event__synthesize_comm(tool, comm_event, pid,
405 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
406 process, machine, mmap_data);
409 if (machine__is_default_guest(machine))
412 snprintf(filename, sizeof(filename), "%s/proc/%d/task",
413 machine->root_dir, pid);
415 tasks = opendir(filename);
417 pr_debug("couldn't open %s\n", filename);
421 while (!readdir_r(tasks, &dirent, &next) && next) {
425 _pid = strtol(dirent.d_name, &end, 10);
430 if (perf_event__prepare_comm(comm_event, _pid, machine,
434 if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
435 ppid, process, machine) < 0)
438 * Send the prepared comm event
440 if (process(tool, comm_event, &synth_sample, machine) != 0)
445 /* process the parent's maps too */
446 rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
447 process, machine, mmap_data);
457 int perf_event__synthesize_thread_map(struct perf_tool *tool,
458 struct thread_map *threads,
459 perf_event__handler_t process,
460 struct machine *machine,
463 union perf_event *comm_event, *mmap_event, *fork_event;
464 int err = -1, thread, j;
466 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
467 if (comm_event == NULL)
470 mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
471 if (mmap_event == NULL)
474 fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
475 if (fork_event == NULL)
479 for (thread = 0; thread < threads->nr; ++thread) {
480 if (__event__synthesize_thread(comm_event, mmap_event,
482 threads->map[thread], 0,
483 process, tool, machine,
490 * comm.pid is set to thread group id by
491 * perf_event__synthesize_comm
493 if ((int) comm_event->comm.pid != threads->map[thread]) {
494 bool need_leader = true;
496 /* is thread group leader in thread_map? */
497 for (j = 0; j < threads->nr; ++j) {
498 if ((int) comm_event->comm.pid == threads->map[j]) {
504 /* if not, generate events for it */
506 __event__synthesize_thread(comm_event, mmap_event,
508 comm_event->comm.pid, 0,
509 process, tool, machine,
525 int perf_event__synthesize_threads(struct perf_tool *tool,
526 perf_event__handler_t process,
527 struct machine *machine, bool mmap_data)
530 char proc_path[PATH_MAX];
531 struct dirent dirent, *next;
532 union perf_event *comm_event, *mmap_event, *fork_event;
535 if (machine__is_default_guest(machine))
538 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
539 if (comm_event == NULL)
542 mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
543 if (mmap_event == NULL)
546 fork_event = malloc(sizeof(fork_event->fork) + machine->id_hdr_size);
547 if (fork_event == NULL)
550 snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir);
551 proc = opendir(proc_path);
556 while (!readdir_r(proc, &dirent, &next) && next) {
558 pid_t pid = strtol(dirent.d_name, &end, 10);
560 if (*end) /* only interested in proper numerical dirents */
563 * We may race with exiting thread, so don't stop just because
564 * one thread couldn't be synthesized.
566 __event__synthesize_thread(comm_event, mmap_event, fork_event, pid,
567 1, process, tool, machine, mmap_data);
582 struct process_symbol_args {
587 static int find_symbol_cb(void *arg, const char *name, char type,
590 struct process_symbol_args *args = arg;
593 * Must be a function or at least an alias, as in PARISC64, where "_text" is
594 * an 'A' to the same address as "_stext".
596 if (!(symbol_type__is_a(type, MAP__FUNCTION) ||
597 type == 'A') || strcmp(name, args->name))
604 u64 kallsyms__get_function_start(const char *kallsyms_filename,
605 const char *symbol_name)
607 struct process_symbol_args args = { .name = symbol_name, };
609 if (kallsyms__parse(kallsyms_filename, &args, find_symbol_cb) <= 0)
615 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
616 perf_event__handler_t process,
617 struct machine *machine)
620 const char *mmap_name;
621 char name_buff[PATH_MAX];
625 union perf_event *event;
627 if (machine->vmlinux_maps[0] == NULL)
631 * We should get this from /sys/kernel/sections/.text, but till that is
632 * available use this, and after it is use this as a fallback for older
635 event = zalloc((sizeof(event->mmap) + machine->id_hdr_size));
637 pr_debug("Not enough memory synthesizing mmap event "
638 "for kernel modules\n");
642 mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
643 if (machine__is_host(machine)) {
645 * kernel uses PERF_RECORD_MISC_USER for user space maps,
646 * see kernel/perf_event.c __perf_event_mmap
648 event->header.misc = PERF_RECORD_MISC_KERNEL;
650 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
653 map = machine->vmlinux_maps[MAP__FUNCTION];
654 kmap = map__kmap(map);
655 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
656 "%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1;
657 size = PERF_ALIGN(size, sizeof(u64));
658 event->mmap.header.type = PERF_RECORD_MMAP;
659 event->mmap.header.size = (sizeof(event->mmap) -
660 (sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
661 event->mmap.pgoff = kmap->ref_reloc_sym->addr;
662 event->mmap.start = map->start;
663 event->mmap.len = map->end - event->mmap.start;
664 event->mmap.pid = machine->pid;
666 err = process(tool, event, &synth_sample, machine);
672 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
676 if (event->header.misc & PERF_RECORD_MISC_COMM_EXEC)
681 return fprintf(fp, "%s: %s:%d/%d\n", s, event->comm.comm, event->comm.pid, event->comm.tid);
684 int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
685 union perf_event *event,
686 struct perf_sample *sample,
687 struct machine *machine)
689 return machine__process_comm_event(machine, event, sample);
692 int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
693 union perf_event *event,
694 struct perf_sample *sample,
695 struct machine *machine)
697 return machine__process_lost_event(machine, event, sample);
700 int perf_event__process_aux(struct perf_tool *tool __maybe_unused,
701 union perf_event *event,
702 struct perf_sample *sample __maybe_unused,
703 struct machine *machine)
705 return machine__process_aux_event(machine, event);
708 int perf_event__process_itrace_start(struct perf_tool *tool __maybe_unused,
709 union perf_event *event,
710 struct perf_sample *sample __maybe_unused,
711 struct machine *machine)
713 return machine__process_itrace_start_event(machine, event);
716 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
718 return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n",
719 event->mmap.pid, event->mmap.tid, event->mmap.start,
720 event->mmap.len, event->mmap.pgoff,
721 (event->header.misc & PERF_RECORD_MISC_MMAP_DATA) ? 'r' : 'x',
722 event->mmap.filename);
725 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)
727 return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64
728 " %02x:%02x %"PRIu64" %"PRIu64"]: %c%c%c%c %s\n",
729 event->mmap2.pid, event->mmap2.tid, event->mmap2.start,
730 event->mmap2.len, event->mmap2.pgoff, event->mmap2.maj,
731 event->mmap2.min, event->mmap2.ino,
732 event->mmap2.ino_generation,
733 (event->mmap2.prot & PROT_READ) ? 'r' : '-',
734 (event->mmap2.prot & PROT_WRITE) ? 'w' : '-',
735 (event->mmap2.prot & PROT_EXEC) ? 'x' : '-',
736 (event->mmap2.flags & MAP_SHARED) ? 's' : 'p',
737 event->mmap2.filename);
740 int perf_event__process_mmap(struct perf_tool *tool __maybe_unused,
741 union perf_event *event,
742 struct perf_sample *sample,
743 struct machine *machine)
745 return machine__process_mmap_event(machine, event, sample);
748 int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused,
749 union perf_event *event,
750 struct perf_sample *sample,
751 struct machine *machine)
753 return machine__process_mmap2_event(machine, event, sample);
756 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp)
758 return fprintf(fp, "(%d:%d):(%d:%d)\n",
759 event->fork.pid, event->fork.tid,
760 event->fork.ppid, event->fork.ptid);
763 int perf_event__process_fork(struct perf_tool *tool __maybe_unused,
764 union perf_event *event,
765 struct perf_sample *sample,
766 struct machine *machine)
768 return machine__process_fork_event(machine, event, sample);
771 int perf_event__process_exit(struct perf_tool *tool __maybe_unused,
772 union perf_event *event,
773 struct perf_sample *sample,
774 struct machine *machine)
776 return machine__process_exit_event(machine, event, sample);
779 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp)
781 return fprintf(fp, " offset: %#"PRIx64" size: %#"PRIx64" flags: %#"PRIx64" [%s%s]\n",
782 event->aux.aux_offset, event->aux.aux_size,
784 event->aux.flags & PERF_AUX_FLAG_TRUNCATED ? "T" : "",
785 event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : "");
788 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp)
790 return fprintf(fp, " pid: %u tid: %u\n",
791 event->itrace_start.pid, event->itrace_start.tid);
794 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
796 size_t ret = fprintf(fp, "PERF_RECORD_%s",
797 perf_event__name(event->header.type));
799 switch (event->header.type) {
800 case PERF_RECORD_COMM:
801 ret += perf_event__fprintf_comm(event, fp);
803 case PERF_RECORD_FORK:
804 case PERF_RECORD_EXIT:
805 ret += perf_event__fprintf_task(event, fp);
807 case PERF_RECORD_MMAP:
808 ret += perf_event__fprintf_mmap(event, fp);
810 case PERF_RECORD_MMAP2:
811 ret += perf_event__fprintf_mmap2(event, fp);
813 case PERF_RECORD_AUX:
814 ret += perf_event__fprintf_aux(event, fp);
816 case PERF_RECORD_ITRACE_START:
817 ret += perf_event__fprintf_itrace_start(event, fp);
820 ret += fprintf(fp, "\n");
826 int perf_event__process(struct perf_tool *tool __maybe_unused,
827 union perf_event *event,
828 struct perf_sample *sample,
829 struct machine *machine)
831 return machine__process_event(machine, event, sample);
834 void thread__find_addr_map(struct thread *thread, u8 cpumode,
835 enum map_type type, u64 addr,
836 struct addr_location *al)
838 struct map_groups *mg = thread->mg;
839 struct machine *machine = mg->machine;
840 bool load_map = false;
842 al->machine = machine;
845 al->cpumode = cpumode;
848 if (machine == NULL) {
853 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
855 mg = &machine->kmaps;
857 } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
859 } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
861 mg = &machine->kmaps;
863 } else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
869 if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
870 cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
872 al->filtered |= (1 << HIST_FILTER__GUEST);
873 if ((cpumode == PERF_RECORD_MISC_USER ||
874 cpumode == PERF_RECORD_MISC_KERNEL) &&
876 al->filtered |= (1 << HIST_FILTER__HOST);
881 al->map = map_groups__find(mg, type, al->addr);
882 if (al->map == NULL) {
884 * If this is outside of all known maps, and is a negative
885 * address, try to look it up in the kernel dso, as it might be
886 * a vsyscall or vdso (which executes in user-mode).
888 * XXX This is nasty, we should have a symbol list in the
889 * "[vdso]" dso, but for now lets use the old trick of looking
890 * in the whole kernel symbol list.
892 if (cpumode == PERF_RECORD_MISC_USER && machine &&
893 mg != &machine->kmaps &&
894 machine__kernel_ip(machine, al->addr)) {
895 mg = &machine->kmaps;
901 * Kernel maps might be changed when loading symbols so loading
902 * must be done prior to using kernel maps.
905 map__load(al->map, machine->symbol_filter);
906 al->addr = al->map->map_ip(al->map, al->addr);
910 void thread__find_addr_location(struct thread *thread,
911 u8 cpumode, enum map_type type, u64 addr,
912 struct addr_location *al)
914 thread__find_addr_map(thread, cpumode, type, addr, al);
916 al->sym = map__find_symbol(al->map, al->addr,
917 thread->mg->machine->symbol_filter);
923 * Callers need to drop the reference to al->thread, obtained in
924 * machine__findnew_thread()
926 int perf_event__preprocess_sample(const union perf_event *event,
927 struct machine *machine,
928 struct addr_location *al,
929 struct perf_sample *sample)
931 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
932 struct thread *thread = machine__findnew_thread(machine, sample->pid,
938 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
940 * Have we already created the kernel maps for this machine?
942 * This should have happened earlier, when we processed the kernel MMAP
943 * events, but for older perf.data files there was no such thing, so do
946 if (cpumode == PERF_RECORD_MISC_KERNEL &&
947 machine->vmlinux_maps[MAP__FUNCTION] == NULL)
948 machine__create_kernel_maps(machine);
950 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al);
951 dump_printf(" ...... dso: %s\n",
952 al->map ? al->map->dso->long_name :
953 al->level == 'H' ? "[hypervisor]" : "<not found>");
955 if (thread__is_filtered(thread))
956 al->filtered |= (1 << HIST_FILTER__THREAD);
959 al->cpu = sample->cpu;
962 struct dso *dso = al->map->dso;
964 if (symbol_conf.dso_list &&
965 (!dso || !(strlist__has_entry(symbol_conf.dso_list,
967 (dso->short_name != dso->long_name &&
968 strlist__has_entry(symbol_conf.dso_list,
969 dso->long_name))))) {
970 al->filtered |= (1 << HIST_FILTER__DSO);
973 al->sym = map__find_symbol(al->map, al->addr,
974 machine->symbol_filter);
977 if (symbol_conf.sym_list &&
978 (!al->sym || !strlist__has_entry(symbol_conf.sym_list,
980 al->filtered |= (1 << HIST_FILTER__SYMBOL);
987 * The preprocess_sample method will return with reference counts for the
988 * in it, when done using (and perhaps getting ref counts if needing to
989 * keep a pointer to one of those entries) it must be paired with
990 * addr_location__put(), so that the refcounts can be decremented.
992 void addr_location__put(struct addr_location *al)
994 thread__zput(al->thread);
997 bool is_bts_event(struct perf_event_attr *attr)
999 return attr->type == PERF_TYPE_HARDWARE &&
1000 (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
1001 attr->sample_period == 1;
1004 bool sample_addr_correlates_sym(struct perf_event_attr *attr)
1006 if (attr->type == PERF_TYPE_SOFTWARE &&
1007 (attr->config == PERF_COUNT_SW_PAGE_FAULTS ||
1008 attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN ||
1009 attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ))
1012 if (is_bts_event(attr))
1018 void perf_event__preprocess_sample_addr(union perf_event *event,
1019 struct perf_sample *sample,
1020 struct thread *thread,
1021 struct addr_location *al)
1023 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1025 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
1027 thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
1030 al->cpu = sample->cpu;
1034 al->sym = map__find_symbol(al->map, al->addr, NULL);