event.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. machine = perf_session__find_host_machine(session);
  418. if (machine == NULL)
  419. goto out_problem;
  420. thread = perf_session__findnew(session, self->mmap.pid);
  421. map = map__new(&machine->user_dsos, self->mmap.start,
  422. self->mmap.len, self->mmap.pgoff,
  423. self->mmap.pid, self->mmap.filename,
  424. MAP__FUNCTION, session->cwd, session->cwdlen);
  425. if (thread == NULL || map == NULL)
  426. goto out_problem;
  427. thread__insert_map(thread, map);
  428. return 0;
  429. out_problem:
  430. dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
  431. return 0;
  432. }
  433. int event__process_task(event_t *self, struct perf_session *session)
  434. {
  435. struct thread *thread = perf_session__findnew(session, self->fork.pid);
  436. struct thread *parent = perf_session__findnew(session, self->fork.ppid);
  437. dump_printf("(%d:%d):(%d:%d)\n", self->fork.pid, self->fork.tid,
  438. self->fork.ppid, self->fork.ptid);
  439. /*
  440. * A thread clone will have the same PID for both parent and child.
  441. */
  442. if (thread == parent)
  443. return 0;
  444. if (self->header.type == PERF_RECORD_EXIT)
  445. return 0;
  446. if (thread == NULL || parent == NULL ||
  447. thread__fork(thread, parent) < 0) {
  448. dump_printf("problem processing PERF_RECORD_FORK, skipping event.\n");
  449. return -1;
  450. }
  451. return 0;
  452. }
  453. void thread__find_addr_map(struct thread *self,
  454. struct perf_session *session, u8 cpumode,
  455. enum map_type type, pid_t pid, u64 addr,
  456. struct addr_location *al)
  457. {
  458. struct map_groups *mg = &self->mg;
  459. struct machine *machine = NULL;
  460. al->thread = self;
  461. al->addr = addr;
  462. al->cpumode = cpumode;
  463. al->filtered = false;
  464. if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
  465. al->level = 'k';
  466. machine = perf_session__find_host_machine(session);
  467. if (machine == NULL) {
  468. al->map = NULL;
  469. return;
  470. }
  471. mg = &machine->kmaps;
  472. } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
  473. al->level = '.';
  474. machine = perf_session__find_host_machine(session);
  475. } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
  476. al->level = 'g';
  477. machine = perf_session__find_machine(session, pid);
  478. if (machine == NULL) {
  479. al->map = NULL;
  480. return;
  481. }
  482. mg = &machine->kmaps;
  483. } else {
  484. /*
  485. * 'u' means guest os user space.
  486. * TODO: We don't support guest user space. Might support late.
  487. */
  488. if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest)
  489. al->level = 'u';
  490. else
  491. al->level = 'H';
  492. al->map = NULL;
  493. if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
  494. cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
  495. !perf_guest)
  496. al->filtered = true;
  497. if ((cpumode == PERF_RECORD_MISC_USER ||
  498. cpumode == PERF_RECORD_MISC_KERNEL) &&
  499. !perf_host)
  500. al->filtered = true;
  501. return;
  502. }
  503. try_again:
  504. al->map = map_groups__find(mg, type, al->addr);
  505. if (al->map == NULL) {
  506. /*
  507. * If this is outside of all known maps, and is a negative
  508. * address, try to look it up in the kernel dso, as it might be
  509. * a vsyscall or vdso (which executes in user-mode).
  510. *
  511. * XXX This is nasty, we should have a symbol list in the
  512. * "[vdso]" dso, but for now lets use the old trick of looking
  513. * in the whole kernel symbol list.
  514. */
  515. if ((long long)al->addr < 0 &&
  516. cpumode == PERF_RECORD_MISC_KERNEL &&
  517. machine && mg != &machine->kmaps) {
  518. mg = &machine->kmaps;
  519. goto try_again;
  520. }
  521. } else
  522. al->addr = al->map->map_ip(al->map, al->addr);
  523. }
  524. void thread__find_addr_location(struct thread *self,
  525. struct perf_session *session, u8 cpumode,
  526. enum map_type type, pid_t pid, u64 addr,
  527. struct addr_location *al,
  528. symbol_filter_t filter)
  529. {
  530. thread__find_addr_map(self, session, cpumode, type, pid, addr, al);
  531. if (al->map != NULL)
  532. al->sym = map__find_symbol(al->map, al->addr, filter);
  533. else
  534. al->sym = NULL;
  535. }
  536. static void dso__calc_col_width(struct dso *self)
  537. {
  538. if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
  539. (!symbol_conf.dso_list ||
  540. strlist__has_entry(symbol_conf.dso_list, self->name))) {
  541. u16 slen = self->short_name_len;
  542. if (verbose)
  543. slen = self->long_name_len;
  544. if (dsos__col_width < slen)
  545. dsos__col_width = slen;
  546. }
  547. self->slen_calculated = 1;
  548. }
  549. int event__preprocess_sample(const event_t *self, struct perf_session *session,
  550. struct addr_location *al, symbol_filter_t filter)
  551. {
  552. u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  553. struct thread *thread = perf_session__findnew(session, self->ip.pid);
  554. if (thread == NULL)
  555. return -1;
  556. if (symbol_conf.comm_list &&
  557. !strlist__has_entry(symbol_conf.comm_list, thread->comm))
  558. goto out_filtered;
  559. dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
  560. /*
  561. * Have we already created the kernel maps for the host machine?
  562. *
  563. * This should have happened earlier, when we processed the kernel MMAP
  564. * events, but for older perf.data files there was no such thing, so do
  565. * it now.
  566. */
  567. if (cpumode == PERF_RECORD_MISC_KERNEL &&
  568. session->host_machine.vmlinux_maps[MAP__FUNCTION] == NULL)
  569. machine__create_kernel_maps(&session->host_machine);
  570. thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
  571. self->ip.pid, self->ip.ip, al);
  572. dump_printf(" ...... dso: %s\n",
  573. al->map ? al->map->dso->long_name :
  574. al->level == 'H' ? "[hypervisor]" : "<not found>");
  575. al->sym = NULL;
  576. if (al->map) {
  577. if (symbol_conf.dso_list &&
  578. (!al->map || !al->map->dso ||
  579. !(strlist__has_entry(symbol_conf.dso_list,
  580. al->map->dso->short_name) ||
  581. (al->map->dso->short_name != al->map->dso->long_name &&
  582. strlist__has_entry(symbol_conf.dso_list,
  583. al->map->dso->long_name)))))
  584. goto out_filtered;
  585. /*
  586. * We have to do this here as we may have a dso with no symbol
  587. * hit that has a name longer than the ones with symbols
  588. * sampled.
  589. */
  590. if (!sort_dso.elide && !al->map->dso->slen_calculated)
  591. dso__calc_col_width(al->map->dso);
  592. al->sym = map__find_symbol(al->map, al->addr, filter);
  593. } else {
  594. const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
  595. if (dsos__col_width < unresolved_col_width &&
  596. !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
  597. !symbol_conf.dso_list)
  598. dsos__col_width = unresolved_col_width;
  599. }
  600. if (symbol_conf.sym_list && al->sym &&
  601. !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
  602. goto out_filtered;
  603. return 0;
  604. out_filtered:
  605. al->filtered = true;
  606. return 0;
  607. }
  608. int event__parse_sample(event_t *event, u64 type, struct sample_data *data)
  609. {
  610. u64 *array = event->sample.array;
  611. if (type & PERF_SAMPLE_IP) {
  612. data->ip = event->ip.ip;
  613. array++;
  614. }
  615. if (type & PERF_SAMPLE_TID) {
  616. u32 *p = (u32 *)array;
  617. data->pid = p[0];
  618. data->tid = p[1];
  619. array++;
  620. }
  621. if (type & PERF_SAMPLE_TIME) {
  622. data->time = *array;
  623. array++;
  624. }
  625. if (type & PERF_SAMPLE_ADDR) {
  626. data->addr = *array;
  627. array++;
  628. }
  629. data->id = -1ULL;
  630. if (type & PERF_SAMPLE_ID) {
  631. data->id = *array;
  632. array++;
  633. }
  634. if (type & PERF_SAMPLE_STREAM_ID) {
  635. data->stream_id = *array;
  636. array++;
  637. }
  638. if (type & PERF_SAMPLE_CPU) {
  639. u32 *p = (u32 *)array;
  640. data->cpu = *p;
  641. array++;
  642. }
  643. if (type & PERF_SAMPLE_PERIOD) {
  644. data->period = *array;
  645. array++;
  646. }
  647. if (type & PERF_SAMPLE_READ) {
  648. pr_debug("PERF_SAMPLE_READ is unsuported for now\n");
  649. return -1;
  650. }
  651. if (type & PERF_SAMPLE_CALLCHAIN) {
  652. data->callchain = (struct ip_callchain *)array;
  653. array += 1 + data->callchain->nr;
  654. }
  655. if (type & PERF_SAMPLE_RAW) {
  656. u32 *p = (u32 *)array;
  657. data->raw_size = *p;
  658. p++;
  659. data->raw_data = p;
  660. }
  661. return 0;
  662. }