event.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. #include <linux/types.h>
  2. #include "event.h"
  3. #include "debug.h"
  4. #include "session.h"
  5. #include "sort.h"
  6. #include "string.h"
  7. #include "strlist.h"
  8. #include "thread.h"
  9. static pid_t event__synthesize_comm(pid_t pid, int full,
  10. event__handler_t process,
  11. struct perf_session *session)
  12. {
  13. event_t ev;
  14. char filename[PATH_MAX];
  15. char bf[BUFSIZ];
  16. FILE *fp;
  17. size_t size = 0;
  18. DIR *tasks;
  19. struct dirent dirent, *next;
  20. pid_t tgid = 0;
  21. snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
  22. fp = fopen(filename, "r");
  23. if (fp == NULL) {
  24. out_race:
  25. /*
  26. * We raced with a task exiting - just return:
  27. */
  28. pr_debug("couldn't open %s\n", filename);
  29. return 0;
  30. }
  31. memset(&ev.comm, 0, sizeof(ev.comm));
  32. while (!ev.comm.comm[0] || !ev.comm.pid) {
  33. if (fgets(bf, sizeof(bf), fp) == NULL)
  34. goto out_failure;
  35. if (memcmp(bf, "Name:", 5) == 0) {
  36. char *name = bf + 5;
  37. while (*name && isspace(*name))
  38. ++name;
  39. size = strlen(name) - 1;
  40. memcpy(ev.comm.comm, name, size++);
  41. } else if (memcmp(bf, "Tgid:", 5) == 0) {
  42. char *tgids = bf + 5;
  43. while (*tgids && isspace(*tgids))
  44. ++tgids;
  45. tgid = ev.comm.pid = atoi(tgids);
  46. }
  47. }
  48. ev.comm.header.type = PERF_RECORD_COMM;
  49. size = ALIGN(size, sizeof(u64));
  50. ev.comm.header.size = sizeof(ev.comm) - (sizeof(ev.comm.comm) - size);
  51. if (!full) {
  52. ev.comm.tid = pid;
  53. process(&ev, session);
  54. goto out_fclose;
  55. }
  56. snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
  57. tasks = opendir(filename);
  58. if (tasks == NULL)
  59. goto out_race;
  60. while (!readdir_r(tasks, &dirent, &next) && next) {
  61. char *end;
  62. pid = strtol(dirent.d_name, &end, 10);
  63. if (*end)
  64. continue;
  65. ev.comm.tid = pid;
  66. process(&ev, session);
  67. }
  68. closedir(tasks);
  69. out_fclose:
  70. fclose(fp);
  71. return tgid;
  72. out_failure:
  73. pr_warning("couldn't get COMM and pgid, malformed %s\n", filename);
  74. return -1;
  75. }
  76. static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
  77. event__handler_t process,
  78. struct perf_session *session)
  79. {
  80. char filename[PATH_MAX];
  81. FILE *fp;
  82. snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
  83. fp = fopen(filename, "r");
  84. if (fp == NULL) {
  85. /*
  86. * We raced with a task exiting - just return:
  87. */
  88. pr_debug("couldn't open %s\n", filename);
  89. return -1;
  90. }
  91. while (1) {
  92. char bf[BUFSIZ], *pbf = bf;
  93. event_t ev = {
  94. .header = {
  95. .type = PERF_RECORD_MMAP,
  96. /*
  97. * Just like the kernel, see __perf_event_mmap
  98. * in kernel/perf_event.c
  99. */
  100. .misc = PERF_RECORD_MISC_USER,
  101. },
  102. };
  103. int n;
  104. size_t size;
  105. if (fgets(bf, sizeof(bf), fp) == NULL)
  106. break;
  107. /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
  108. n = hex2u64(pbf, &ev.mmap.start);
  109. if (n < 0)
  110. continue;
  111. pbf += n + 1;
  112. n = hex2u64(pbf, &ev.mmap.len);
  113. if (n < 0)
  114. continue;
  115. pbf += n + 3;
  116. if (*pbf == 'x') { /* vm_exec */
  117. u64 vm_pgoff;
  118. char *execname = strchr(bf, '/');
  119. /* Catch VDSO */
  120. if (execname == NULL)
  121. execname = strstr(bf, "[vdso]");
  122. if (execname == NULL)
  123. continue;
  124. pbf += 3;
  125. n = hex2u64(pbf, &vm_pgoff);
  126. /* pgoff is in bytes, not pages */
  127. if (n >= 0)
  128. ev.mmap.pgoff = vm_pgoff << getpagesize();
  129. else
  130. ev.mmap.pgoff = 0;
  131. size = strlen(execname);
  132. execname[size - 1] = '\0'; /* Remove \n */
  133. memcpy(ev.mmap.filename, execname, size);
  134. size = ALIGN(size, sizeof(u64));
  135. ev.mmap.len -= ev.mmap.start;
  136. ev.mmap.header.size = (sizeof(ev.mmap) -
  137. (sizeof(ev.mmap.filename) - size));
  138. ev.mmap.pid = tgid;
  139. ev.mmap.tid = pid;
  140. process(&ev, session);
  141. }
  142. }
  143. fclose(fp);
  144. return 0;
  145. }
  146. int event__synthesize_modules(event__handler_t process,
  147. struct perf_session *session,
  148. struct machine *machine)
  149. {
  150. struct rb_node *nd;
  151. struct map_groups *kmaps = &machine->kmaps;
  152. u16 misc;
  153. /*
  154. * kernel uses 0 for user space maps, see kernel/perf_event.c
  155. * __perf_event_mmap
  156. */
  157. if (machine__is_host(machine))
  158. misc = PERF_RECORD_MISC_KERNEL;
  159. else
  160. misc = PERF_RECORD_MISC_GUEST_KERNEL;
  161. for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]);
  162. nd; nd = rb_next(nd)) {
  163. event_t ev;
  164. size_t size;
  165. struct map *pos = rb_entry(nd, struct map, rb_node);
  166. if (pos->dso->kernel)
  167. continue;
  168. size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
  169. memset(&ev, 0, sizeof(ev));
  170. ev.mmap.header.misc = misc;
  171. ev.mmap.header.type = PERF_RECORD_MMAP;
  172. ev.mmap.header.size = (sizeof(ev.mmap) -
  173. (sizeof(ev.mmap.filename) - size));
  174. ev.mmap.start = pos->start;
  175. ev.mmap.len = pos->end - pos->start;
  176. ev.mmap.pid = machine->pid;
  177. memcpy(ev.mmap.filename, pos->dso->long_name,
  178. pos->dso->long_name_len + 1);
  179. process(&ev, session);
  180. }
  181. return 0;
  182. }
  183. int event__synthesize_thread(pid_t pid, event__handler_t process,
  184. struct perf_session *session)
  185. {
  186. pid_t tgid = event__synthesize_comm(pid, 1, process, session);
  187. if (tgid == -1)
  188. return -1;
  189. return event__synthesize_mmap_events(pid, tgid, process, session);
  190. }
  191. void event__synthesize_threads(event__handler_t process,
  192. struct perf_session *session)
  193. {
  194. DIR *proc;
  195. struct dirent dirent, *next;
  196. proc = opendir("/proc");
  197. while (!readdir_r(proc, &dirent, &next) && next) {
  198. char *end;
  199. pid_t pid = strtol(dirent.d_name, &end, 10);
  200. if (*end) /* only interested in proper numerical dirents */
  201. continue;
  202. event__synthesize_thread(pid, process, session);
  203. }
  204. closedir(proc);
  205. }
  206. struct process_symbol_args {
  207. const char *name;
  208. u64 start;
  209. };
  210. static int find_symbol_cb(void *arg, const char *name, char type, u64 start)
  211. {
  212. struct process_symbol_args *args = arg;
  213. /*
  214. * Must be a function or at least an alias, as in PARISC64, where "_text" is
  215. * an 'A' to the same address as "_stext".
  216. */
  217. if (!(symbol_type__is_a(type, MAP__FUNCTION) ||
  218. type == 'A') || strcmp(name, args->name))
  219. return 0;
  220. args->start = start;
  221. return 1;
  222. }
  223. int event__synthesize_kernel_mmap(event__handler_t process,
  224. struct perf_session *session,
  225. struct machine *machine,
  226. const char *symbol_name)
  227. {
  228. size_t size;
  229. const char *filename, *mmap_name;
  230. char path[PATH_MAX];
  231. char name_buff[PATH_MAX];
  232. struct map *map;
  233. event_t ev = {
  234. .header = {
  235. .type = PERF_RECORD_MMAP,
  236. },
  237. };
  238. /*
  239. * We should get this from /sys/kernel/sections/.text, but till that is
  240. * available use this, and after it is use this as a fallback for older
  241. * kernels.
  242. */
  243. struct process_symbol_args args = { .name = symbol_name, };
  244. mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
  245. if (machine__is_host(machine)) {
  246. /*
  247. * kernel uses PERF_RECORD_MISC_USER for user space maps,
  248. * see kernel/perf_event.c __perf_event_mmap
  249. */
  250. ev.header.misc = PERF_RECORD_MISC_KERNEL;
  251. filename = "/proc/kallsyms";
  252. } else {
  253. ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
  254. if (machine__is_default_guest(machine))
  255. filename = (char *) symbol_conf.default_guest_kallsyms;
  256. else {
  257. sprintf(path, "%s/proc/kallsyms", machine->root_dir);
  258. filename = path;
  259. }
  260. }
  261. if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0)
  262. return -ENOENT;
  263. map = machine->vmlinux_maps[MAP__FUNCTION];
  264. size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename),
  265. "%s%s", mmap_name, symbol_name) + 1;
  266. size = ALIGN(size, sizeof(u64));
  267. ev.mmap.header.size = (sizeof(ev.mmap) -
  268. (sizeof(ev.mmap.filename) - size));
  269. ev.mmap.pgoff = args.start;
  270. ev.mmap.start = map->start;
  271. ev.mmap.len = map->end - ev.mmap.start;
  272. ev.mmap.pid = machine->pid;
  273. return process(&ev, session);
  274. }
  275. static void thread__comm_adjust(struct thread *self)
  276. {
  277. char *comm = self->comm;
  278. if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
  279. (!symbol_conf.comm_list ||
  280. strlist__has_entry(symbol_conf.comm_list, comm))) {
  281. unsigned int slen = strlen(comm);
  282. if (slen > comms__col_width) {
  283. comms__col_width = slen;
  284. threads__col_width = slen + 6;
  285. }
  286. }
  287. }
  288. static int thread__set_comm_adjust(struct thread *self, const char *comm)
  289. {
  290. int ret = thread__set_comm(self, comm);
  291. if (ret)
  292. return ret;
  293. thread__comm_adjust(self);
  294. return 0;
  295. }
  296. int event__process_comm(event_t *self, struct perf_session *session)
  297. {
  298. struct thread *thread = perf_session__findnew(session, self->comm.pid);
  299. dump_printf(": %s:%d\n", self->comm.comm, self->comm.pid);
  300. if (thread == NULL || thread__set_comm_adjust(thread, self->comm.comm)) {
  301. dump_printf("problem processing PERF_RECORD_COMM, skipping event.\n");
  302. return -1;
  303. }
  304. return 0;
  305. }
  306. int event__process_lost(event_t *self, struct perf_session *session)
  307. {
  308. dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost);
  309. session->events_stats.lost += self->lost.lost;
  310. return 0;
  311. }
  312. static void event_set_kernel_mmap_len(struct map **maps, event_t *self)
  313. {
  314. maps[MAP__FUNCTION]->start = self->mmap.start;
  315. maps[MAP__FUNCTION]->end = self->mmap.start + self->mmap.len;
  316. /*
  317. * Be a bit paranoid here, some perf.data file came with
  318. * a zero sized synthesized MMAP event for the kernel.
  319. */
  320. if (maps[MAP__FUNCTION]->end == 0)
  321. maps[MAP__FUNCTION]->end = ~0UL;
  322. }
  323. static int event__process_kernel_mmap(event_t *self,
  324. struct perf_session *session)
  325. {
  326. struct map *map;
  327. char kmmap_prefix[PATH_MAX];
  328. struct machine *machine;
  329. enum dso_kernel_type kernel_type;
  330. bool is_kernel_mmap;
  331. machine = perf_session__findnew_machine(session, self->mmap.pid);
  332. if (!machine) {
  333. pr_err("Can't find id %d's machine\n", self->mmap.pid);
  334. goto out_problem;
  335. }
  336. machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
  337. if (machine__is_host(machine))
  338. kernel_type = DSO_TYPE_KERNEL;
  339. else
  340. kernel_type = DSO_TYPE_GUEST_KERNEL;
  341. is_kernel_mmap = memcmp(self->mmap.filename,
  342. kmmap_prefix,
  343. strlen(kmmap_prefix)) == 0;
  344. if (self->mmap.filename[0] == '/' ||
  345. (!is_kernel_mmap && self->mmap.filename[0] == '[')) {
  346. char short_module_name[1024];
  347. char *name, *dot;
  348. if (self->mmap.filename[0] == '/') {
  349. name = strrchr(self->mmap.filename, '/');
  350. if (name == NULL)
  351. goto out_problem;
  352. ++name; /* skip / */
  353. dot = strrchr(name, '.');
  354. if (dot == NULL)
  355. goto out_problem;
  356. snprintf(short_module_name, sizeof(short_module_name),
  357. "[%.*s]", (int)(dot - name), name);
  358. strxfrchar(short_module_name, '-', '_');
  359. } else
  360. strcpy(short_module_name, self->mmap.filename);
  361. map = machine__new_module(machine, self->mmap.start,
  362. self->mmap.filename);
  363. if (map == NULL)
  364. goto out_problem;
  365. name = strdup(short_module_name);
  366. if (name == NULL)
  367. goto out_problem;
  368. map->dso->short_name = name;
  369. map->end = map->start + self->mmap.len;
  370. } else if (is_kernel_mmap) {
  371. const char *symbol_name = (self->mmap.filename +
  372. strlen(kmmap_prefix));
  373. /*
  374. * Should be there already, from the build-id table in
  375. * the header.
  376. */
  377. struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
  378. kmmap_prefix);
  379. if (kernel == NULL)
  380. goto out_problem;
  381. kernel->kernel = kernel_type;
  382. if (__machine__create_kernel_maps(machine, kernel) < 0)
  383. goto out_problem;
  384. event_set_kernel_mmap_len(machine->vmlinux_maps, self);
  385. perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
  386. symbol_name,
  387. self->mmap.pgoff);
  388. if (machine__is_default_guest(machine)) {
  389. /*
  390. * preload dso of guest kernel and modules
  391. */
  392. dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
  393. NULL);
  394. }
  395. }
  396. return 0;
  397. out_problem:
  398. return -1;
  399. }
  400. int event__process_mmap(event_t *self, struct perf_session *session)
  401. {
  402. struct machine *machine;
  403. struct thread *thread;
  404. struct map *map;
  405. u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  406. int ret = 0;
  407. dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n",
  408. self->mmap.pid, self->mmap.tid, self->mmap.start,
  409. self->mmap.len, self->mmap.pgoff, self->mmap.filename);
  410. if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
  411. cpumode == PERF_RECORD_MISC_KERNEL) {
  412. ret = event__process_kernel_mmap(self, session);
  413. if (ret < 0)
  414. goto out_problem;
  415. return 0;
  416. }
  417. thread = perf_session__findnew(session, self->mmap.pid);
  418. machine = perf_session__find_host_machine(session);
  419. map = map__new(&machine->user_dsos, self->mmap.start,
  420. self->mmap.len, self->mmap.pgoff,
  421. self->mmap.pid, self->mmap.filename,
  422. MAP__FUNCTION, session->cwd, session->cwdlen);
  423. if (thread == NULL || map == NULL)
  424. goto out_problem;
  425. thread__insert_map(thread, map);
  426. return 0;
  427. out_problem:
  428. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  429. return 0;
  430. }
  431. int event__process_task(event_t *self, struct perf_session *session)
  432. {
  433. struct thread *thread = perf_session__findnew(session, self->fork.pid);
  434. struct thread *parent = perf_session__findnew(session, self->fork.ppid);
  435. dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
  436. self->fork.ppid, self->fork.ptid);
  437. /*
  438. * A thread clone will have the same PID for both parent and child.
  439. */
  440. if (thread == parent)
  441. return 0;
  442. if (self->header.type == PERF_RECORD_EXIT)
  443. return 0;
  444. if (thread == NULL || parent == NULL ||
  445. thread__fork(thread, parent) < 0) {
  446. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  447. return -1;
  448. }
  449. return 0;
  450. }
  451. void thread__find_addr_map(struct thread *self,
  452. struct perf_session *session, u8 cpumode,
  453. enum map_type type, pid_t pid, u64 addr,
  454. struct addr_location *al)
  455. {
  456. struct map_groups *mg = &self->mg;
  457. struct machine *machine = NULL;
  458. al->thread = self;
  459. al->addr = addr;
  460. al->cpumode = cpumode;
  461. al->filtered = false;
  462. if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
  463. al->level = 'k';
  464. machine = perf_session__find_host_machine(session);
  465. mg = &machine->kmaps;
  466. } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
  467. al->level = '.';
  468. machine = perf_session__find_host_machine(session);
  469. } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
  470. al->level = 'g';
  471. machine = perf_session__find_machine(session, pid);
  472. if (!machine) {
  473. al->map = NULL;
  474. return;
  475. }
  476. mg = &machine->kmaps;
  477. } else {
  478. /*
  479. * 'u' means guest os user space.
  480. * TODO: We don't support guest user space. Might support late.
  481. */
  482. if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest)
  483. al->level = 'u';
  484. else
  485. al->level = 'H';
  486. al->map = NULL;
  487. if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
  488. cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
  489. !perf_guest)
  490. al->filtered = true;
  491. if ((cpumode == PERF_RECORD_MISC_USER ||
  492. cpumode == PERF_RECORD_MISC_KERNEL) &&
  493. !perf_host)
  494. al->filtered = true;
  495. return;
  496. }
  497. try_again:
  498. al->map = map_groups__find(mg, type, al->addr);
  499. if (al->map == NULL) {
  500. /*
  501. * If this is outside of all known maps, and is a negative
  502. * address, try to look it up in the kernel dso, as it might be
  503. * a vsyscall or vdso (which executes in user-mode).
  504. *
  505. * XXX This is nasty, we should have a symbol list in the
  506. * "[vdso]" dso, but for now lets use the old trick of looking
  507. * in the whole kernel symbol list.
  508. */
  509. if ((long long)al->addr < 0 &&
  510. cpumode == PERF_RECORD_MISC_KERNEL &&
  511. machine && mg != &machine->kmaps) {
  512. mg = &machine->kmaps;
  513. goto try_again;
  514. }
  515. } else
  516. al->addr = al->map->map_ip(al->map, al->addr);
  517. }
  518. void thread__find_addr_location(struct thread *self,
  519. struct perf_session *session, u8 cpumode,
  520. enum map_type type, pid_t pid, u64 addr,
  521. struct addr_location *al,
  522. symbol_filter_t filter)
  523. {
  524. thread__find_addr_map(self, session, cpumode, type, pid, addr, al);
  525. if (al->map != NULL)
  526. al->sym = map__find_symbol(al->map, al->addr, filter);
  527. else
  528. al->sym = NULL;
  529. }
  530. static void dso__calc_col_width(struct dso *self)
  531. {
  532. if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
  533. (!symbol_conf.dso_list ||
  534. strlist__has_entry(symbol_conf.dso_list, self->name))) {
  535. unsigned int slen = strlen(self->name);
  536. if (slen > dsos__col_width)
  537. dsos__col_width = slen;
  538. }
  539. self->slen_calculated = 1;
  540. }
  541. int event__preprocess_sample(const event_t *self, struct perf_session *session,
  542. struct addr_location *al, symbol_filter_t filter)
  543. {
  544. u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  545. struct thread *thread = perf_session__findnew(session, self->ip.pid);
  546. if (thread == NULL)
  547. return -1;
  548. if (symbol_conf.comm_list &&
  549. !strlist__has_entry(symbol_conf.comm_list, thread->comm))
  550. goto out_filtered;
  551. dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
  552. thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
  553. self->ip.pid, self->ip.ip, al);
  554. dump_printf(" ...... dso: %s\n",
  555. al->map ? al->map->dso->long_name :
  556. al->level == 'H' ? "[hypervisor]" : "<not found>");
  557. al->sym = NULL;
  558. if (al->map) {
  559. if (symbol_conf.dso_list &&
  560. (!al->map || !al->map->dso ||
  561. !(strlist__has_entry(symbol_conf.dso_list,
  562. al->map->dso->short_name) ||
  563. (al->map->dso->short_name != al->map->dso->long_name &&
  564. strlist__has_entry(symbol_conf.dso_list,
  565. al->map->dso->long_name)))))
  566. goto out_filtered;
  567. /*
  568. * We have to do this here as we may have a dso with no symbol
  569. * hit that has a name longer than the ones with symbols
  570. * sampled.
  571. */
  572. if (!sort_dso.elide && !al->map->dso->slen_calculated)
  573. dso__calc_col_width(al->map->dso);
  574. al->sym = map__find_symbol(al->map, al->addr, filter);
  575. }
  576. if (symbol_conf.sym_list && al->sym &&
  577. !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
  578. goto out_filtered;
  579. return 0;
  580. out_filtered:
  581. al->filtered = true;
  582. return 0;
  583. }
  584. int event__parse_sample(event_t *event, u64 type, struct sample_data *data)
  585. {
  586. u64 *array = event->sample.array;
  587. if (type & PERF_SAMPLE_IP) {
  588. data->ip = event->ip.ip;
  589. array++;
  590. }
  591. if (type & PERF_SAMPLE_TID) {
  592. u32 *p = (u32 *)array;
  593. data->pid = p[0];
  594. data->tid = p[1];
  595. array++;
  596. }
  597. if (type & PERF_SAMPLE_TIME) {
  598. data->time = *array;
  599. array++;
  600. }
  601. if (type & PERF_SAMPLE_ADDR) {
  602. data->addr = *array;
  603. array++;
  604. }
  605. data->id = -1ULL;
  606. if (type & PERF_SAMPLE_ID) {
  607. data->id = *array;
  608. array++;
  609. }
  610. if (type & PERF_SAMPLE_STREAM_ID) {
  611. data->stream_id = *array;
  612. array++;
  613. }
  614. if (type & PERF_SAMPLE_CPU) {
  615. u32 *p = (u32 *)array;
  616. data->cpu = *p;
  617. array++;
  618. }
  619. if (type & PERF_SAMPLE_PERIOD) {
  620. data->period = *array;
  621. array++;
  622. }
  623. if (type & PERF_SAMPLE_READ) {
  624. pr_debug("PERF_SAMPLE_READ is unsuported for now\n");
  625. return -1;
  626. }
  627. if (type & PERF_SAMPLE_CALLCHAIN) {
  628. data->callchain = (struct ip_callchain *)array;
  629. array += 1 + data->callchain->nr;
  630. }
  631. if (type & PERF_SAMPLE_RAW) {
  632. u32 *p = (u32 *)array;
  633. data->raw_size = *p;
  634. p++;
  635. data->raw_data = p;
  636. }
  637. return 0;
  638. }