5 #include <linux/kernel.h>
6 #include <linux/types.h>
10 #include <uapi/linux/mman.h> /* To get things like MAP_HUGETLB even on older libc headers */
11 #include <api/fs/fs.h>
12 #include <linux/perf_event.h>
13 #include <linux/zalloc.h>
23 #include "thread_map.h"
24 #include "time-utils.h"
25 #include <linux/ctype.h>
28 #include "symbol/kallsyms.h"
32 #include "bpf-event.h"
36 #define DEFAULT_PROC_MAP_PARSE_TIMEOUT 500
38 static const char *perf_event__names
[] = {
40 [PERF_RECORD_MMAP
] = "MMAP",
41 [PERF_RECORD_MMAP2
] = "MMAP2",
42 [PERF_RECORD_LOST
] = "LOST",
43 [PERF_RECORD_COMM
] = "COMM",
44 [PERF_RECORD_EXIT
] = "EXIT",
45 [PERF_RECORD_THROTTLE
] = "THROTTLE",
46 [PERF_RECORD_UNTHROTTLE
] = "UNTHROTTLE",
47 [PERF_RECORD_FORK
] = "FORK",
48 [PERF_RECORD_READ
] = "READ",
49 [PERF_RECORD_SAMPLE
] = "SAMPLE",
50 [PERF_RECORD_AUX
] = "AUX",
51 [PERF_RECORD_ITRACE_START
] = "ITRACE_START",
52 [PERF_RECORD_LOST_SAMPLES
] = "LOST_SAMPLES",
53 [PERF_RECORD_SWITCH
] = "SWITCH",
54 [PERF_RECORD_SWITCH_CPU_WIDE
] = "SWITCH_CPU_WIDE",
55 [PERF_RECORD_NAMESPACES
] = "NAMESPACES",
56 [PERF_RECORD_KSYMBOL
] = "KSYMBOL",
57 [PERF_RECORD_BPF_EVENT
] = "BPF_EVENT",
58 [PERF_RECORD_HEADER_ATTR
] = "ATTR",
59 [PERF_RECORD_HEADER_EVENT_TYPE
] = "EVENT_TYPE",
60 [PERF_RECORD_HEADER_TRACING_DATA
] = "TRACING_DATA",
61 [PERF_RECORD_HEADER_BUILD_ID
] = "BUILD_ID",
62 [PERF_RECORD_FINISHED_ROUND
] = "FINISHED_ROUND",
63 [PERF_RECORD_ID_INDEX
] = "ID_INDEX",
64 [PERF_RECORD_AUXTRACE_INFO
] = "AUXTRACE_INFO",
65 [PERF_RECORD_AUXTRACE
] = "AUXTRACE",
66 [PERF_RECORD_AUXTRACE_ERROR
] = "AUXTRACE_ERROR",
67 [PERF_RECORD_THREAD_MAP
] = "THREAD_MAP",
68 [PERF_RECORD_CPU_MAP
] = "CPU_MAP",
69 [PERF_RECORD_STAT_CONFIG
] = "STAT_CONFIG",
70 [PERF_RECORD_STAT
] = "STAT",
71 [PERF_RECORD_STAT_ROUND
] = "STAT_ROUND",
72 [PERF_RECORD_EVENT_UPDATE
] = "EVENT_UPDATE",
73 [PERF_RECORD_TIME_CONV
] = "TIME_CONV",
74 [PERF_RECORD_HEADER_FEATURE
] = "FEATURE",
75 [PERF_RECORD_COMPRESSED
] = "COMPRESSED",
78 static const char *perf_ns__names
[] = {
79 [NET_NS_INDEX
] = "net",
80 [UTS_NS_INDEX
] = "uts",
81 [IPC_NS_INDEX
] = "ipc",
82 [PID_NS_INDEX
] = "pid",
83 [USER_NS_INDEX
] = "user",
84 [MNT_NS_INDEX
] = "mnt",
85 [CGROUP_NS_INDEX
] = "cgroup",
88 unsigned int proc_map_timeout
= DEFAULT_PROC_MAP_PARSE_TIMEOUT
;
90 const char *perf_event__name(unsigned int id
)
92 if (id
>= ARRAY_SIZE(perf_event__names
))
94 if (!perf_event__names
[id
])
96 return perf_event__names
[id
];
99 static const char *perf_ns__name(unsigned int id
)
101 if (id
>= ARRAY_SIZE(perf_ns__names
))
103 return perf_ns__names
[id
];
106 int perf_tool__process_synth_event(struct perf_tool
*tool
,
107 union perf_event
*event
,
108 struct machine
*machine
,
109 perf_event__handler_t process
)
111 struct perf_sample synth_sample
= {
118 .cpumode
= event
->header
.misc
& PERF_RECORD_MISC_CPUMODE_MASK
,
121 return process(tool
, event
, &synth_sample
, machine
);
125 * Assumes that the first 4095 bytes of /proc/pid/stat contains
126 * the comm, tgid and ppid.
128 static int perf_event__get_comm_ids(pid_t pid
, char *comm
, size_t len
,
129 pid_t
*tgid
, pid_t
*ppid
)
131 char filename
[PATH_MAX
];
136 char *name
, *tgids
, *ppids
;
141 snprintf(filename
, sizeof(filename
), "/proc/%d/status", pid
);
143 fd
= open(filename
, O_RDONLY
);
145 pr_debug("couldn't open %s\n", filename
);
149 n
= read(fd
, bf
, sizeof(bf
) - 1);
152 pr_warning("Couldn't get COMM, tigd and ppid for pid %d\n",
158 name
= strstr(bf
, "Name:");
159 tgids
= strstr(bf
, "Tgid:");
160 ppids
= strstr(bf
, "PPid:");
165 name
= skip_spaces(name
+ 5); /* strlen("Name:") */
166 nl
= strchr(name
, '\n');
173 memcpy(comm
, name
, size
);
176 pr_debug("Name: string not found for pid %d\n", pid
);
180 tgids
+= 5; /* strlen("Tgid:") */
183 pr_debug("Tgid: string not found for pid %d\n", pid
);
187 ppids
+= 5; /* strlen("PPid:") */
190 pr_debug("PPid: string not found for pid %d\n", pid
);
196 static int perf_event__prepare_comm(union perf_event
*event
, pid_t pid
,
197 struct machine
*machine
,
198 pid_t
*tgid
, pid_t
*ppid
)
204 memset(&event
->comm
, 0, sizeof(event
->comm
));
206 if (machine__is_host(machine
)) {
207 if (perf_event__get_comm_ids(pid
, event
->comm
.comm
,
208 sizeof(event
->comm
.comm
),
213 *tgid
= machine
->pid
;
219 event
->comm
.pid
= *tgid
;
220 event
->comm
.header
.type
= PERF_RECORD_COMM
;
222 size
= strlen(event
->comm
.comm
) + 1;
223 size
= PERF_ALIGN(size
, sizeof(u64
));
224 memset(event
->comm
.comm
+ size
, 0, machine
->id_hdr_size
);
225 event
->comm
.header
.size
= (sizeof(event
->comm
) -
226 (sizeof(event
->comm
.comm
) - size
) +
227 machine
->id_hdr_size
);
228 event
->comm
.tid
= pid
;
233 pid_t
perf_event__synthesize_comm(struct perf_tool
*tool
,
234 union perf_event
*event
, pid_t pid
,
235 perf_event__handler_t process
,
236 struct machine
*machine
)
240 if (perf_event__prepare_comm(event
, pid
, machine
, &tgid
, &ppid
) != 0)
243 if (perf_tool__process_synth_event(tool
, event
, machine
, process
) != 0)
249 static void perf_event__get_ns_link_info(pid_t pid
, const char *ns
,
250 struct perf_ns_link_info
*ns_link_info
)
255 sprintf(proc_ns
, "/proc/%u/ns/%s", pid
, ns
);
256 if (stat64(proc_ns
, &st
) == 0) {
257 ns_link_info
->dev
= st
.st_dev
;
258 ns_link_info
->ino
= st
.st_ino
;
262 int perf_event__synthesize_namespaces(struct perf_tool
*tool
,
263 union perf_event
*event
,
264 pid_t pid
, pid_t tgid
,
265 perf_event__handler_t process
,
266 struct machine
*machine
)
269 struct perf_ns_link_info
*ns_link_info
;
271 if (!tool
|| !tool
->namespace_events
)
274 memset(&event
->namespaces
, 0, (sizeof(event
->namespaces
) +
275 (NR_NAMESPACES
* sizeof(struct perf_ns_link_info
)) +
276 machine
->id_hdr_size
));
278 event
->namespaces
.pid
= tgid
;
279 event
->namespaces
.tid
= pid
;
281 event
->namespaces
.nr_namespaces
= NR_NAMESPACES
;
283 ns_link_info
= event
->namespaces
.link_info
;
285 for (idx
= 0; idx
< event
->namespaces
.nr_namespaces
; idx
++)
286 perf_event__get_ns_link_info(pid
, perf_ns__name(idx
),
289 event
->namespaces
.header
.type
= PERF_RECORD_NAMESPACES
;
291 event
->namespaces
.header
.size
= (sizeof(event
->namespaces
) +
292 (NR_NAMESPACES
* sizeof(struct perf_ns_link_info
)) +
293 machine
->id_hdr_size
);
295 if (perf_tool__process_synth_event(tool
, event
, machine
, process
) != 0)
301 static int perf_event__synthesize_fork(struct perf_tool
*tool
,
302 union perf_event
*event
,
303 pid_t pid
, pid_t tgid
, pid_t ppid
,
304 perf_event__handler_t process
,
305 struct machine
*machine
)
307 memset(&event
->fork
, 0, sizeof(event
->fork
) + machine
->id_hdr_size
);
310 * for main thread set parent to ppid from status file. For other
311 * threads set parent pid to main thread. ie., assume main thread
312 * spawns all threads in a process
315 event
->fork
.ppid
= ppid
;
316 event
->fork
.ptid
= ppid
;
318 event
->fork
.ppid
= tgid
;
319 event
->fork
.ptid
= tgid
;
321 event
->fork
.pid
= tgid
;
322 event
->fork
.tid
= pid
;
323 event
->fork
.header
.type
= PERF_RECORD_FORK
;
324 event
->fork
.header
.misc
= PERF_RECORD_MISC_FORK_EXEC
;
326 event
->fork
.header
.size
= (sizeof(event
->fork
) + machine
->id_hdr_size
);
328 if (perf_tool__process_synth_event(tool
, event
, machine
, process
) != 0)
334 int perf_event__synthesize_mmap_events(struct perf_tool
*tool
,
335 union perf_event
*event
,
336 pid_t pid
, pid_t tgid
,
337 perf_event__handler_t process
,
338 struct machine
*machine
,
341 char filename
[PATH_MAX
];
343 unsigned long long t
;
344 bool truncation
= false;
345 unsigned long long timeout
= proc_map_timeout
* 1000000ULL;
347 const char *hugetlbfs_mnt
= hugetlbfs__mountpoint();
348 int hugetlbfs_mnt_len
= hugetlbfs_mnt
? strlen(hugetlbfs_mnt
) : 0;
350 if (machine__is_default_guest(machine
))
353 snprintf(filename
, sizeof(filename
), "%s/proc/%d/task/%d/maps",
354 machine
->root_dir
, pid
, pid
);
356 fp
= fopen(filename
, "r");
359 * We raced with a task exiting - just return:
361 pr_debug("couldn't open %s\n", filename
);
365 event
->header
.type
= PERF_RECORD_MMAP2
;
371 char execname
[PATH_MAX
];
372 char anonstr
[] = "//anon";
377 if (fgets(bf
, sizeof(bf
), fp
) == NULL
)
380 if ((rdclock() - t
) > timeout
) {
381 pr_warning("Reading %s time out. "
382 "You may want to increase "
383 "the time limit by --proc-map-timeout\n",
389 /* ensure null termination since stack will be reused. */
390 strcpy(execname
, "");
392 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
393 n
= sscanf(bf
, "%"PRI_lx64
"-%"PRI_lx64
" %s %"PRI_lx64
" %x:%x %u %[^\n]\n",
394 &event
->mmap2
.start
, &event
->mmap2
.len
, prot
,
395 &event
->mmap2
.pgoff
, &event
->mmap2
.maj
,
400 * Anon maps don't have the execname.
405 event
->mmap2
.ino
= (u64
)ino
;
408 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
410 if (machine__is_host(machine
))
411 event
->header
.misc
= PERF_RECORD_MISC_USER
;
413 event
->header
.misc
= PERF_RECORD_MISC_GUEST_USER
;
415 /* map protection and flags bits */
416 event
->mmap2
.prot
= 0;
417 event
->mmap2
.flags
= 0;
419 event
->mmap2
.prot
|= PROT_READ
;
421 event
->mmap2
.prot
|= PROT_WRITE
;
423 event
->mmap2
.prot
|= PROT_EXEC
;
426 event
->mmap2
.flags
|= MAP_SHARED
;
428 event
->mmap2
.flags
|= MAP_PRIVATE
;
430 if (prot
[2] != 'x') {
431 if (!mmap_data
|| prot
[0] != 'r')
434 event
->header
.misc
|= PERF_RECORD_MISC_MMAP_DATA
;
439 event
->header
.misc
|= PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT
;
441 if (!strcmp(execname
, ""))
442 strcpy(execname
, anonstr
);
444 if (hugetlbfs_mnt_len
&&
445 !strncmp(execname
, hugetlbfs_mnt
, hugetlbfs_mnt_len
)) {
446 strcpy(execname
, anonstr
);
447 event
->mmap2
.flags
|= MAP_HUGETLB
;
450 size
= strlen(execname
) + 1;
451 memcpy(event
->mmap2
.filename
, execname
, size
);
452 size
= PERF_ALIGN(size
, sizeof(u64
));
453 event
->mmap2
.len
-= event
->mmap
.start
;
454 event
->mmap2
.header
.size
= (sizeof(event
->mmap2
) -
455 (sizeof(event
->mmap2
.filename
) - size
));
456 memset(event
->mmap2
.filename
+ size
, 0, machine
->id_hdr_size
);
457 event
->mmap2
.header
.size
+= machine
->id_hdr_size
;
458 event
->mmap2
.pid
= tgid
;
459 event
->mmap2
.tid
= pid
;
461 if (perf_tool__process_synth_event(tool
, event
, machine
, process
) != 0) {
474 int perf_event__synthesize_modules(struct perf_tool
*tool
,
475 perf_event__handler_t process
,
476 struct machine
*machine
)
480 struct maps
*maps
= machine__kernel_maps(machine
);
481 union perf_event
*event
= zalloc((sizeof(event
->mmap
) +
482 machine
->id_hdr_size
));
484 pr_debug("Not enough memory synthesizing mmap event "
485 "for kernel modules\n");
489 event
->header
.type
= PERF_RECORD_MMAP
;
492 * kernel uses 0 for user space maps, see kernel/perf_event.c
495 if (machine__is_host(machine
))
496 event
->header
.misc
= PERF_RECORD_MISC_KERNEL
;
498 event
->header
.misc
= PERF_RECORD_MISC_GUEST_KERNEL
;
500 for (pos
= maps__first(maps
); pos
; pos
= map__next(pos
)) {
503 if (!__map__is_kmodule(pos
))
506 size
= PERF_ALIGN(pos
->dso
->long_name_len
+ 1, sizeof(u64
));
507 event
->mmap
.header
.type
= PERF_RECORD_MMAP
;
508 event
->mmap
.header
.size
= (sizeof(event
->mmap
) -
509 (sizeof(event
->mmap
.filename
) - size
));
510 memset(event
->mmap
.filename
+ size
, 0, machine
->id_hdr_size
);
511 event
->mmap
.header
.size
+= machine
->id_hdr_size
;
512 event
->mmap
.start
= pos
->start
;
513 event
->mmap
.len
= pos
->end
- pos
->start
;
514 event
->mmap
.pid
= machine
->pid
;
516 memcpy(event
->mmap
.filename
, pos
->dso
->long_name
,
517 pos
->dso
->long_name_len
+ 1);
518 if (perf_tool__process_synth_event(tool
, event
, machine
, process
) != 0) {
528 static int __event__synthesize_thread(union perf_event
*comm_event
,
529 union perf_event
*mmap_event
,
530 union perf_event
*fork_event
,
531 union perf_event
*namespaces_event
,
533 perf_event__handler_t process
,
534 struct perf_tool
*tool
,
535 struct machine
*machine
,
538 char filename
[PATH_MAX
];
540 struct dirent
*dirent
;
544 /* special case: only send one comm event using passed in pid */
546 tgid
= perf_event__synthesize_comm(tool
, comm_event
, pid
,
552 if (perf_event__synthesize_namespaces(tool
, namespaces_event
, pid
,
553 tgid
, process
, machine
) < 0)
557 * send mmap only for thread group leader
558 * see thread__init_map_groups
561 perf_event__synthesize_mmap_events(tool
, mmap_event
, pid
, tgid
,
562 process
, machine
, mmap_data
))
568 if (machine__is_default_guest(machine
))
571 snprintf(filename
, sizeof(filename
), "%s/proc/%d/task",
572 machine
->root_dir
, pid
);
574 tasks
= opendir(filename
);
576 pr_debug("couldn't open %s\n", filename
);
580 while ((dirent
= readdir(tasks
)) != NULL
) {
584 _pid
= strtol(dirent
->d_name
, &end
, 10);
589 if (perf_event__prepare_comm(comm_event
, _pid
, machine
,
593 if (perf_event__synthesize_fork(tool
, fork_event
, _pid
, tgid
,
594 ppid
, process
, machine
) < 0)
597 if (perf_event__synthesize_namespaces(tool
, namespaces_event
, _pid
,
598 tgid
, process
, machine
) < 0)
602 * Send the prepared comm event
604 if (perf_tool__process_synth_event(tool
, comm_event
, machine
, process
) != 0)
609 /* process the parent's maps too */
610 rc
= perf_event__synthesize_mmap_events(tool
, mmap_event
, pid
, tgid
,
611 process
, machine
, mmap_data
);
621 int perf_event__synthesize_thread_map(struct perf_tool
*tool
,
622 struct perf_thread_map
*threads
,
623 perf_event__handler_t process
,
624 struct machine
*machine
,
627 union perf_event
*comm_event
, *mmap_event
, *fork_event
;
628 union perf_event
*namespaces_event
;
629 int err
= -1, thread
, j
;
631 comm_event
= malloc(sizeof(comm_event
->comm
) + machine
->id_hdr_size
);
632 if (comm_event
== NULL
)
635 mmap_event
= malloc(sizeof(mmap_event
->mmap2
) + machine
->id_hdr_size
);
636 if (mmap_event
== NULL
)
639 fork_event
= malloc(sizeof(fork_event
->fork
) + machine
->id_hdr_size
);
640 if (fork_event
== NULL
)
643 namespaces_event
= malloc(sizeof(namespaces_event
->namespaces
) +
644 (NR_NAMESPACES
* sizeof(struct perf_ns_link_info
)) +
645 machine
->id_hdr_size
);
646 if (namespaces_event
== NULL
)
650 for (thread
= 0; thread
< threads
->nr
; ++thread
) {
651 if (__event__synthesize_thread(comm_event
, mmap_event
,
652 fork_event
, namespaces_event
,
653 perf_thread_map__pid(threads
, thread
), 0,
654 process
, tool
, machine
,
661 * comm.pid is set to thread group id by
662 * perf_event__synthesize_comm
664 if ((int) comm_event
->comm
.pid
!= perf_thread_map__pid(threads
, thread
)) {
665 bool need_leader
= true;
667 /* is thread group leader in thread_map? */
668 for (j
= 0; j
< threads
->nr
; ++j
) {
669 if ((int) comm_event
->comm
.pid
== perf_thread_map__pid(threads
, j
)) {
675 /* if not, generate events for it */
677 __event__synthesize_thread(comm_event
, mmap_event
,
678 fork_event
, namespaces_event
,
679 comm_event
->comm
.pid
, 0,
680 process
, tool
, machine
,
687 free(namespaces_event
);
698 static int __perf_event__synthesize_threads(struct perf_tool
*tool
,
699 perf_event__handler_t process
,
700 struct machine
*machine
,
702 struct dirent
**dirent
,
706 union perf_event
*comm_event
, *mmap_event
, *fork_event
;
707 union perf_event
*namespaces_event
;
713 comm_event
= malloc(sizeof(comm_event
->comm
) + machine
->id_hdr_size
);
714 if (comm_event
== NULL
)
717 mmap_event
= malloc(sizeof(mmap_event
->mmap2
) + machine
->id_hdr_size
);
718 if (mmap_event
== NULL
)
721 fork_event
= malloc(sizeof(fork_event
->fork
) + machine
->id_hdr_size
);
722 if (fork_event
== NULL
)
725 namespaces_event
= malloc(sizeof(namespaces_event
->namespaces
) +
726 (NR_NAMESPACES
* sizeof(struct perf_ns_link_info
)) +
727 machine
->id_hdr_size
);
728 if (namespaces_event
== NULL
)
731 for (i
= start
; i
< start
+ num
; i
++) {
732 if (!isdigit(dirent
[i
]->d_name
[0]))
735 pid
= (pid_t
)strtol(dirent
[i
]->d_name
, &end
, 10);
736 /* only interested in proper numerical dirents */
740 * We may race with exiting thread, so don't stop just because
741 * one thread couldn't be synthesized.
743 __event__synthesize_thread(comm_event
, mmap_event
, fork_event
,
744 namespaces_event
, pid
, 1, process
,
745 tool
, machine
, mmap_data
);
749 free(namespaces_event
);
760 struct synthesize_threads_arg
{
761 struct perf_tool
*tool
;
762 perf_event__handler_t process
;
763 struct machine
*machine
;
765 struct dirent
**dirent
;
770 static void *synthesize_threads_worker(void *arg
)
772 struct synthesize_threads_arg
*args
= arg
;
774 __perf_event__synthesize_threads(args
->tool
, args
->process
,
775 args
->machine
, args
->mmap_data
,
777 args
->start
, args
->num
);
781 int perf_event__synthesize_threads(struct perf_tool
*tool
,
782 perf_event__handler_t process
,
783 struct machine
*machine
,
785 unsigned int nr_threads_synthesize
)
787 struct synthesize_threads_arg
*args
= NULL
;
788 pthread_t
*synthesize_threads
= NULL
;
789 char proc_path
[PATH_MAX
];
790 struct dirent
**dirent
;
798 if (machine__is_default_guest(machine
))
801 snprintf(proc_path
, sizeof(proc_path
), "%s/proc", machine
->root_dir
);
802 n
= scandir(proc_path
, &dirent
, 0, alphasort
);
806 if (nr_threads_synthesize
== UINT_MAX
)
807 thread_nr
= sysconf(_SC_NPROCESSORS_ONLN
);
809 thread_nr
= nr_threads_synthesize
;
811 if (thread_nr
<= 1) {
812 err
= __perf_event__synthesize_threads(tool
, process
,
820 synthesize_threads
= calloc(sizeof(pthread_t
), thread_nr
);
821 if (synthesize_threads
== NULL
)
824 args
= calloc(sizeof(*args
), thread_nr
);
828 num_per_thread
= n
/ thread_nr
;
830 for (i
= 0; i
< thread_nr
; i
++) {
832 args
[i
].process
= process
;
833 args
[i
].machine
= machine
;
834 args
[i
].mmap_data
= mmap_data
;
835 args
[i
].dirent
= dirent
;
837 for (i
= 0; i
< m
; i
++) {
838 args
[i
].num
= num_per_thread
+ 1;
839 args
[i
].start
= i
* args
[i
].num
;
842 base
= args
[i
-1].start
+ args
[i
-1].num
;
843 for (j
= i
; j
< thread_nr
; j
++) {
844 args
[j
].num
= num_per_thread
;
845 args
[j
].start
= base
+ (j
- i
) * args
[i
].num
;
848 for (i
= 0; i
< thread_nr
; i
++) {
849 if (pthread_create(&synthesize_threads
[i
], NULL
,
850 synthesize_threads_worker
, &args
[i
]))
855 for (i
= 0; i
< thread_nr
; i
++)
856 pthread_join(synthesize_threads
[i
], NULL
);
859 free(synthesize_threads
);
861 for (i
= 0; i
< n
; i
++)
868 struct process_symbol_args
{
873 static int find_symbol_cb(void *arg
, const char *name
, char type
,
876 struct process_symbol_args
*args
= arg
;
879 * Must be a function or at least an alias, as in PARISC64, where "_text" is
880 * an 'A' to the same address as "_stext".
882 if (!(kallsyms__is_function(type
) ||
883 type
== 'A') || strcmp(name
, args
->name
))
890 int kallsyms__get_function_start(const char *kallsyms_filename
,
891 const char *symbol_name
, u64
*addr
)
893 struct process_symbol_args args
= { .name
= symbol_name
, };
895 if (kallsyms__parse(kallsyms_filename
, &args
, find_symbol_cb
) <= 0)
902 int __weak
perf_event__synthesize_extra_kmaps(struct perf_tool
*tool __maybe_unused
,
903 perf_event__handler_t process __maybe_unused
,
904 struct machine
*machine __maybe_unused
)
909 static int __perf_event__synthesize_kernel_mmap(struct perf_tool
*tool
,
910 perf_event__handler_t process
,
911 struct machine
*machine
)
914 struct map
*map
= machine__kernel_map(machine
);
917 union perf_event
*event
;
922 kmap
= map__kmap(map
);
923 if (!kmap
->ref_reloc_sym
)
927 * We should get this from /sys/kernel/sections/.text, but till that is
928 * available use this, and after it is use this as a fallback for older
931 event
= zalloc((sizeof(event
->mmap
) + machine
->id_hdr_size
));
933 pr_debug("Not enough memory synthesizing mmap event "
934 "for kernel modules\n");
938 if (machine__is_host(machine
)) {
940 * kernel uses PERF_RECORD_MISC_USER for user space maps,
941 * see kernel/perf_event.c __perf_event_mmap
943 event
->header
.misc
= PERF_RECORD_MISC_KERNEL
;
945 event
->header
.misc
= PERF_RECORD_MISC_GUEST_KERNEL
;
948 size
= snprintf(event
->mmap
.filename
, sizeof(event
->mmap
.filename
),
949 "%s%s", machine
->mmap_name
, kmap
->ref_reloc_sym
->name
) + 1;
950 size
= PERF_ALIGN(size
, sizeof(u64
));
951 event
->mmap
.header
.type
= PERF_RECORD_MMAP
;
952 event
->mmap
.header
.size
= (sizeof(event
->mmap
) -
953 (sizeof(event
->mmap
.filename
) - size
) + machine
->id_hdr_size
);
954 event
->mmap
.pgoff
= kmap
->ref_reloc_sym
->addr
;
955 event
->mmap
.start
= map
->start
;
956 event
->mmap
.len
= map
->end
- event
->mmap
.start
;
957 event
->mmap
.pid
= machine
->pid
;
959 err
= perf_tool__process_synth_event(tool
, event
, machine
, process
);
965 int perf_event__synthesize_kernel_mmap(struct perf_tool
*tool
,
966 perf_event__handler_t process
,
967 struct machine
*machine
)
971 err
= __perf_event__synthesize_kernel_mmap(tool
, process
, machine
);
975 return perf_event__synthesize_extra_kmaps(tool
, process
, machine
);
978 int perf_event__synthesize_thread_map2(struct perf_tool
*tool
,
979 struct perf_thread_map
*threads
,
980 perf_event__handler_t process
,
981 struct machine
*machine
)
983 union perf_event
*event
;
986 size
= sizeof(event
->thread_map
);
987 size
+= threads
->nr
* sizeof(event
->thread_map
.entries
[0]);
989 event
= zalloc(size
);
993 event
->header
.type
= PERF_RECORD_THREAD_MAP
;
994 event
->header
.size
= size
;
995 event
->thread_map
.nr
= threads
->nr
;
997 for (i
= 0; i
< threads
->nr
; i
++) {
998 struct perf_record_thread_map_entry
*entry
= &event
->thread_map
.entries
[i
];
999 char *comm
= perf_thread_map__comm(threads
, i
);
1004 entry
->pid
= perf_thread_map__pid(threads
, i
);
1005 strncpy((char *) &entry
->comm
, comm
, sizeof(entry
->comm
));
1008 err
= process(tool
, event
, NULL
, machine
);
1014 static void synthesize_cpus(struct cpu_map_entries
*cpus
,
1015 struct perf_cpu_map
*map
)
1021 for (i
= 0; i
< map
->nr
; i
++)
1022 cpus
->cpu
[i
] = map
->map
[i
];
1025 static void synthesize_mask(struct perf_record_record_cpu_map
*mask
,
1026 struct perf_cpu_map
*map
, int max
)
1030 mask
->nr
= BITS_TO_LONGS(max
);
1031 mask
->long_size
= sizeof(long);
1033 for (i
= 0; i
< map
->nr
; i
++)
1034 set_bit(map
->map
[i
], mask
->mask
);
1037 static size_t cpus_size(struct perf_cpu_map
*map
)
1039 return sizeof(struct cpu_map_entries
) + map
->nr
* sizeof(u16
);
1042 static size_t mask_size(struct perf_cpu_map
*map
, int *max
)
1048 for (i
= 0; i
< map
->nr
; i
++) {
1049 /* bit possition of the cpu is + 1 */
1050 int bit
= map
->map
[i
] + 1;
1056 return sizeof(struct perf_record_record_cpu_map
) + BITS_TO_LONGS(*max
) * sizeof(long);
1059 void *cpu_map_data__alloc(struct perf_cpu_map
*map
, size_t *size
, u16
*type
, int *max
)
1061 size_t size_cpus
, size_mask
;
1062 bool is_dummy
= perf_cpu_map__empty(map
);
1065 * Both array and mask data have variable size based
1066 * on the number of cpus and their actual values.
1067 * The size of the 'struct perf_record_cpu_map_data' is:
1069 * array = size of 'struct cpu_map_entries' +
1070 * number of cpus * sizeof(u64)
1072 * mask = size of 'struct perf_record_record_cpu_map' +
1073 * maximum cpu bit converted to size of longs
1075 * and finaly + the size of 'struct perf_record_cpu_map_data'.
1077 size_cpus
= cpus_size(map
);
1078 size_mask
= mask_size(map
, max
);
1080 if (is_dummy
|| (size_cpus
< size_mask
)) {
1082 *type
= PERF_CPU_MAP__CPUS
;
1085 *type
= PERF_CPU_MAP__MASK
;
1088 *size
+= sizeof(struct perf_record_cpu_map_data
);
1089 *size
= PERF_ALIGN(*size
, sizeof(u64
));
1090 return zalloc(*size
);
1093 void cpu_map_data__synthesize(struct perf_record_cpu_map_data
*data
, struct perf_cpu_map
*map
,
1099 case PERF_CPU_MAP__CPUS
:
1100 synthesize_cpus((struct cpu_map_entries
*) data
->data
, map
);
1102 case PERF_CPU_MAP__MASK
:
1103 synthesize_mask((struct perf_record_record_cpu_map
*)data
->data
, map
, max
);
1109 static struct perf_record_cpu_map
*cpu_map_event__new(struct perf_cpu_map
*map
)
1111 size_t size
= sizeof(struct perf_record_cpu_map
);
1112 struct perf_record_cpu_map
*event
;
1116 event
= cpu_map_data__alloc(map
, &size
, &type
, &max
);
1120 event
->header
.type
= PERF_RECORD_CPU_MAP
;
1121 event
->header
.size
= size
;
1122 event
->data
.type
= type
;
1124 cpu_map_data__synthesize(&event
->data
, map
, type
, max
);
1128 int perf_event__synthesize_cpu_map(struct perf_tool
*tool
,
1129 struct perf_cpu_map
*map
,
1130 perf_event__handler_t process
,
1131 struct machine
*machine
)
1133 struct perf_record_cpu_map
*event
;
1136 event
= cpu_map_event__new(map
);
1140 err
= process(tool
, (union perf_event
*) event
, NULL
, machine
);
1146 int perf_event__synthesize_stat_config(struct perf_tool
*tool
,
1147 struct perf_stat_config
*config
,
1148 perf_event__handler_t process
,
1149 struct machine
*machine
)
1151 struct perf_record_stat_config
*event
;
1152 int size
, i
= 0, err
;
1154 size
= sizeof(*event
);
1155 size
+= (PERF_STAT_CONFIG_TERM__MAX
* sizeof(event
->data
[0]));
1157 event
= zalloc(size
);
1161 event
->header
.type
= PERF_RECORD_STAT_CONFIG
;
1162 event
->header
.size
= size
;
1163 event
->nr
= PERF_STAT_CONFIG_TERM__MAX
;
1165 #define ADD(__term, __val) \
1166 event->data[i].tag = PERF_STAT_CONFIG_TERM__##__term; \
1167 event->data[i].val = __val; \
1170 ADD(AGGR_MODE
, config
->aggr_mode
)
1171 ADD(INTERVAL
, config
->interval
)
1172 ADD(SCALE
, config
->scale
)
1174 WARN_ONCE(i
!= PERF_STAT_CONFIG_TERM__MAX
,
1175 "stat config terms unbalanced\n");
1178 err
= process(tool
, (union perf_event
*) event
, NULL
, machine
);
1184 int perf_event__synthesize_stat(struct perf_tool
*tool
,
1185 u32 cpu
, u32 thread
, u64 id
,
1186 struct perf_counts_values
*count
,
1187 perf_event__handler_t process
,
1188 struct machine
*machine
)
1190 struct perf_record_stat event
;
1192 event
.header
.type
= PERF_RECORD_STAT
;
1193 event
.header
.size
= sizeof(event
);
1194 event
.header
.misc
= 0;
1198 event
.thread
= thread
;
1199 event
.val
= count
->val
;
1200 event
.ena
= count
->ena
;
1201 event
.run
= count
->run
;
1203 return process(tool
, (union perf_event
*) &event
, NULL
, machine
);
1206 int perf_event__synthesize_stat_round(struct perf_tool
*tool
,
1207 u64 evtime
, u64 type
,
1208 perf_event__handler_t process
,
1209 struct machine
*machine
)
1211 struct perf_record_stat_round event
;
1213 event
.header
.type
= PERF_RECORD_STAT_ROUND
;
1214 event
.header
.size
= sizeof(event
);
1215 event
.header
.misc
= 0;
1217 event
.time
= evtime
;
1220 return process(tool
, (union perf_event
*) &event
, NULL
, machine
);
1223 void perf_event__read_stat_config(struct perf_stat_config
*config
,
1224 struct perf_record_stat_config
*event
)
1228 for (i
= 0; i
< event
->nr
; i
++) {
1230 switch (event
->data
[i
].tag
) {
1231 #define CASE(__term, __val) \
1232 case PERF_STAT_CONFIG_TERM__##__term: \
1233 config->__val = event->data[i].val; \
1236 CASE(AGGR_MODE
, aggr_mode
)
1238 CASE(INTERVAL
, interval
)
1241 pr_warning("unknown stat config term %" PRI_lu64
"\n",
1242 event
->data
[i
].tag
);
1247 size_t perf_event__fprintf_comm(union perf_event
*event
, FILE *fp
)
1251 if (event
->header
.misc
& PERF_RECORD_MISC_COMM_EXEC
)
1256 return fprintf(fp
, "%s: %s:%d/%d\n", s
, event
->comm
.comm
, event
->comm
.pid
, event
->comm
.tid
);
1259 size_t perf_event__fprintf_namespaces(union perf_event
*event
, FILE *fp
)
1262 struct perf_ns_link_info
*ns_link_info
;
1263 u32 nr_namespaces
, idx
;
1265 ns_link_info
= event
->namespaces
.link_info
;
1266 nr_namespaces
= event
->namespaces
.nr_namespaces
;
1268 ret
+= fprintf(fp
, " %d/%d - nr_namespaces: %u\n\t\t[",
1269 event
->namespaces
.pid
,
1270 event
->namespaces
.tid
,
1273 for (idx
= 0; idx
< nr_namespaces
; idx
++) {
1274 if (idx
&& (idx
% 4 == 0))
1275 ret
+= fprintf(fp
, "\n\t\t ");
1277 ret
+= fprintf(fp
, "%u/%s: %" PRIu64
"/%#" PRIx64
"%s", idx
,
1278 perf_ns__name(idx
), (u64
)ns_link_info
[idx
].dev
,
1279 (u64
)ns_link_info
[idx
].ino
,
1280 ((idx
+ 1) != nr_namespaces
) ? ", " : "]\n");
1286 int perf_event__process_comm(struct perf_tool
*tool __maybe_unused
,
1287 union perf_event
*event
,
1288 struct perf_sample
*sample
,
1289 struct machine
*machine
)
1291 return machine__process_comm_event(machine
, event
, sample
);
1294 int perf_event__process_namespaces(struct perf_tool
*tool __maybe_unused
,
1295 union perf_event
*event
,
1296 struct perf_sample
*sample
,
1297 struct machine
*machine
)
1299 return machine__process_namespaces_event(machine
, event
, sample
);
1302 int perf_event__process_lost(struct perf_tool
*tool __maybe_unused
,
1303 union perf_event
*event
,
1304 struct perf_sample
*sample
,
1305 struct machine
*machine
)
1307 return machine__process_lost_event(machine
, event
, sample
);
1310 int perf_event__process_aux(struct perf_tool
*tool __maybe_unused
,
1311 union perf_event
*event
,
1312 struct perf_sample
*sample __maybe_unused
,
1313 struct machine
*machine
)
1315 return machine__process_aux_event(machine
, event
);
1318 int perf_event__process_itrace_start(struct perf_tool
*tool __maybe_unused
,
1319 union perf_event
*event
,
1320 struct perf_sample
*sample __maybe_unused
,
1321 struct machine
*machine
)
1323 return machine__process_itrace_start_event(machine
, event
);
1326 int perf_event__process_lost_samples(struct perf_tool
*tool __maybe_unused
,
1327 union perf_event
*event
,
1328 struct perf_sample
*sample
,
1329 struct machine
*machine
)
1331 return machine__process_lost_samples_event(machine
, event
, sample
);
1334 int perf_event__process_switch(struct perf_tool
*tool __maybe_unused
,
1335 union perf_event
*event
,
1336 struct perf_sample
*sample __maybe_unused
,
1337 struct machine
*machine
)
1339 return machine__process_switch_event(machine
, event
);
1342 int perf_event__process_ksymbol(struct perf_tool
*tool __maybe_unused
,
1343 union perf_event
*event
,
1344 struct perf_sample
*sample __maybe_unused
,
1345 struct machine
*machine
)
1347 return machine__process_ksymbol(machine
, event
, sample
);
1350 int perf_event__process_bpf(struct perf_tool
*tool __maybe_unused
,
1351 union perf_event
*event
,
1352 struct perf_sample
*sample
,
1353 struct machine
*machine
)
1355 return machine__process_bpf(machine
, event
, sample
);
1358 size_t perf_event__fprintf_mmap(union perf_event
*event
, FILE *fp
)
1360 return fprintf(fp
, " %d/%d: [%#" PRI_lx64
"(%#" PRI_lx64
") @ %#" PRI_lx64
"]: %c %s\n",
1361 event
->mmap
.pid
, event
->mmap
.tid
, event
->mmap
.start
,
1362 event
->mmap
.len
, event
->mmap
.pgoff
,
1363 (event
->header
.misc
& PERF_RECORD_MISC_MMAP_DATA
) ? 'r' : 'x',
1364 event
->mmap
.filename
);
1367 size_t perf_event__fprintf_mmap2(union perf_event
*event
, FILE *fp
)
1369 return fprintf(fp
, " %d/%d: [%#" PRI_lx64
"(%#" PRI_lx64
") @ %#" PRI_lx64
1370 " %02x:%02x %"PRI_lu64
" %"PRI_lu64
"]: %c%c%c%c %s\n",
1371 event
->mmap2
.pid
, event
->mmap2
.tid
, event
->mmap2
.start
,
1372 event
->mmap2
.len
, event
->mmap2
.pgoff
, event
->mmap2
.maj
,
1373 event
->mmap2
.min
, event
->mmap2
.ino
,
1374 event
->mmap2
.ino_generation
,
1375 (event
->mmap2
.prot
& PROT_READ
) ? 'r' : '-',
1376 (event
->mmap2
.prot
& PROT_WRITE
) ? 'w' : '-',
1377 (event
->mmap2
.prot
& PROT_EXEC
) ? 'x' : '-',
1378 (event
->mmap2
.flags
& MAP_SHARED
) ? 's' : 'p',
1379 event
->mmap2
.filename
);
1382 size_t perf_event__fprintf_thread_map(union perf_event
*event
, FILE *fp
)
1384 struct perf_thread_map
*threads
= thread_map__new_event(&event
->thread_map
);
1387 ret
= fprintf(fp
, " nr: ");
1390 ret
+= thread_map__fprintf(threads
, fp
);
1392 ret
+= fprintf(fp
, "failed to get threads from event\n");
1394 perf_thread_map__put(threads
);
1398 size_t perf_event__fprintf_cpu_map(union perf_event
*event
, FILE *fp
)
1400 struct perf_cpu_map
*cpus
= cpu_map__new_data(&event
->cpu_map
.data
);
1403 ret
= fprintf(fp
, ": ");
1406 ret
+= cpu_map__fprintf(cpus
, fp
);
1408 ret
+= fprintf(fp
, "failed to get cpumap from event\n");
1410 perf_cpu_map__put(cpus
);
1414 int perf_event__process_mmap(struct perf_tool
*tool __maybe_unused
,
1415 union perf_event
*event
,
1416 struct perf_sample
*sample
,
1417 struct machine
*machine
)
1419 return machine__process_mmap_event(machine
, event
, sample
);
1422 int perf_event__process_mmap2(struct perf_tool
*tool __maybe_unused
,
1423 union perf_event
*event
,
1424 struct perf_sample
*sample
,
1425 struct machine
*machine
)
1427 return machine__process_mmap2_event(machine
, event
, sample
);
1430 size_t perf_event__fprintf_task(union perf_event
*event
, FILE *fp
)
1432 return fprintf(fp
, "(%d:%d):(%d:%d)\n",
1433 event
->fork
.pid
, event
->fork
.tid
,
1434 event
->fork
.ppid
, event
->fork
.ptid
);
1437 int perf_event__process_fork(struct perf_tool
*tool __maybe_unused
,
1438 union perf_event
*event
,
1439 struct perf_sample
*sample
,
1440 struct machine
*machine
)
1442 return machine__process_fork_event(machine
, event
, sample
);
1445 int perf_event__process_exit(struct perf_tool
*tool __maybe_unused
,
1446 union perf_event
*event
,
1447 struct perf_sample
*sample
,
1448 struct machine
*machine
)
1450 return machine__process_exit_event(machine
, event
, sample
);
1453 size_t perf_event__fprintf_aux(union perf_event
*event
, FILE *fp
)
1455 return fprintf(fp
, " offset: %#"PRI_lx64
" size: %#"PRI_lx64
" flags: %#"PRI_lx64
" [%s%s%s]\n",
1456 event
->aux
.aux_offset
, event
->aux
.aux_size
,
1458 event
->aux
.flags
& PERF_AUX_FLAG_TRUNCATED
? "T" : "",
1459 event
->aux
.flags
& PERF_AUX_FLAG_OVERWRITE
? "O" : "",
1460 event
->aux
.flags
& PERF_AUX_FLAG_PARTIAL
? "P" : "");
1463 size_t perf_event__fprintf_itrace_start(union perf_event
*event
, FILE *fp
)
1465 return fprintf(fp
, " pid: %u tid: %u\n",
1466 event
->itrace_start
.pid
, event
->itrace_start
.tid
);
1469 size_t perf_event__fprintf_switch(union perf_event
*event
, FILE *fp
)
1471 bool out
= event
->header
.misc
& PERF_RECORD_MISC_SWITCH_OUT
;
1472 const char *in_out
= !out
? "IN " :
1473 !(event
->header
.misc
& PERF_RECORD_MISC_SWITCH_OUT_PREEMPT
) ?
1474 "OUT " : "OUT preempt";
1476 if (event
->header
.type
== PERF_RECORD_SWITCH
)
1477 return fprintf(fp
, " %s\n", in_out
);
1479 return fprintf(fp
, " %s %s pid/tid: %5u/%-5u\n",
1480 in_out
, out
? "next" : "prev",
1481 event
->context_switch
.next_prev_pid
,
1482 event
->context_switch
.next_prev_tid
);
1485 static size_t perf_event__fprintf_lost(union perf_event
*event
, FILE *fp
)
1487 return fprintf(fp
, " lost %" PRI_lu64
"\n", event
->lost
.lost
);
1490 size_t perf_event__fprintf_ksymbol(union perf_event
*event
, FILE *fp
)
1492 return fprintf(fp
, " addr %" PRI_lx64
" len %u type %u flags 0x%x name %s\n",
1493 event
->ksymbol
.addr
, event
->ksymbol
.len
,
1494 event
->ksymbol
.ksym_type
,
1495 event
->ksymbol
.flags
, event
->ksymbol
.name
);
1498 size_t perf_event__fprintf_bpf(union perf_event
*event
, FILE *fp
)
1500 return fprintf(fp
, " type %u, flags %u, id %u\n",
1501 event
->bpf
.type
, event
->bpf
.flags
, event
->bpf
.id
);
1504 size_t perf_event__fprintf(union perf_event
*event
, FILE *fp
)
1506 size_t ret
= fprintf(fp
, "PERF_RECORD_%s",
1507 perf_event__name(event
->header
.type
));
1509 switch (event
->header
.type
) {
1510 case PERF_RECORD_COMM
:
1511 ret
+= perf_event__fprintf_comm(event
, fp
);
1513 case PERF_RECORD_FORK
:
1514 case PERF_RECORD_EXIT
:
1515 ret
+= perf_event__fprintf_task(event
, fp
);
1517 case PERF_RECORD_MMAP
:
1518 ret
+= perf_event__fprintf_mmap(event
, fp
);
1520 case PERF_RECORD_NAMESPACES
:
1521 ret
+= perf_event__fprintf_namespaces(event
, fp
);
1523 case PERF_RECORD_MMAP2
:
1524 ret
+= perf_event__fprintf_mmap2(event
, fp
);
1526 case PERF_RECORD_AUX
:
1527 ret
+= perf_event__fprintf_aux(event
, fp
);
1529 case PERF_RECORD_ITRACE_START
:
1530 ret
+= perf_event__fprintf_itrace_start(event
, fp
);
1532 case PERF_RECORD_SWITCH
:
1533 case PERF_RECORD_SWITCH_CPU_WIDE
:
1534 ret
+= perf_event__fprintf_switch(event
, fp
);
1536 case PERF_RECORD_LOST
:
1537 ret
+= perf_event__fprintf_lost(event
, fp
);
1539 case PERF_RECORD_KSYMBOL
:
1540 ret
+= perf_event__fprintf_ksymbol(event
, fp
);
1542 case PERF_RECORD_BPF_EVENT
:
1543 ret
+= perf_event__fprintf_bpf(event
, fp
);
1546 ret
+= fprintf(fp
, "\n");
1552 int perf_event__process(struct perf_tool
*tool __maybe_unused
,
1553 union perf_event
*event
,
1554 struct perf_sample
*sample
,
1555 struct machine
*machine
)
1557 return machine__process_event(machine
, event
, sample
);
1560 struct map
*thread__find_map(struct thread
*thread
, u8 cpumode
, u64 addr
,
1561 struct addr_location
*al
)
1563 struct map_groups
*mg
= thread
->mg
;
1564 struct machine
*machine
= mg
->machine
;
1565 bool load_map
= false;
1567 al
->machine
= machine
;
1568 al
->thread
= thread
;
1570 al
->cpumode
= cpumode
;
1573 if (machine
== NULL
) {
1578 if (cpumode
== PERF_RECORD_MISC_KERNEL
&& perf_host
) {
1580 mg
= &machine
->kmaps
;
1582 } else if (cpumode
== PERF_RECORD_MISC_USER
&& perf_host
) {
1584 } else if (cpumode
== PERF_RECORD_MISC_GUEST_KERNEL
&& perf_guest
) {
1586 mg
= &machine
->kmaps
;
1588 } else if (cpumode
== PERF_RECORD_MISC_GUEST_USER
&& perf_guest
) {
1594 if ((cpumode
== PERF_RECORD_MISC_GUEST_USER
||
1595 cpumode
== PERF_RECORD_MISC_GUEST_KERNEL
) &&
1597 al
->filtered
|= (1 << HIST_FILTER__GUEST
);
1598 if ((cpumode
== PERF_RECORD_MISC_USER
||
1599 cpumode
== PERF_RECORD_MISC_KERNEL
) &&
1601 al
->filtered
|= (1 << HIST_FILTER__HOST
);
1606 al
->map
= map_groups__find(mg
, al
->addr
);
1607 if (al
->map
!= NULL
) {
1609 * Kernel maps might be changed when loading symbols so loading
1610 * must be done prior to using kernel maps.
1614 al
->addr
= al
->map
->map_ip(al
->map
, al
->addr
);
1621 * For branch stacks or branch samples, the sample cpumode might not be correct
1622 * because it applies only to the sample 'ip' and not necessary to 'addr' or
1623 * branch stack addresses. If possible, use a fallback to deal with those cases.
1625 struct map
*thread__find_map_fb(struct thread
*thread
, u8 cpumode
, u64 addr
,
1626 struct addr_location
*al
)
1628 struct map
*map
= thread__find_map(thread
, cpumode
, addr
, al
);
1629 struct machine
*machine
= thread
->mg
->machine
;
1630 u8 addr_cpumode
= machine__addr_cpumode(machine
, cpumode
, addr
);
1632 if (map
|| addr_cpumode
== cpumode
)
1635 return thread__find_map(thread
, addr_cpumode
, addr
, al
);
1638 struct symbol
*thread__find_symbol(struct thread
*thread
, u8 cpumode
,
1639 u64 addr
, struct addr_location
*al
)
1642 if (thread__find_map(thread
, cpumode
, addr
, al
))
1643 al
->sym
= map__find_symbol(al
->map
, al
->addr
);
1647 struct symbol
*thread__find_symbol_fb(struct thread
*thread
, u8 cpumode
,
1648 u64 addr
, struct addr_location
*al
)
1651 if (thread__find_map_fb(thread
, cpumode
, addr
, al
))
1652 al
->sym
= map__find_symbol(al
->map
, al
->addr
);
1657 * Callers need to drop the reference to al->thread, obtained in
1658 * machine__findnew_thread()
1660 int machine__resolve(struct machine
*machine
, struct addr_location
*al
,
1661 struct perf_sample
*sample
)
1663 struct thread
*thread
= machine__findnew_thread(machine
, sample
->pid
,
1669 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread
), thread
->tid
);
1670 thread__find_map(thread
, sample
->cpumode
, sample
->ip
, al
);
1671 dump_printf(" ...... dso: %s\n",
1672 al
->map
? al
->map
->dso
->long_name
:
1673 al
->level
== 'H' ? "[hypervisor]" : "<not found>");
1675 if (thread__is_filtered(thread
))
1676 al
->filtered
|= (1 << HIST_FILTER__THREAD
);
1679 al
->cpu
= sample
->cpu
;
1684 struct perf_env
*env
= machine
->env
;
1686 if (env
&& env
->cpu
)
1687 al
->socket
= env
->cpu
[al
->cpu
].socket_id
;
1691 struct dso
*dso
= al
->map
->dso
;
1693 if (symbol_conf
.dso_list
&&
1694 (!dso
|| !(strlist__has_entry(symbol_conf
.dso_list
,
1696 (dso
->short_name
!= dso
->long_name
&&
1697 strlist__has_entry(symbol_conf
.dso_list
,
1698 dso
->long_name
))))) {
1699 al
->filtered
|= (1 << HIST_FILTER__DSO
);
1702 al
->sym
= map__find_symbol(al
->map
, al
->addr
);
1705 if (symbol_conf
.sym_list
&&
1706 (!al
->sym
|| !strlist__has_entry(symbol_conf
.sym_list
,
1708 al
->filtered
|= (1 << HIST_FILTER__SYMBOL
);
1715 * The preprocess_sample method will return with reference counts for the
1716 * in it, when done using (and perhaps getting ref counts if needing to
1717 * keep a pointer to one of those entries) it must be paired with
1718 * addr_location__put(), so that the refcounts can be decremented.
1720 void addr_location__put(struct addr_location
*al
)
1722 thread__zput(al
->thread
);
1725 bool is_bts_event(struct perf_event_attr
*attr
)
1727 return attr
->type
== PERF_TYPE_HARDWARE
&&
1728 (attr
->config
& PERF_COUNT_HW_BRANCH_INSTRUCTIONS
) &&
1729 attr
->sample_period
== 1;
1732 bool sample_addr_correlates_sym(struct perf_event_attr
*attr
)
1734 if (attr
->type
== PERF_TYPE_SOFTWARE
&&
1735 (attr
->config
== PERF_COUNT_SW_PAGE_FAULTS
||
1736 attr
->config
== PERF_COUNT_SW_PAGE_FAULTS_MIN
||
1737 attr
->config
== PERF_COUNT_SW_PAGE_FAULTS_MAJ
))
1740 if (is_bts_event(attr
))
1746 void thread__resolve(struct thread
*thread
, struct addr_location
*al
,
1747 struct perf_sample
*sample
)
1749 thread__find_map_fb(thread
, sample
->cpumode
, sample
->addr
, al
);
1751 al
->cpu
= sample
->cpu
;
1755 al
->sym
= map__find_symbol(al
->map
, al
->addr
);