blob: cc7c0c9c9ea67bbc52e0d6dca83176f30130fc1d [file] [log] [blame]
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -02001#include <linux/types.h>
2#include "event.h"
3#include "debug.h"
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -03004#include "machine.h"
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -02005#include "sort.h"
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -02006#include "string.h"
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -02007#include "strlist.h"
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -02008#include "thread.h"
Arnaldo Carvalho de Melo7c940c12011-02-11 11:45:54 -02009#include "thread_map.h"
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020010
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020011static const char *perf_event__names[] = {
Frederic Weisbecker3cb6d152011-05-23 13:06:27 +020012 [0] = "TOTAL",
13 [PERF_RECORD_MMAP] = "MMAP",
14 [PERF_RECORD_LOST] = "LOST",
15 [PERF_RECORD_COMM] = "COMM",
16 [PERF_RECORD_EXIT] = "EXIT",
17 [PERF_RECORD_THROTTLE] = "THROTTLE",
18 [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE",
19 [PERF_RECORD_FORK] = "FORK",
20 [PERF_RECORD_READ] = "READ",
21 [PERF_RECORD_SAMPLE] = "SAMPLE",
22 [PERF_RECORD_HEADER_ATTR] = "ATTR",
23 [PERF_RECORD_HEADER_EVENT_TYPE] = "EVENT_TYPE",
24 [PERF_RECORD_HEADER_TRACING_DATA] = "TRACING_DATA",
25 [PERF_RECORD_HEADER_BUILD_ID] = "BUILD_ID",
26 [PERF_RECORD_FINISHED_ROUND] = "FINISHED_ROUND",
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -030027};
28
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020029const char *perf_event__name(unsigned int id)
Thomas Gleixner3835bc02010-12-07 12:48:42 +000030{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020031 if (id >= ARRAY_SIZE(perf_event__names))
Thomas Gleixner3835bc02010-12-07 12:48:42 +000032 return "INVALID";
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020033 if (!perf_event__names[id])
Thomas Gleixner3835bc02010-12-07 12:48:42 +000034 return "UNKNOWN";
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020035 return perf_event__names[id];
Thomas Gleixner3835bc02010-12-07 12:48:42 +000036}
37
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -020038static struct perf_sample synth_sample = {
Arnaldo Carvalho de Melo640c03c2010-12-02 14:10:21 -020039 .pid = -1,
40 .tid = -1,
41 .time = -1,
42 .stream_id = -1,
43 .cpu = -1,
44 .period = 1,
45};
46
David Ahernf5faf722011-12-22 11:30:02 -070047static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020048{
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020049 char filename[PATH_MAX];
50 char bf[BUFSIZ];
51 FILE *fp;
52 size_t size = 0;
David Ahernf5faf722011-12-22 11:30:02 -070053 pid_t tgid = -1;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020054
55 snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
56
57 fp = fopen(filename, "r");
58 if (fp == NULL) {
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020059 pr_debug("couldn't open %s\n", filename);
60 return 0;
61 }
62
David Ahernf5faf722011-12-22 11:30:02 -070063 while (!comm[0] || (tgid < 0)) {
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020064 if (fgets(bf, sizeof(bf), fp) == NULL) {
David Ahernf5faf722011-12-22 11:30:02 -070065 pr_warning("couldn't get COMM and pgid, malformed %s\n",
66 filename);
67 break;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -020068 }
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020069
70 if (memcmp(bf, "Name:", 5) == 0) {
71 char *name = bf + 5;
72 while (*name && isspace(*name))
73 ++name;
74 size = strlen(name) - 1;
David Ahernf5faf722011-12-22 11:30:02 -070075 if (size >= len)
76 size = len - 1;
77 memcpy(comm, name, size);
David Aherncfbd70c2012-02-24 12:31:38 -070078 comm[size] = '\0';
David Ahernf5faf722011-12-22 11:30:02 -070079
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020080 } else if (memcmp(bf, "Tgid:", 5) == 0) {
81 char *tgids = bf + 5;
82 while (*tgids && isspace(*tgids))
83 ++tgids;
David Ahernf5faf722011-12-22 11:30:02 -070084 tgid = atoi(tgids);
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -020085 }
86 }
87
David Ahernf5faf722011-12-22 11:30:02 -070088 fclose(fp);
89
90 return tgid;
91}
92
93static pid_t perf_event__synthesize_comm(struct perf_tool *tool,
94 union perf_event *event, pid_t pid,
95 int full,
96 perf_event__handler_t process,
97 struct machine *machine)
98{
99 char filename[PATH_MAX];
100 size_t size;
101 DIR *tasks;
102 struct dirent dirent, *next;
103 pid_t tgid;
104
105 memset(&event->comm, 0, sizeof(event->comm));
106
107 tgid = perf_event__get_comm_tgid(pid, event->comm.comm,
108 sizeof(event->comm.comm));
109 if (tgid < 0)
110 goto out;
111
112 event->comm.pid = tgid;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200113 event->comm.header.type = PERF_RECORD_COMM;
David Ahernf5faf722011-12-22 11:30:02 -0700114
115 size = strlen(event->comm.comm) + 1;
Irina Tirdea9ac3e482012-09-11 01:15:01 +0300116 size = PERF_ALIGN(size, sizeof(u64));
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200117 memset(event->comm.comm + size, 0, machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200118 event->comm.header.size = (sizeof(event->comm) -
119 (sizeof(event->comm.comm) - size) +
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200120 machine->id_hdr_size);
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200121 if (!full) {
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200122 event->comm.tid = pid;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200123
David Ahern1e6d5322012-08-26 12:24:42 -0600124 if (process(tool, event, &synth_sample, machine) != 0)
125 return -1;
126
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200127 goto out;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200128 }
129
130 snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
131
132 tasks = opendir(filename);
David Ahernf5faf722011-12-22 11:30:02 -0700133 if (tasks == NULL) {
134 pr_debug("couldn't open %s\n", filename);
135 return 0;
136 }
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200137
138 while (!readdir_r(tasks, &dirent, &next) && next) {
139 char *end;
140 pid = strtol(dirent.d_name, &end, 10);
141 if (*end)
142 continue;
143
David Ahernf5faf722011-12-22 11:30:02 -0700144 /* already have tgid; jut want to update the comm */
145 (void) perf_event__get_comm_tgid(pid, event->comm.comm,
146 sizeof(event->comm.comm));
147
148 size = strlen(event->comm.comm) + 1;
Irina Tirdea9ac3e482012-09-11 01:15:01 +0300149 size = PERF_ALIGN(size, sizeof(u64));
David Ahernf5faf722011-12-22 11:30:02 -0700150 memset(event->comm.comm + size, 0, machine->id_hdr_size);
151 event->comm.header.size = (sizeof(event->comm) -
152 (sizeof(event->comm.comm) - size) +
153 machine->id_hdr_size);
154
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200155 event->comm.tid = pid;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200156
David Ahern1e6d5322012-08-26 12:24:42 -0600157 if (process(tool, event, &synth_sample, machine) != 0) {
158 tgid = -1;
159 break;
160 }
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200161 }
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200162
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200163 closedir(tasks);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200164out:
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200165 return tgid;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200166}
167
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200168static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200169 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200170 pid_t pid, pid_t tgid,
171 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200172 struct machine *machine)
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200173{
174 char filename[PATH_MAX];
175 FILE *fp;
David Ahern1e6d5322012-08-26 12:24:42 -0600176 int rc = 0;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200177
178 snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
179
180 fp = fopen(filename, "r");
181 if (fp == NULL) {
182 /*
183 * We raced with a task exiting - just return:
184 */
185 pr_debug("couldn't open %s\n", filename);
186 return -1;
187 }
188
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200189 event->header.type = PERF_RECORD_MMAP;
190 /*
191 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
192 */
193 event->header.misc = PERF_RECORD_MISC_USER;
194
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200195 while (1) {
Namhyung Kim60648032012-11-11 23:20:50 +0900196 char bf[BUFSIZ];
197 char prot[5];
198 char execname[PATH_MAX];
199 char anonstr[] = "//anon";
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200200 size_t size;
Namhyung Kim60648032012-11-11 23:20:50 +0900201
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200202 if (fgets(bf, sizeof(bf), fp) == NULL)
203 break;
204
Namhyung Kim60648032012-11-11 23:20:50 +0900205 /* ensure null termination since stack will be reused. */
206 strcpy(execname, "");
207
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200208 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
Namhyung Kim60648032012-11-11 23:20:50 +0900209 sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %*x:%*x %*u %s\n",
210 &event->mmap.start, &event->mmap.len, prot,
211 &event->mmap.pgoff, execname);
212
213 if (prot[2] != 'x')
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200214 continue;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200215
Namhyung Kim60648032012-11-11 23:20:50 +0900216 if (!strcmp(execname, ""))
217 strcpy(execname, anonstr);
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200218
Namhyung Kim60648032012-11-11 23:20:50 +0900219 size = strlen(execname) + 1;
220 memcpy(event->mmap.filename, execname, size);
221 size = PERF_ALIGN(size, sizeof(u64));
222 event->mmap.len -= event->mmap.start;
223 event->mmap.header.size = (sizeof(event->mmap) -
224 (sizeof(event->mmap.filename) - size));
225 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
226 event->mmap.header.size += machine->id_hdr_size;
227 event->mmap.pid = tgid;
228 event->mmap.tid = pid;
Anton Blanchard6a0e55d2011-08-30 09:15:06 +1000229
Namhyung Kim60648032012-11-11 23:20:50 +0900230 if (process(tool, event, &synth_sample, machine) != 0) {
231 rc = -1;
232 break;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200233 }
234 }
235
236 fclose(fp);
David Ahern1e6d5322012-08-26 12:24:42 -0600237 return rc;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200238}
239
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200240int perf_event__synthesize_modules(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200241 perf_event__handler_t process,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200242 struct machine *machine)
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200243{
David Ahern1e6d5322012-08-26 12:24:42 -0600244 int rc = 0;
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200245 struct rb_node *nd;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300246 struct map_groups *kmaps = &machine->kmaps;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200247 union perf_event *event = zalloc((sizeof(event->mmap) +
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200248 machine->id_hdr_size));
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200249 if (event == NULL) {
250 pr_debug("Not enough memory synthesizing mmap event "
251 "for kernel modules\n");
252 return -1;
253 }
254
255 event->header.type = PERF_RECORD_MMAP;
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200256
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800257 /*
258 * kernel uses 0 for user space maps, see kernel/perf_event.c
259 * __perf_event_mmap
260 */
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300261 if (machine__is_host(machine))
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200262 event->header.misc = PERF_RECORD_MISC_KERNEL;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800263 else
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200264 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800265
266 for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]);
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200267 nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200268 size_t size;
269 struct map *pos = rb_entry(nd, struct map, rb_node);
270
271 if (pos->dso->kernel)
272 continue;
273
Irina Tirdea9ac3e482012-09-11 01:15:01 +0300274 size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200275 event->mmap.header.type = PERF_RECORD_MMAP;
276 event->mmap.header.size = (sizeof(event->mmap) -
277 (sizeof(event->mmap.filename) - size));
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200278 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
279 event->mmap.header.size += machine->id_hdr_size;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200280 event->mmap.start = pos->start;
281 event->mmap.len = pos->end - pos->start;
282 event->mmap.pid = machine->pid;
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200283
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200284 memcpy(event->mmap.filename, pos->dso->long_name,
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200285 pos->dso->long_name_len + 1);
David Ahern1e6d5322012-08-26 12:24:42 -0600286 if (process(tool, event, &synth_sample, machine) != 0) {
287 rc = -1;
288 break;
289 }
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200290 }
291
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200292 free(event);
David Ahern1e6d5322012-08-26 12:24:42 -0600293 return rc;
Arnaldo Carvalho de Melob7cece72010-01-13 13:22:17 -0200294}
295
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200296static int __event__synthesize_thread(union perf_event *comm_event,
297 union perf_event *mmap_event,
David Aherndefd8d32011-12-22 11:30:01 -0700298 pid_t pid, int full,
299 perf_event__handler_t process,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200300 struct perf_tool *tool,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200301 struct machine *machine)
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200302{
David Aherndefd8d32011-12-22 11:30:01 -0700303 pid_t tgid = perf_event__synthesize_comm(tool, comm_event, pid, full,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200304 process, machine);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200305 if (tgid == -1)
306 return -1;
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200307 return perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200308 process, machine);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200309}
310
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200311int perf_event__synthesize_thread_map(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200312 struct thread_map *threads,
Arnaldo Carvalho de Melo7c940c12011-02-11 11:45:54 -0200313 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200314 struct machine *machine)
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200315{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200316 union perf_event *comm_event, *mmap_event;
David Aherndefd8d32011-12-22 11:30:01 -0700317 int err = -1, thread, j;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200318
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200319 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200320 if (comm_event == NULL)
321 goto out;
322
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200323 mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200324 if (mmap_event == NULL)
325 goto out_free_comm;
326
Arnaldo Carvalho de Melo401b8e12011-02-10 12:52:47 -0200327 err = 0;
328 for (thread = 0; thread < threads->nr; ++thread) {
329 if (__event__synthesize_thread(comm_event, mmap_event,
David Aherndefd8d32011-12-22 11:30:01 -0700330 threads->map[thread], 0,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200331 process, tool, machine)) {
Arnaldo Carvalho de Melo401b8e12011-02-10 12:52:47 -0200332 err = -1;
333 break;
334 }
David Aherndefd8d32011-12-22 11:30:01 -0700335
336 /*
337 * comm.pid is set to thread group id by
338 * perf_event__synthesize_comm
339 */
340 if ((int) comm_event->comm.pid != threads->map[thread]) {
341 bool need_leader = true;
342
343 /* is thread group leader in thread_map? */
344 for (j = 0; j < threads->nr; ++j) {
345 if ((int) comm_event->comm.pid == threads->map[j]) {
346 need_leader = false;
347 break;
348 }
349 }
350
351 /* if not, generate events for it */
352 if (need_leader &&
353 __event__synthesize_thread(comm_event,
354 mmap_event,
355 comm_event->comm.pid, 0,
356 process, tool, machine)) {
357 err = -1;
358 break;
359 }
360 }
Arnaldo Carvalho de Melo401b8e12011-02-10 12:52:47 -0200361 }
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200362 free(mmap_event);
363out_free_comm:
364 free(comm_event);
365out:
366 return err;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200367}
368
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200369int perf_event__synthesize_threads(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200370 perf_event__handler_t process,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200371 struct machine *machine)
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200372{
373 DIR *proc;
374 struct dirent dirent, *next;
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200375 union perf_event *comm_event, *mmap_event;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200376 int err = -1;
377
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200378 comm_event = malloc(sizeof(comm_event->comm) + machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200379 if (comm_event == NULL)
380 goto out;
381
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200382 mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200383 if (mmap_event == NULL)
384 goto out_free_comm;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200385
386 proc = opendir("/proc");
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200387 if (proc == NULL)
388 goto out_free_mmap;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200389
390 while (!readdir_r(proc, &dirent, &next) && next) {
391 char *end;
392 pid_t pid = strtol(dirent.d_name, &end, 10);
393
394 if (*end) /* only interested in proper numerical dirents */
395 continue;
Arnaldo Carvalho de Meloba361c92012-10-17 18:50:13 -0300396 /*
397 * We may race with exiting thread, so don't stop just because
398 * one thread couldn't be synthesized.
399 */
400 __event__synthesize_thread(comm_event, mmap_event, pid, 1,
401 process, tool, machine);
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200402 }
403
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200404 err = 0;
David Ahern1e6d5322012-08-26 12:24:42 -0600405 closedir(proc);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200406out_free_mmap:
407 free(mmap_event);
408out_free_comm:
409 free(comm_event);
410out:
411 return err;
Arnaldo Carvalho de Melo234fbbf2009-10-26 19:23:18 -0200412}
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200413
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200414struct process_symbol_args {
415 const char *name;
416 u64 start;
417};
418
Arnaldo Carvalho de Melo3b01a412010-12-22 01:08:36 -0200419static int find_symbol_cb(void *arg, const char *name, char type,
Cody P Schafer82151522012-08-10 15:22:48 -0700420 u64 start)
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200421{
422 struct process_symbol_args *args = arg;
423
Arnaldo Carvalho de Melo881516e2010-01-15 18:08:27 -0200424 /*
425 * Must be a function or at least an alias, as in PARISC64, where "_text" is
426 * an 'A' to the same address as "_stext".
427 */
428 if (!(symbol_type__is_a(type, MAP__FUNCTION) ||
429 type == 'A') || strcmp(name, args->name))
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200430 return 0;
431
432 args->start = start;
433 return 1;
434}
435
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200436int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200437 perf_event__handler_t process,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200438 struct machine *machine,
439 const char *symbol_name)
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200440{
441 size_t size;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800442 const char *filename, *mmap_name;
443 char path[PATH_MAX];
444 char name_buff[PATH_MAX];
445 struct map *map;
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200446 int err;
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200447 /*
448 * We should get this from /sys/kernel/sections/.text, but till that is
449 * available use this, and after it is use this as a fallback for older
450 * kernels.
451 */
452 struct process_symbol_args args = { .name = symbol_name, };
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200453 union perf_event *event = zalloc((sizeof(event->mmap) +
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200454 machine->id_hdr_size));
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200455 if (event == NULL) {
456 pr_debug("Not enough memory synthesizing mmap event "
457 "for kernel modules\n");
458 return -1;
459 }
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200460
Arnaldo Carvalho de Melo48ea8f52010-04-27 21:19:05 -0300461 mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300462 if (machine__is_host(machine)) {
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800463 /*
464 * kernel uses PERF_RECORD_MISC_USER for user space maps,
465 * see kernel/perf_event.c __perf_event_mmap
466 */
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200467 event->header.misc = PERF_RECORD_MISC_KERNEL;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800468 filename = "/proc/kallsyms";
469 } else {
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200470 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300471 if (machine__is_default_guest(machine))
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800472 filename = (char *) symbol_conf.default_guest_kallsyms;
473 else {
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300474 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800475 filename = path;
476 }
477 }
478
Thomas Jarosch0b9e01a2013-01-25 11:20:47 +0100479 if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0) {
480 free(event);
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200481 return -ENOENT;
Thomas Jarosch0b9e01a2013-01-25 11:20:47 +0100482 }
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200483
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300484 map = machine->vmlinux_maps[MAP__FUNCTION];
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200485 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800486 "%s%s", mmap_name, symbol_name) + 1;
Irina Tirdea9ac3e482012-09-11 01:15:01 +0300487 size = PERF_ALIGN(size, sizeof(u64));
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200488 event->mmap.header.type = PERF_RECORD_MMAP;
489 event->mmap.header.size = (sizeof(event->mmap) -
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200490 (sizeof(event->mmap.filename) - size) + machine->id_hdr_size);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200491 event->mmap.pgoff = args.start;
492 event->mmap.start = map->start;
493 event->mmap.len = map->end - event->mmap.start;
494 event->mmap.pid = machine->pid;
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200495
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200496 err = process(tool, event, &synth_sample, machine);
Arnaldo Carvalho de Melo9c90a612010-12-02 10:25:28 -0200497 free(event);
498
499 return err;
Arnaldo Carvalho de Melo56b03f32010-01-05 16:50:31 -0200500}
501
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200502size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
503{
504 return fprintf(fp, ": %s:%d\n", event->comm.comm, event->comm.tid);
505}
506
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300507int perf_event__process_comm(struct perf_tool *tool __maybe_unused,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200508 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300509 struct perf_sample *sample __maybe_unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200510 struct machine *machine)
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200511{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300512 return machine__process_comm_event(machine, event);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200513}
514
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300515int perf_event__process_lost(struct perf_tool *tool __maybe_unused,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200516 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300517 struct perf_sample *sample __maybe_unused,
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300518 struct machine *machine)
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200519{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300520 return machine__process_lost_event(machine, event);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800521}
522
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200523size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
524{
525 return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %s\n",
526 event->mmap.pid, event->mmap.tid, event->mmap.start,
527 event->mmap.len, event->mmap.pgoff, event->mmap.filename);
528}
529
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300530int perf_event__process_mmap(struct perf_tool *tool __maybe_unused,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200531 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300532 struct perf_sample *sample __maybe_unused,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200533 struct machine *machine)
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800534{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300535 return machine__process_mmap_event(machine, event);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200536}
537
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200538size_t perf_event__fprintf_task(union perf_event *event, FILE *fp)
539{
540 return fprintf(fp, "(%d:%d):(%d:%d)\n",
541 event->fork.pid, event->fork.tid,
542 event->fork.ppid, event->fork.ptid);
543}
544
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300545int perf_event__process_fork(struct perf_tool *tool __maybe_unused,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200546 union perf_event *event,
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300547 struct perf_sample *sample __maybe_unused,
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300548 struct machine *machine)
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200549{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300550 return machine__process_fork_event(machine, event);
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200551}
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200552
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300553int perf_event__process_exit(struct perf_tool *tool __maybe_unused,
554 union perf_event *event,
555 struct perf_sample *sample __maybe_unused,
556 struct machine *machine)
557{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300558 return machine__process_exit_event(machine, event);
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300559}
560
Arnaldo Carvalho de Melo482ad892011-12-02 11:06:37 -0200561size_t perf_event__fprintf(union perf_event *event, FILE *fp)
562{
563 size_t ret = fprintf(fp, "PERF_RECORD_%s",
564 perf_event__name(event->header.type));
565
566 switch (event->header.type) {
567 case PERF_RECORD_COMM:
568 ret += perf_event__fprintf_comm(event, fp);
569 break;
570 case PERF_RECORD_FORK:
571 case PERF_RECORD_EXIT:
572 ret += perf_event__fprintf_task(event, fp);
573 break;
574 case PERF_RECORD_MMAP:
575 ret += perf_event__fprintf_mmap(event, fp);
576 break;
577 default:
578 ret += fprintf(fp, "\n");
579 }
580
581 return ret;
582}
583
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300584int perf_event__process(struct perf_tool *tool __maybe_unused,
585 union perf_event *event,
586 struct perf_sample *sample __maybe_unused,
587 struct machine *machine)
Srikar Dronamrajub83f9202010-08-02 18:08:51 +0530588{
Arnaldo Carvalho de Melob0a7d1a2012-10-06 16:26:02 -0300589 return machine__process_event(machine, event);
Srikar Dronamrajub83f9202010-08-02 18:08:51 +0530590}
591
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200592void thread__find_addr_map(struct thread *self,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200593 struct machine *machine, u8 cpumode,
594 enum map_type type, u64 addr,
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300595 struct addr_location *al, symbol_filter_t filter)
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200596{
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -0200597 struct map_groups *mg = &self->mg;
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300598 bool load_map = false;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200599
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -0200600 al->thread = self;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200601 al->addr = addr;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800602 al->cpumode = cpumode;
603 al->filtered = false;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200604
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200605 if (machine == NULL) {
606 al->map = NULL;
607 return;
608 }
609
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800610 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200611 al->level = 'k';
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300612 mg = &machine->kmaps;
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300613 load_map = true;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800614 } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200615 al->level = '.';
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800616 } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
617 al->level = 'g';
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300618 mg = &machine->kmaps;
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300619 load_map = true;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800620 } else {
621 /*
622 * 'u' means guest os user space.
623 * TODO: We don't support guest user space. Might support late.
624 */
625 if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest)
626 al->level = 'u';
627 else
628 al->level = 'H';
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200629 al->map = NULL;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800630
631 if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
632 cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
633 !perf_guest)
634 al->filtered = true;
635 if ((cpumode == PERF_RECORD_MISC_USER ||
636 cpumode == PERF_RECORD_MISC_KERNEL) &&
637 !perf_host)
638 al->filtered = true;
639
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200640 return;
641 }
642try_again:
Arnaldo Carvalho de Melo9958e1f2009-12-11 14:50:36 -0200643 al->map = map_groups__find(mg, type, al->addr);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200644 if (al->map == NULL) {
645 /*
646 * If this is outside of all known maps, and is a negative
647 * address, try to look it up in the kernel dso, as it might be
648 * a vsyscall or vdso (which executes in user-mode).
649 *
650 * XXX This is nasty, we should have a symbol list in the
651 * "[vdso]" dso, but for now lets use the old trick of looking
652 * in the whole kernel symbol list.
653 */
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800654 if ((long long)al->addr < 0 &&
Andrew Lutomirski6c6804fb2011-03-24 00:36:56 -0400655 cpumode == PERF_RECORD_MISC_USER &&
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -0300656 machine && mg != &machine->kmaps) {
657 mg = &machine->kmaps;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200658 goto try_again;
659 }
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300660 } else {
661 /*
662 * Kernel maps might be changed when loading symbols so loading
663 * must be done prior to using kernel maps.
664 */
665 if (load_map)
666 map__load(al->map, filter);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200667 al->addr = al->map->map_ip(al->map, al->addr);
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300668 }
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200669}
670
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200671void thread__find_addr_location(struct thread *thread, struct machine *machine,
672 u8 cpumode, enum map_type type, u64 addr,
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200673 struct addr_location *al,
674 symbol_filter_t filter)
675{
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300676 thread__find_addr_map(thread, machine, cpumode, type, addr, al, filter);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200677 if (al->map != NULL)
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200678 al->sym = map__find_symbol(al->map, al->addr, filter);
Arnaldo Carvalho de Melo59ee68e2010-01-14 23:45:29 -0200679 else
680 al->sym = NULL;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200681}
682
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200683int perf_event__preprocess_sample(const union perf_event *event,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200684 struct machine *machine,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200685 struct addr_location *al,
686 struct perf_sample *sample,
687 symbol_filter_t filter)
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200688{
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -0200689 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200690 struct thread *thread = machine__findnew_thread(machine, event->ip.pid);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200691
692 if (thread == NULL)
693 return -1;
694
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200695 if (symbol_conf.comm_list &&
696 !strlist__has_entry(symbol_conf.comm_list, thread->comm))
697 goto out_filtered;
698
Adrian Hunter38051232013-07-04 16:20:31 +0300699 dump_printf(" ... thread: %s:%d\n", thread->comm, thread->tid);
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300700 /*
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200701 * Have we already created the kernel maps for this machine?
Arnaldo Carvalho de Melo1f626bc2010-05-09 19:57:08 -0300702 *
703 * This should have happened earlier, when we processed the kernel MMAP
704 * events, but for older perf.data files there was no such thing, so do
705 * it now.
706 */
707 if (cpumode == PERF_RECORD_MISC_KERNEL &&
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200708 machine->vmlinux_maps[MAP__FUNCTION] == NULL)
709 machine__create_kernel_maps(machine);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200710
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200711 thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
Adrian Hunter5b7ba822013-08-07 14:38:46 +0300712 event->ip.ip, al, filter);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200713 dump_printf(" ...... dso: %s\n",
714 al->map ? al->map->dso->long_name :
715 al->level == 'H' ? "[hypervisor]" : "<not found>");
Arnaldo Carvalho de Melo96415e42010-03-24 16:40:15 -0300716 al->sym = NULL;
Arnaldo Carvalho de Melo8d50e5b2011-01-29 13:02:00 -0200717 al->cpu = sample->cpu;
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200718
Arnaldo Carvalho de Melo96415e42010-03-24 16:40:15 -0300719 if (al->map) {
Namhyung Kimcb8f4e92011-12-13 00:16:55 +0900720 struct dso *dso = al->map->dso;
721
Arnaldo Carvalho de Melo96415e42010-03-24 16:40:15 -0300722 if (symbol_conf.dso_list &&
Namhyung Kimcb8f4e92011-12-13 00:16:55 +0900723 (!dso || !(strlist__has_entry(symbol_conf.dso_list,
724 dso->short_name) ||
725 (dso->short_name != dso->long_name &&
726 strlist__has_entry(symbol_conf.dso_list,
727 dso->long_name)))))
Arnaldo Carvalho de Melo96415e42010-03-24 16:40:15 -0300728 goto out_filtered;
Arnaldo Carvalho de Melo96415e42010-03-24 16:40:15 -0300729
730 al->sym = map__find_symbol(al->map, al->addr, filter);
731 }
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200732
Feng Tang1500b932012-09-07 16:42:23 +0800733 if (symbol_conf.sym_list &&
734 (!al->sym || !strlist__has_entry(symbol_conf.sym_list,
735 al->sym->name)))
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200736 goto out_filtered;
737
Arnaldo Carvalho de Meloc410a332009-12-15 20:04:41 -0200738 return 0;
739
740out_filtered:
741 al->filtered = true;
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -0200742 return 0;
743}