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_HEADER_ATTR
] = "ATTR",
27 [PERF_RECORD_HEADER_EVENT_TYPE
] = "EVENT_TYPE",
28 [PERF_RECORD_HEADER_TRACING_DATA
] = "TRACING_DATA",
29 [PERF_RECORD_HEADER_BUILD_ID
] = "BUILD_ID",
30 [PERF_RECORD_FINISHED_ROUND
] = "FINISHED_ROUND",
31 [PERF_RECORD_ID_INDEX
] = "ID_INDEX",
34 const char *perf_event__name(unsigned int id
)
36 if (id
>= ARRAY_SIZE(perf_event__names
))
38 if (!perf_event__names
[id
])
40 return perf_event__names
[id
];
43 static struct perf_sample synth_sample
= {
53 * Assumes that the first 4095 bytes of /proc/pid/stat contains
54 * the comm, tgid and ppid.
56 static int perf_event__get_comm_ids(pid_t pid
, char *comm
, size_t len
,
57 pid_t
*tgid
, pid_t
*ppid
)
59 char filename
[PATH_MAX
];
63 char *nl
, *name
, *tgids
, *ppids
;
68 snprintf(filename
, sizeof(filename
), "/proc/%d/status", pid
);
70 fd
= open(filename
, O_RDONLY
);
72 pr_debug("couldn't open %s\n", filename
);
76 n
= read(fd
, bf
, sizeof(bf
) - 1);
79 pr_warning("Couldn't get COMM, tigd and ppid for pid %d\n",
85 name
= strstr(bf
, "Name:");
86 tgids
= strstr(bf
, "Tgid:");
87 ppids
= strstr(bf
, "PPid:");
90 name
+= 5; /* strlen("Name:") */
92 while (*name
&& isspace(*name
))
95 nl
= strchr(name
, '\n');
102 memcpy(comm
, name
, size
);
105 pr_debug("Name: string not found for pid %d\n", pid
);
109 tgids
+= 5; /* strlen("Tgid:") */
112 pr_debug("Tgid: string not found for pid %d\n", pid
);
116 ppids
+= 5; /* strlen("PPid:") */
119 pr_debug("PPid: string not found for pid %d\n", pid
);
125 static int perf_event__prepare_comm(union perf_event
*event
, pid_t pid
,
126 struct machine
*machine
,
127 pid_t
*tgid
, pid_t
*ppid
)
133 memset(&event
->comm
, 0, sizeof(event
->comm
));
135 if (machine__is_host(machine
)) {
136 if (perf_event__get_comm_ids(pid
, event
->comm
.comm
,
137 sizeof(event
->comm
.comm
),
142 *tgid
= machine
->pid
;
148 event
->comm
.pid
= *tgid
;
149 event
->comm
.header
.type
= PERF_RECORD_COMM
;
151 size
= strlen(event
->comm
.comm
) + 1;
152 size
= PERF_ALIGN(size
, sizeof(u64
));
153 memset(event
->comm
.comm
+ size
, 0, machine
->id_hdr_size
);
154 event
->comm
.header
.size
= (sizeof(event
->comm
) -
155 (sizeof(event
->comm
.comm
) - size
) +
156 machine
->id_hdr_size
);
157 event
->comm
.tid
= pid
;
162 static pid_t
perf_event__synthesize_comm(struct perf_tool
*tool
,
163 union perf_event
*event
, pid_t pid
,
164 perf_event__handler_t process
,
165 struct machine
*machine
)
169 if (perf_event__prepare_comm(event
, pid
, machine
, &tgid
, &ppid
) != 0)
172 if (process(tool
, event
, &synth_sample
, machine
) != 0)
178 static int perf_event__synthesize_fork(struct perf_tool
*tool
,
179 union perf_event
*event
,
180 pid_t pid
, pid_t tgid
, pid_t ppid
,
181 perf_event__handler_t process
,
182 struct machine
*machine
)
184 memset(&event
->fork
, 0, sizeof(event
->fork
) + machine
->id_hdr_size
);
187 * for main thread set parent to ppid from status file. For other
188 * threads set parent pid to main thread. ie., assume main thread
189 * spawns all threads in a process
192 event
->fork
.ppid
= ppid
;
193 event
->fork
.ptid
= ppid
;
195 event
->fork
.ppid
= tgid
;
196 event
->fork
.ptid
= tgid
;
198 event
->fork
.pid
= tgid
;
199 event
->fork
.tid
= pid
;
200 event
->fork
.header
.type
= PERF_RECORD_FORK
;
202 event
->fork
.header
.size
= (sizeof(event
->fork
) + machine
->id_hdr_size
);
204 if (process(tool
, event
, &synth_sample
, machine
) != 0)
210 int perf_event__synthesize_mmap_events(struct perf_tool
*tool
,
211 union perf_event
*event
,
212 pid_t pid
, pid_t tgid
,
213 perf_event__handler_t process
,
214 struct machine
*machine
,
217 char filename
[PATH_MAX
];
221 if (machine__is_default_guest(machine
))
224 snprintf(filename
, sizeof(filename
), "%s/proc/%d/maps",
225 machine
->root_dir
, pid
);
227 fp
= fopen(filename
, "r");
230 * We raced with a task exiting - just return:
232 pr_debug("couldn't open %s\n", filename
);
236 event
->header
.type
= PERF_RECORD_MMAP2
;
241 char execname
[PATH_MAX
];
242 char anonstr
[] = "//anon";
247 if (fgets(bf
, sizeof(bf
), fp
) == NULL
)
250 /* ensure null termination since stack will be reused. */
251 strcpy(execname
, "");
253 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
254 n
= sscanf(bf
, "%"PRIx64
"-%"PRIx64
" %s %"PRIx64
" %x:%x %u %s\n",
255 &event
->mmap2
.start
, &event
->mmap2
.len
, prot
,
256 &event
->mmap2
.pgoff
, &event
->mmap2
.maj
,
261 * Anon maps don't have the execname.
266 event
->mmap2
.ino
= (u64
)ino
;
269 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
271 if (machine__is_host(machine
))
272 event
->header
.misc
= PERF_RECORD_MISC_USER
;
274 event
->header
.misc
= PERF_RECORD_MISC_GUEST_USER
;
276 /* map protection and flags bits */
277 event
->mmap2
.prot
= 0;
278 event
->mmap2
.flags
= 0;
280 event
->mmap2
.prot
|= PROT_READ
;
282 event
->mmap2
.prot
|= PROT_WRITE
;
284 event
->mmap2
.prot
|= PROT_EXEC
;
287 event
->mmap2
.flags
|= MAP_SHARED
;
289 event
->mmap2
.flags
|= MAP_PRIVATE
;
291 if (prot
[2] != 'x') {
292 if (!mmap_data
|| prot
[0] != 'r')
295 event
->header
.misc
|= PERF_RECORD_MISC_MMAP_DATA
;
298 if (!strcmp(execname
, ""))
299 strcpy(execname
, anonstr
);
301 size
= strlen(execname
) + 1;
302 memcpy(event
->mmap2
.filename
, execname
, size
);
303 size
= PERF_ALIGN(size
, sizeof(u64
));
304 event
->mmap2
.len
-= event
->mmap
.start
;
305 event
->mmap2
.header
.size
= (sizeof(event
->mmap2
) -
306 (sizeof(event
->mmap2
.filename
) - size
));
307 memset(event
->mmap2
.filename
+ size
, 0, machine
->id_hdr_size
);
308 event
->mmap2
.header
.size
+= machine
->id_hdr_size
;
309 event
->mmap2
.pid
= tgid
;
310 event
->mmap2
.tid
= pid
;
312 if (process(tool
, event
, &synth_sample
, machine
) != 0) {
322 int perf_event__synthesize_modules(struct perf_tool
*tool
,
323 perf_event__handler_t process
,
324 struct machine
*machine
)
328 struct map_groups
*kmaps
= &machine
->kmaps
;
329 union perf_event
*event
= zalloc((sizeof(event
->mmap
) +
330 machine
->id_hdr_size
));
332 pr_debug("Not enough memory synthesizing mmap event "
333 "for kernel modules\n");
337 event
->header
.type
= PERF_RECORD_MMAP
;
340 * kernel uses 0 for user space maps, see kernel/perf_event.c
343 if (machine__is_host(machine
))
344 event
->header
.misc
= PERF_RECORD_MISC_KERNEL
;
346 event
->header
.misc
= PERF_RECORD_MISC_GUEST_KERNEL
;
348 for (nd
= rb_first(&kmaps
->maps
[MAP__FUNCTION
]);
349 nd
; nd
= rb_next(nd
)) {
351 struct map
*pos
= rb_entry(nd
, struct map
, rb_node
);
353 if (pos
->dso
->kernel
)
356 size
= PERF_ALIGN(pos
->dso
->long_name_len
+ 1, sizeof(u64
));
357 event
->mmap
.header
.type
= PERF_RECORD_MMAP
;
358 event
->mmap
.header
.size
= (sizeof(event
->mmap
) -
359 (sizeof(event
->mmap
.filename
) - size
));
360 memset(event
->mmap
.filename
+ size
, 0, machine
->id_hdr_size
);
361 event
->mmap
.header
.size
+= machine
->id_hdr_size
;
362 event
->mmap
.start
= pos
->start
;
363 event
->mmap
.len
= pos
->end
- pos
->start
;
364 event
->mmap
.pid
= machine
->pid
;
366 memcpy(event
->mmap
.filename
, pos
->dso
->long_name
,
367 pos
->dso
->long_name_len
+ 1);
368 if (process(tool
, event
, &synth_sample
, machine
) != 0) {
378 static int __event__synthesize_thread(union perf_event
*comm_event
,
379 union perf_event
*mmap_event
,
380 union perf_event
*fork_event
,
382 perf_event__handler_t process
,
383 struct perf_tool
*tool
,
384 struct machine
*machine
, bool mmap_data
)
386 char filename
[PATH_MAX
];
388 struct dirent dirent
, *next
;
392 /* special case: only send one comm event using passed in pid */
394 tgid
= perf_event__synthesize_comm(tool
, comm_event
, pid
,
400 return perf_event__synthesize_mmap_events(tool
, mmap_event
, pid
, tgid
,
401 process
, machine
, mmap_data
);
404 if (machine__is_default_guest(machine
))
407 snprintf(filename
, sizeof(filename
), "%s/proc/%d/task",
408 machine
->root_dir
, pid
);
410 tasks
= opendir(filename
);
412 pr_debug("couldn't open %s\n", filename
);
416 while (!readdir_r(tasks
, &dirent
, &next
) && next
) {
420 _pid
= strtol(dirent
.d_name
, &end
, 10);
425 if (perf_event__prepare_comm(comm_event
, _pid
, machine
,
429 if (perf_event__synthesize_fork(tool
, fork_event
, _pid
, tgid
,
430 ppid
, process
, machine
) < 0)
433 * Send the prepared comm event
435 if (process(tool
, comm_event
, &synth_sample
, machine
) != 0)
440 /* process the parent's maps too */
441 rc
= perf_event__synthesize_mmap_events(tool
, mmap_event
, pid
, tgid
,
442 process
, machine
, mmap_data
);
452 int perf_event__synthesize_thread_map(struct perf_tool
*tool
,
453 struct thread_map
*threads
,
454 perf_event__handler_t process
,
455 struct machine
*machine
,
458 union perf_event
*comm_event
, *mmap_event
, *fork_event
;
459 int err
= -1, thread
, j
;
461 comm_event
= malloc(sizeof(comm_event
->comm
) + machine
->id_hdr_size
);
462 if (comm_event
== NULL
)
465 mmap_event
= malloc(sizeof(mmap_event
->mmap
) + machine
->id_hdr_size
);
466 if (mmap_event
== NULL
)
469 fork_event
= malloc(sizeof(fork_event
->fork
) + machine
->id_hdr_size
);
470 if (fork_event
== NULL
)
474 for (thread
= 0; thread
< threads
->nr
; ++thread
) {
475 if (__event__synthesize_thread(comm_event
, mmap_event
,
477 threads
->map
[thread
], 0,
478 process
, tool
, machine
,
485 * comm.pid is set to thread group id by
486 * perf_event__synthesize_comm
488 if ((int) comm_event
->comm
.pid
!= threads
->map
[thread
]) {
489 bool need_leader
= true;
491 /* is thread group leader in thread_map? */
492 for (j
= 0; j
< threads
->nr
; ++j
) {
493 if ((int) comm_event
->comm
.pid
== threads
->map
[j
]) {
499 /* if not, generate events for it */
501 __event__synthesize_thread(comm_event
, mmap_event
,
503 comm_event
->comm
.pid
, 0,
504 process
, tool
, machine
,
520 int perf_event__synthesize_threads(struct perf_tool
*tool
,
521 perf_event__handler_t process
,
522 struct machine
*machine
, bool mmap_data
)
525 char proc_path
[PATH_MAX
];
526 struct dirent dirent
, *next
;
527 union perf_event
*comm_event
, *mmap_event
, *fork_event
;
530 if (machine__is_default_guest(machine
))
533 comm_event
= malloc(sizeof(comm_event
->comm
) + machine
->id_hdr_size
);
534 if (comm_event
== NULL
)
537 mmap_event
= malloc(sizeof(mmap_event
->mmap
) + machine
->id_hdr_size
);
538 if (mmap_event
== NULL
)
541 fork_event
= malloc(sizeof(fork_event
->fork
) + machine
->id_hdr_size
);
542 if (fork_event
== NULL
)
545 snprintf(proc_path
, sizeof(proc_path
), "%s/proc", machine
->root_dir
);
546 proc
= opendir(proc_path
);
551 while (!readdir_r(proc
, &dirent
, &next
) && next
) {
553 pid_t pid
= strtol(dirent
.d_name
, &end
, 10);
555 if (*end
) /* only interested in proper numerical dirents */
558 * We may race with exiting thread, so don't stop just because
559 * one thread couldn't be synthesized.
561 __event__synthesize_thread(comm_event
, mmap_event
, fork_event
, pid
,
562 1, process
, tool
, machine
, mmap_data
);
577 struct process_symbol_args
{
582 static int find_symbol_cb(void *arg
, const char *name
, char type
,
585 struct process_symbol_args
*args
= arg
;
588 * Must be a function or at least an alias, as in PARISC64, where "_text" is
589 * an 'A' to the same address as "_stext".
591 if (!(symbol_type__is_a(type
, MAP__FUNCTION
) ||
592 type
== 'A') || strcmp(name
, args
->name
))
599 u64
kallsyms__get_function_start(const char *kallsyms_filename
,
600 const char *symbol_name
)
602 struct process_symbol_args args
= { .name
= symbol_name
, };
604 if (kallsyms__parse(kallsyms_filename
, &args
, find_symbol_cb
) <= 0)
610 int perf_event__synthesize_kernel_mmap(struct perf_tool
*tool
,
611 perf_event__handler_t process
,
612 struct machine
*machine
)
615 const char *mmap_name
;
616 char name_buff
[PATH_MAX
];
620 union perf_event
*event
;
622 if (machine
->vmlinux_maps
[0] == NULL
)
626 * We should get this from /sys/kernel/sections/.text, but till that is
627 * available use this, and after it is use this as a fallback for older
630 event
= zalloc((sizeof(event
->mmap
) + machine
->id_hdr_size
));
632 pr_debug("Not enough memory synthesizing mmap event "
633 "for kernel modules\n");
637 mmap_name
= machine__mmap_name(machine
, name_buff
, sizeof(name_buff
));
638 if (machine__is_host(machine
)) {
640 * kernel uses PERF_RECORD_MISC_USER for user space maps,
641 * see kernel/perf_event.c __perf_event_mmap
643 event
->header
.misc
= PERF_RECORD_MISC_KERNEL
;
645 event
->header
.misc
= PERF_RECORD_MISC_GUEST_KERNEL
;
648 map
= machine
->vmlinux_maps
[MAP__FUNCTION
];
649 kmap
= map__kmap(map
);
650 size
= snprintf(event
->mmap
.filename
, sizeof(event
->mmap
.filename
),
651 "%s%s", mmap_name
, kmap
->ref_reloc_sym
->name
) + 1;
652 size
= PERF_ALIGN(size
, sizeof(u64
));
653 event
->mmap
.header
.type
= PERF_RECORD_MMAP
;
654 event
->mmap
.header
.size
= (sizeof(event
->mmap
) -
655 (sizeof(event
->mmap
.filename
) - size
) + machine
->id_hdr_size
);
656 event
->mmap
.pgoff
= kmap
->ref_reloc_sym
->addr
;
657 event
->mmap
.start
= map
->start
;
658 event
->mmap
.len
= map
->end
- event
->mmap
.start
;
659 event
->mmap
.pid
= machine
->pid
;
661 err
= process(tool
, event
, &synth_sample
, machine
);
667 size_t perf_event__fprintf_comm(union perf_event
*event
, FILE *fp
)
671 if (event
->header
.misc
& PERF_RECORD_MISC_COMM_EXEC
)
676 return fprintf(fp
, "%s: %s:%d/%d\n", s
, event
->comm
.comm
, event
->comm
.pid
, event
->comm
.tid
);
679 int perf_event__process_comm(struct perf_tool
*tool __maybe_unused
,
680 union perf_event
*event
,
681 struct perf_sample
*sample
,
682 struct machine
*machine
)
684 return machine__process_comm_event(machine
, event
, sample
);
687 int perf_event__process_lost(struct perf_tool
*tool __maybe_unused
,
688 union perf_event
*event
,
689 struct perf_sample
*sample
,
690 struct machine
*machine
)
692 return machine__process_lost_event(machine
, event
, sample
);
695 size_t perf_event__fprintf_mmap(union perf_event
*event
, FILE *fp
)
697 return fprintf(fp
, " %d/%d: [%#" PRIx64
"(%#" PRIx64
") @ %#" PRIx64
"]: %c %s\n",
698 event
->mmap
.pid
, event
->mmap
.tid
, event
->mmap
.start
,
699 event
->mmap
.len
, event
->mmap
.pgoff
,
700 (event
->header
.misc
& PERF_RECORD_MISC_MMAP_DATA
) ? 'r' : 'x',
701 event
->mmap
.filename
);
704 size_t perf_event__fprintf_mmap2(union perf_event
*event
, FILE *fp
)
706 return fprintf(fp
, " %d/%d: [%#" PRIx64
"(%#" PRIx64
") @ %#" PRIx64
707 " %02x:%02x %"PRIu64
" %"PRIu64
"]: %c%c%c%c %s\n",
708 event
->mmap2
.pid
, event
->mmap2
.tid
, event
->mmap2
.start
,
709 event
->mmap2
.len
, event
->mmap2
.pgoff
, event
->mmap2
.maj
,
710 event
->mmap2
.min
, event
->mmap2
.ino
,
711 event
->mmap2
.ino_generation
,
712 (event
->mmap2
.prot
& PROT_READ
) ? 'r' : '-',
713 (event
->mmap2
.prot
& PROT_WRITE
) ? 'w' : '-',
714 (event
->mmap2
.prot
& PROT_EXEC
) ? 'x' : '-',
715 (event
->mmap2
.flags
& MAP_SHARED
) ? 's' : 'p',
716 event
->mmap2
.filename
);
719 int perf_event__process_mmap(struct perf_tool
*tool __maybe_unused
,
720 union perf_event
*event
,
721 struct perf_sample
*sample
,
722 struct machine
*machine
)
724 return machine__process_mmap_event(machine
, event
, sample
);
727 int perf_event__process_mmap2(struct perf_tool
*tool __maybe_unused
,
728 union perf_event
*event
,
729 struct perf_sample
*sample
,
730 struct machine
*machine
)
732 return machine__process_mmap2_event(machine
, event
, sample
);
735 size_t perf_event__fprintf_task(union perf_event
*event
, FILE *fp
)
737 return fprintf(fp
, "(%d:%d):(%d:%d)\n",
738 event
->fork
.pid
, event
->fork
.tid
,
739 event
->fork
.ppid
, event
->fork
.ptid
);
742 int perf_event__process_fork(struct perf_tool
*tool __maybe_unused
,
743 union perf_event
*event
,
744 struct perf_sample
*sample
,
745 struct machine
*machine
)
747 return machine__process_fork_event(machine
, event
, sample
);
750 int perf_event__process_exit(struct perf_tool
*tool __maybe_unused
,
751 union perf_event
*event
,
752 struct perf_sample
*sample
,
753 struct machine
*machine
)
755 return machine__process_exit_event(machine
, event
, sample
);
758 size_t perf_event__fprintf(union perf_event
*event
, FILE *fp
)
760 size_t ret
= fprintf(fp
, "PERF_RECORD_%s",
761 perf_event__name(event
->header
.type
));
763 switch (event
->header
.type
) {
764 case PERF_RECORD_COMM
:
765 ret
+= perf_event__fprintf_comm(event
, fp
);
767 case PERF_RECORD_FORK
:
768 case PERF_RECORD_EXIT
:
769 ret
+= perf_event__fprintf_task(event
, fp
);
771 case PERF_RECORD_MMAP
:
772 ret
+= perf_event__fprintf_mmap(event
, fp
);
774 case PERF_RECORD_MMAP2
:
775 ret
+= perf_event__fprintf_mmap2(event
, fp
);
778 ret
+= fprintf(fp
, "\n");
784 int perf_event__process(struct perf_tool
*tool __maybe_unused
,
785 union perf_event
*event
,
786 struct perf_sample
*sample
,
787 struct machine
*machine
)
789 return machine__process_event(machine
, event
, sample
);
792 void thread__find_addr_map(struct thread
*thread
, u8 cpumode
,
793 enum map_type type
, u64 addr
,
794 struct addr_location
*al
)
796 struct map_groups
*mg
= thread
->mg
;
797 struct machine
*machine
= mg
->machine
;
798 bool load_map
= false;
800 al
->machine
= machine
;
803 al
->cpumode
= cpumode
;
806 if (machine
== NULL
) {
811 if (cpumode
== PERF_RECORD_MISC_KERNEL
&& perf_host
) {
813 mg
= &machine
->kmaps
;
815 } else if (cpumode
== PERF_RECORD_MISC_USER
&& perf_host
) {
817 } else if (cpumode
== PERF_RECORD_MISC_GUEST_KERNEL
&& perf_guest
) {
819 mg
= &machine
->kmaps
;
821 } else if (cpumode
== PERF_RECORD_MISC_GUEST_USER
&& perf_guest
) {
827 if ((cpumode
== PERF_RECORD_MISC_GUEST_USER
||
828 cpumode
== PERF_RECORD_MISC_GUEST_KERNEL
) &&
830 al
->filtered
|= (1 << HIST_FILTER__GUEST
);
831 if ((cpumode
== PERF_RECORD_MISC_USER
||
832 cpumode
== PERF_RECORD_MISC_KERNEL
) &&
834 al
->filtered
|= (1 << HIST_FILTER__HOST
);
839 al
->map
= map_groups__find(mg
, type
, al
->addr
);
840 if (al
->map
== NULL
) {
842 * If this is outside of all known maps, and is a negative
843 * address, try to look it up in the kernel dso, as it might be
844 * a vsyscall or vdso (which executes in user-mode).
846 * XXX This is nasty, we should have a symbol list in the
847 * "[vdso]" dso, but for now lets use the old trick of looking
848 * in the whole kernel symbol list.
850 if (cpumode
== PERF_RECORD_MISC_USER
&& machine
&&
851 mg
!= &machine
->kmaps
&&
852 machine__kernel_ip(machine
, al
->addr
)) {
853 mg
= &machine
->kmaps
;
859 * Kernel maps might be changed when loading symbols so loading
860 * must be done prior to using kernel maps.
863 map__load(al
->map
, machine
->symbol_filter
);
864 al
->addr
= al
->map
->map_ip(al
->map
, al
->addr
);
868 void thread__find_addr_location(struct thread
*thread
,
869 u8 cpumode
, enum map_type type
, u64 addr
,
870 struct addr_location
*al
)
872 thread__find_addr_map(thread
, cpumode
, type
, addr
, al
);
874 al
->sym
= map__find_symbol(al
->map
, al
->addr
,
875 thread
->mg
->machine
->symbol_filter
);
880 int perf_event__preprocess_sample(const union perf_event
*event
,
881 struct machine
*machine
,
882 struct addr_location
*al
,
883 struct perf_sample
*sample
)
885 u8 cpumode
= event
->header
.misc
& PERF_RECORD_MISC_CPUMODE_MASK
;
886 struct thread
*thread
= machine__findnew_thread(machine
, sample
->pid
,
892 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread
), thread
->tid
);
894 * Have we already created the kernel maps for this machine?
896 * This should have happened earlier, when we processed the kernel MMAP
897 * events, but for older perf.data files there was no such thing, so do
900 if (cpumode
== PERF_RECORD_MISC_KERNEL
&&
901 machine
->vmlinux_maps
[MAP__FUNCTION
] == NULL
)
902 machine__create_kernel_maps(machine
);
904 thread__find_addr_map(thread
, cpumode
, MAP__FUNCTION
, sample
->ip
, al
);
905 dump_printf(" ...... dso: %s\n",
906 al
->map
? al
->map
->dso
->long_name
:
907 al
->level
== 'H' ? "[hypervisor]" : "<not found>");
909 if (thread__is_filtered(thread
))
910 al
->filtered
|= (1 << HIST_FILTER__THREAD
);
913 al
->cpu
= sample
->cpu
;
916 struct dso
*dso
= al
->map
->dso
;
918 if (symbol_conf
.dso_list
&&
919 (!dso
|| !(strlist__has_entry(symbol_conf
.dso_list
,
921 (dso
->short_name
!= dso
->long_name
&&
922 strlist__has_entry(symbol_conf
.dso_list
,
923 dso
->long_name
))))) {
924 al
->filtered
|= (1 << HIST_FILTER__DSO
);
927 al
->sym
= map__find_symbol(al
->map
, al
->addr
,
928 machine
->symbol_filter
);
931 if (symbol_conf
.sym_list
&&
932 (!al
->sym
|| !strlist__has_entry(symbol_conf
.sym_list
,
934 al
->filtered
|= (1 << HIST_FILTER__SYMBOL
);
940 bool is_bts_event(struct perf_event_attr
*attr
)
942 return attr
->type
== PERF_TYPE_HARDWARE
&&
943 (attr
->config
& PERF_COUNT_HW_BRANCH_INSTRUCTIONS
) &&
944 attr
->sample_period
== 1;
947 bool sample_addr_correlates_sym(struct perf_event_attr
*attr
)
949 if (attr
->type
== PERF_TYPE_SOFTWARE
&&
950 (attr
->config
== PERF_COUNT_SW_PAGE_FAULTS
||
951 attr
->config
== PERF_COUNT_SW_PAGE_FAULTS_MIN
||
952 attr
->config
== PERF_COUNT_SW_PAGE_FAULTS_MAJ
))
955 if (is_bts_event(attr
))
961 void perf_event__preprocess_sample_addr(union perf_event
*event
,
962 struct perf_sample
*sample
,
963 struct thread
*thread
,
964 struct addr_location
*al
)
966 u8 cpumode
= event
->header
.misc
& PERF_RECORD_MISC_CPUMODE_MASK
;
968 thread__find_addr_map(thread
, cpumode
, MAP__FUNCTION
, sample
->addr
, al
);
970 thread__find_addr_map(thread
, cpumode
, MAP__VARIABLE
,
973 al
->cpu
= sample
->cpu
;
977 al
->sym
= map__find_symbol(al
->map
, al
->addr
, NULL
);