diff options
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r-- | tools/perf/util/event.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index bb788c109fe6..1fc1c2f04772 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include "strlist.h" | 7 | #include "strlist.h" |
8 | #include "thread.h" | 8 | #include "thread.h" |
9 | #include "thread_map.h" | 9 | #include "thread_map.h" |
10 | #include "symbol/kallsyms.h" | ||
10 | 11 | ||
11 | static const char *perf_event__names[] = { | 12 | static const char *perf_event__names[] = { |
12 | [0] = "TOTAL", | 13 | [0] = "TOTAL", |
@@ -105,8 +106,12 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, | |||
105 | 106 | ||
106 | memset(&event->comm, 0, sizeof(event->comm)); | 107 | memset(&event->comm, 0, sizeof(event->comm)); |
107 | 108 | ||
108 | tgid = perf_event__get_comm_tgid(pid, event->comm.comm, | 109 | if (machine__is_host(machine)) |
109 | sizeof(event->comm.comm)); | 110 | tgid = perf_event__get_comm_tgid(pid, event->comm.comm, |
111 | sizeof(event->comm.comm)); | ||
112 | else | ||
113 | tgid = machine->pid; | ||
114 | |||
110 | if (tgid < 0) | 115 | if (tgid < 0) |
111 | goto out; | 116 | goto out; |
112 | 117 | ||
@@ -128,7 +133,11 @@ static pid_t perf_event__synthesize_comm(struct perf_tool *tool, | |||
128 | goto out; | 133 | goto out; |
129 | } | 134 | } |
130 | 135 | ||
131 | snprintf(filename, sizeof(filename), "/proc/%d/task", pid); | 136 | if (machine__is_default_guest(machine)) |
137 | return 0; | ||
138 | |||
139 | snprintf(filename, sizeof(filename), "%s/proc/%d/task", | ||
140 | machine->root_dir, pid); | ||
132 | 141 | ||
133 | tasks = opendir(filename); | 142 | tasks = opendir(filename); |
134 | if (tasks == NULL) { | 143 | if (tasks == NULL) { |
@@ -166,18 +175,22 @@ out: | |||
166 | return tgid; | 175 | return tgid; |
167 | } | 176 | } |
168 | 177 | ||
169 | static int perf_event__synthesize_mmap_events(struct perf_tool *tool, | 178 | int perf_event__synthesize_mmap_events(struct perf_tool *tool, |
170 | union perf_event *event, | 179 | union perf_event *event, |
171 | pid_t pid, pid_t tgid, | 180 | pid_t pid, pid_t tgid, |
172 | perf_event__handler_t process, | 181 | perf_event__handler_t process, |
173 | struct machine *machine, | 182 | struct machine *machine, |
174 | bool mmap_data) | 183 | bool mmap_data) |
175 | { | 184 | { |
176 | char filename[PATH_MAX]; | 185 | char filename[PATH_MAX]; |
177 | FILE *fp; | 186 | FILE *fp; |
178 | int rc = 0; | 187 | int rc = 0; |
179 | 188 | ||
180 | snprintf(filename, sizeof(filename), "/proc/%d/maps", pid); | 189 | if (machine__is_default_guest(machine)) |
190 | return 0; | ||
191 | |||
192 | snprintf(filename, sizeof(filename), "%s/proc/%d/maps", | ||
193 | machine->root_dir, pid); | ||
181 | 194 | ||
182 | fp = fopen(filename, "r"); | 195 | fp = fopen(filename, "r"); |
183 | if (fp == NULL) { | 196 | if (fp == NULL) { |
@@ -217,7 +230,10 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool, | |||
217 | /* | 230 | /* |
218 | * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c | 231 | * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c |
219 | */ | 232 | */ |
220 | event->header.misc = PERF_RECORD_MISC_USER; | 233 | if (machine__is_host(machine)) |
234 | event->header.misc = PERF_RECORD_MISC_USER; | ||
235 | else | ||
236 | event->header.misc = PERF_RECORD_MISC_GUEST_USER; | ||
221 | 237 | ||
222 | if (prot[2] != 'x') { | 238 | if (prot[2] != 'x') { |
223 | if (!mmap_data || prot[0] != 'r') | 239 | if (!mmap_data || prot[0] != 'r') |
@@ -386,6 +402,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
386 | struct machine *machine, bool mmap_data) | 402 | struct machine *machine, bool mmap_data) |
387 | { | 403 | { |
388 | DIR *proc; | 404 | DIR *proc; |
405 | char proc_path[PATH_MAX]; | ||
389 | struct dirent dirent, *next; | 406 | struct dirent dirent, *next; |
390 | union perf_event *comm_event, *mmap_event; | 407 | union perf_event *comm_event, *mmap_event; |
391 | int err = -1; | 408 | int err = -1; |
@@ -398,7 +415,12 @@ int perf_event__synthesize_threads(struct perf_tool *tool, | |||
398 | if (mmap_event == NULL) | 415 | if (mmap_event == NULL) |
399 | goto out_free_comm; | 416 | goto out_free_comm; |
400 | 417 | ||
401 | proc = opendir("/proc"); | 418 | if (machine__is_default_guest(machine)) |
419 | return 0; | ||
420 | |||
421 | snprintf(proc_path, sizeof(proc_path), "%s/proc", machine->root_dir); | ||
422 | proc = opendir(proc_path); | ||
423 | |||
402 | if (proc == NULL) | 424 | if (proc == NULL) |
403 | goto out_free_mmap; | 425 | goto out_free_mmap; |
404 | 426 | ||
@@ -637,6 +659,7 @@ void thread__find_addr_map(struct thread *thread, | |||
637 | struct map_groups *mg = &thread->mg; | 659 | struct map_groups *mg = &thread->mg; |
638 | bool load_map = false; | 660 | bool load_map = false; |
639 | 661 | ||
662 | al->machine = machine; | ||
640 | al->thread = thread; | 663 | al->thread = thread; |
641 | al->addr = addr; | 664 | al->addr = addr; |
642 | al->cpumode = cpumode; | 665 | al->cpumode = cpumode; |
@@ -657,15 +680,10 @@ void thread__find_addr_map(struct thread *thread, | |||
657 | al->level = 'g'; | 680 | al->level = 'g'; |
658 | mg = &machine->kmaps; | 681 | mg = &machine->kmaps; |
659 | load_map = true; | 682 | load_map = true; |
683 | } else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) { | ||
684 | al->level = 'u'; | ||
660 | } else { | 685 | } else { |
661 | /* | 686 | al->level = 'H'; |
662 | * 'u' means guest os user space. | ||
663 | * TODO: We don't support guest user space. Might support late. | ||
664 | */ | ||
665 | if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) | ||
666 | al->level = 'u'; | ||
667 | else | ||
668 | al->level = 'H'; | ||
669 | al->map = NULL; | 687 | al->map = NULL; |
670 | 688 | ||
671 | if ((cpumode == PERF_RECORD_MISC_GUEST_USER || | 689 | if ((cpumode == PERF_RECORD_MISC_GUEST_USER || |
@@ -732,8 +750,7 @@ int perf_event__preprocess_sample(const union perf_event *event, | |||
732 | if (thread == NULL) | 750 | if (thread == NULL) |
733 | return -1; | 751 | return -1; |
734 | 752 | ||
735 | if (symbol_conf.comm_list && | 753 | if (thread__is_filtered(thread)) |
736 | !strlist__has_entry(symbol_conf.comm_list, thread__comm_str(thread))) | ||
737 | goto out_filtered; | 754 | goto out_filtered; |
738 | 755 | ||
739 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); | 756 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); |