builtin-top.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. /*
  2. * builtin-top.c
  3. *
  4. * Builtin top command: Display a continuously updated profile of
  5. * any workload, CPU or specific PID.
  6. *
  7. * Copyright (C) 2008, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
  8. *
  9. * Improvements and fixes by:
  10. *
  11. * Arjan van de Ven <arjan@linux.intel.com>
  12. * Yanmin Zhang <yanmin.zhang@intel.com>
  13. * Wu Fengguang <fengguang.wu@intel.com>
  14. * Mike Galbraith <efault@gmx.de>
  15. * Paul Mackerras <paulus@samba.org>
  16. *
  17. * Released under the GPL v2. (and only v2, not any later version)
  18. */
  19. #include "builtin.h"
  20. #include "perf.h"
  21. #include "util/color.h"
  22. #include "util/evlist.h"
  23. #include "util/evsel.h"
  24. #include "util/session.h"
  25. #include "util/symbol.h"
  26. #include "util/thread.h"
  27. #include "util/thread_map.h"
  28. #include "util/util.h"
  29. #include <linux/rbtree.h>
  30. #include "util/parse-options.h"
  31. #include "util/parse-events.h"
  32. #include "util/cpumap.h"
  33. #include "util/xyarray.h"
  34. #include "util/debug.h"
  35. #include <assert.h>
  36. #include <fcntl.h>
  37. #include <stdio.h>
  38. #include <termios.h>
  39. #include <unistd.h>
  40. #include <inttypes.h>
  41. #include <errno.h>
  42. #include <time.h>
  43. #include <sched.h>
  44. #include <pthread.h>
  45. #include <sys/syscall.h>
  46. #include <sys/ioctl.h>
  47. #include <sys/poll.h>
  48. #include <sys/prctl.h>
  49. #include <sys/wait.h>
  50. #include <sys/uio.h>
  51. #include <sys/mman.h>
  52. #include <linux/unistd.h>
  53. #include <linux/types.h>
  54. #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
  55. struct perf_evlist *evsel_list;
  56. static bool system_wide = false;
  57. static int default_interval = 0;
  58. static int count_filter = 5;
  59. static int print_entries;
  60. static int target_pid = -1;
  61. static int target_tid = -1;
  62. static struct thread_map *threads;
  63. static bool inherit = false;
  64. static struct cpu_map *cpus;
  65. static int realtime_prio = 0;
  66. static bool group = false;
  67. static unsigned int page_size;
  68. static unsigned int mmap_pages = 128;
  69. static int freq = 1000; /* 1 KHz */
  70. static int delay_secs = 2;
  71. static bool zero = false;
  72. static bool dump_symtab = false;
  73. static bool hide_kernel_symbols = false;
  74. static bool hide_user_symbols = false;
  75. static struct winsize winsize;
  76. /*
  77. * Source
  78. */
  79. struct source_line {
  80. u64 eip;
  81. unsigned long count[MAX_COUNTERS];
  82. char *line;
  83. struct source_line *next;
  84. };
  85. static const char *sym_filter = NULL;
  86. struct sym_entry *sym_filter_entry = NULL;
  87. struct sym_entry *sym_filter_entry_sched = NULL;
  88. static int sym_pcnt_filter = 5;
  89. static int sym_counter = 0;
  90. static struct perf_evsel *sym_evsel = NULL;
  91. static int display_weighted = -1;
  92. static const char *cpu_list;
  93. /*
  94. * Symbols
  95. */
  96. struct sym_entry_source {
  97. struct source_line *source;
  98. struct source_line *lines;
  99. struct source_line **lines_tail;
  100. pthread_mutex_t lock;
  101. };
  102. struct sym_entry {
  103. struct rb_node rb_node;
  104. struct list_head node;
  105. unsigned long snap_count;
  106. double weight;
  107. int skip;
  108. u16 name_len;
  109. u8 origin;
  110. struct map *map;
  111. struct sym_entry_source *src;
  112. unsigned long count[0];
  113. };
  114. /*
  115. * Source functions
  116. */
  117. static inline struct symbol *sym_entry__symbol(struct sym_entry *self)
  118. {
  119. return ((void *)self) + symbol_conf.priv_size;
  120. }
  121. void get_term_dimensions(struct winsize *ws)
  122. {
  123. char *s = getenv("LINES");
  124. if (s != NULL) {
  125. ws->ws_row = atoi(s);
  126. s = getenv("COLUMNS");
  127. if (s != NULL) {
  128. ws->ws_col = atoi(s);
  129. if (ws->ws_row && ws->ws_col)
  130. return;
  131. }
  132. }
  133. #ifdef TIOCGWINSZ
  134. if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
  135. ws->ws_row && ws->ws_col)
  136. return;
  137. #endif
  138. ws->ws_row = 25;
  139. ws->ws_col = 80;
  140. }
  141. static void update_print_entries(struct winsize *ws)
  142. {
  143. print_entries = ws->ws_row;
  144. if (print_entries > 9)
  145. print_entries -= 9;
  146. }
  147. static void sig_winch_handler(int sig __used)
  148. {
  149. get_term_dimensions(&winsize);
  150. update_print_entries(&winsize);
  151. }
  152. static int parse_source(struct sym_entry *syme)
  153. {
  154. struct symbol *sym;
  155. struct sym_entry_source *source;
  156. struct map *map;
  157. FILE *file;
  158. char command[PATH_MAX*2];
  159. const char *path;
  160. u64 len;
  161. if (!syme)
  162. return -1;
  163. sym = sym_entry__symbol(syme);
  164. map = syme->map;
  165. /*
  166. * We can't annotate with just /proc/kallsyms
  167. */
  168. if (map->dso->origin == DSO__ORIG_KERNEL)
  169. return -1;
  170. if (syme->src == NULL) {
  171. syme->src = zalloc(sizeof(*source));
  172. if (syme->src == NULL)
  173. return -1;
  174. pthread_mutex_init(&syme->src->lock, NULL);
  175. }
  176. source = syme->src;
  177. if (source->lines) {
  178. pthread_mutex_lock(&source->lock);
  179. goto out_assign;
  180. }
  181. path = map->dso->long_name;
  182. len = sym->end - sym->start;
  183. sprintf(command,
  184. "objdump --start-address=%#0*" PRIx64 " --stop-address=%#0*" PRIx64 " -dS %s",
  185. BITS_PER_LONG / 4, map__rip_2objdump(map, sym->start),
  186. BITS_PER_LONG / 4, map__rip_2objdump(map, sym->end), path);
  187. file = popen(command, "r");
  188. if (!file)
  189. return -1;
  190. pthread_mutex_lock(&source->lock);
  191. source->lines_tail = &source->lines;
  192. while (!feof(file)) {
  193. struct source_line *src;
  194. size_t dummy = 0;
  195. char *c, *sep;
  196. src = malloc(sizeof(struct source_line));
  197. assert(src != NULL);
  198. memset(src, 0, sizeof(struct source_line));
  199. if (getline(&src->line, &dummy, file) < 0)
  200. break;
  201. if (!src->line)
  202. break;
  203. c = strchr(src->line, '\n');
  204. if (c)
  205. *c = 0;
  206. src->next = NULL;
  207. *source->lines_tail = src;
  208. source->lines_tail = &src->next;
  209. src->eip = strtoull(src->line, &sep, 16);
  210. if (*sep == ':')
  211. src->eip = map__objdump_2ip(map, src->eip);
  212. else /* this line has no ip info (e.g. source line) */
  213. src->eip = 0;
  214. }
  215. pclose(file);
  216. out_assign:
  217. sym_filter_entry = syme;
  218. pthread_mutex_unlock(&source->lock);
  219. return 0;
  220. }
  221. static void __zero_source_counters(struct sym_entry *syme)
  222. {
  223. int i;
  224. struct source_line *line;
  225. line = syme->src->lines;
  226. while (line) {
  227. for (i = 0; i < evsel_list->nr_entries; i++)
  228. line->count[i] = 0;
  229. line = line->next;
  230. }
  231. }
  232. static void record_precise_ip(struct sym_entry *syme, int counter, u64 ip)
  233. {
  234. struct source_line *line;
  235. if (syme != sym_filter_entry)
  236. return;
  237. if (pthread_mutex_trylock(&syme->src->lock))
  238. return;
  239. if (syme->src == NULL || syme->src->source == NULL)
  240. goto out_unlock;
  241. for (line = syme->src->lines; line; line = line->next) {
  242. /* skip lines without IP info */
  243. if (line->eip == 0)
  244. continue;
  245. if (line->eip == ip) {
  246. line->count[counter]++;
  247. break;
  248. }
  249. if (line->eip > ip)
  250. break;
  251. }
  252. out_unlock:
  253. pthread_mutex_unlock(&syme->src->lock);
  254. }
  255. #define PATTERN_LEN (BITS_PER_LONG / 4 + 2)
  256. static void lookup_sym_source(struct sym_entry *syme)
  257. {
  258. struct symbol *symbol = sym_entry__symbol(syme);
  259. struct source_line *line;
  260. char pattern[PATTERN_LEN + 1];
  261. sprintf(pattern, "%0*" PRIx64 " <", BITS_PER_LONG / 4,
  262. map__rip_2objdump(syme->map, symbol->start));
  263. pthread_mutex_lock(&syme->src->lock);
  264. for (line = syme->src->lines; line; line = line->next) {
  265. if (memcmp(line->line, pattern, PATTERN_LEN) == 0) {
  266. syme->src->source = line;
  267. break;
  268. }
  269. }
  270. pthread_mutex_unlock(&syme->src->lock);
  271. }
  272. static void show_lines(struct source_line *queue, int count, int total)
  273. {
  274. int i;
  275. struct source_line *line;
  276. line = queue;
  277. for (i = 0; i < count; i++) {
  278. float pcnt = 100.0*(float)line->count[sym_counter]/(float)total;
  279. printf("%8li %4.1f%%\t%s\n", line->count[sym_counter], pcnt, line->line);
  280. line = line->next;
  281. }
  282. }
  283. #define TRACE_COUNT 3
  284. static void show_details(struct sym_entry *syme)
  285. {
  286. struct symbol *symbol;
  287. struct source_line *line;
  288. struct source_line *line_queue = NULL;
  289. int displayed = 0;
  290. int line_queue_count = 0, total = 0, more = 0;
  291. if (!syme)
  292. return;
  293. if (!syme->src->source)
  294. lookup_sym_source(syme);
  295. if (!syme->src->source)
  296. return;
  297. symbol = sym_entry__symbol(syme);
  298. printf("Showing %s for %s\n", event_name(sym_evsel), symbol->name);
  299. printf(" Events Pcnt (>=%d%%)\n", sym_pcnt_filter);
  300. pthread_mutex_lock(&syme->src->lock);
  301. line = syme->src->source;
  302. while (line) {
  303. total += line->count[sym_counter];
  304. line = line->next;
  305. }
  306. line = syme->src->source;
  307. while (line) {
  308. float pcnt = 0.0;
  309. if (!line_queue_count)
  310. line_queue = line;
  311. line_queue_count++;
  312. if (line->count[sym_counter])
  313. pcnt = 100.0 * line->count[sym_counter] / (float)total;
  314. if (pcnt >= (float)sym_pcnt_filter) {
  315. if (displayed <= print_entries)
  316. show_lines(line_queue, line_queue_count, total);
  317. else more++;
  318. displayed += line_queue_count;
  319. line_queue_count = 0;
  320. line_queue = NULL;
  321. } else if (line_queue_count > TRACE_COUNT) {
  322. line_queue = line_queue->next;
  323. line_queue_count--;
  324. }
  325. line->count[sym_counter] = zero ? 0 : line->count[sym_counter] * 7 / 8;
  326. line = line->next;
  327. }
  328. pthread_mutex_unlock(&syme->src->lock);
  329. if (more)
  330. printf("%d lines not displayed, maybe increase display entries [e]\n", more);
  331. }
  332. /*
  333. * Symbols will be added here in event__process_sample and will get out
  334. * after decayed.
  335. */
  336. static LIST_HEAD(active_symbols);
  337. static pthread_mutex_t active_symbols_lock = PTHREAD_MUTEX_INITIALIZER;
  338. /*
  339. * Ordering weight: count-1 * count-2 * ... / count-n
  340. */
  341. static double sym_weight(const struct sym_entry *sym)
  342. {
  343. double weight = sym->snap_count;
  344. int counter;
  345. if (!display_weighted)
  346. return weight;
  347. for (counter = 1; counter < evsel_list->nr_entries - 1; counter++)
  348. weight *= sym->count[counter];
  349. weight /= (sym->count[counter] + 1);
  350. return weight;
  351. }
  352. static long samples;
  353. static long kernel_samples, us_samples;
  354. static long exact_samples;
  355. static long guest_us_samples, guest_kernel_samples;
  356. static const char CONSOLE_CLEAR[] = "";
  357. static void __list_insert_active_sym(struct sym_entry *syme)
  358. {
  359. list_add(&syme->node, &active_symbols);
  360. }
  361. static void list_remove_active_sym(struct sym_entry *syme)
  362. {
  363. pthread_mutex_lock(&active_symbols_lock);
  364. list_del_init(&syme->node);
  365. pthread_mutex_unlock(&active_symbols_lock);
  366. }
  367. static void rb_insert_active_sym(struct rb_root *tree, struct sym_entry *se)
  368. {
  369. struct rb_node **p = &tree->rb_node;
  370. struct rb_node *parent = NULL;
  371. struct sym_entry *iter;
  372. while (*p != NULL) {
  373. parent = *p;
  374. iter = rb_entry(parent, struct sym_entry, rb_node);
  375. if (se->weight > iter->weight)
  376. p = &(*p)->rb_left;
  377. else
  378. p = &(*p)->rb_right;
  379. }
  380. rb_link_node(&se->rb_node, parent, p);
  381. rb_insert_color(&se->rb_node, tree);
  382. }
  383. static void print_sym_table(void)
  384. {
  385. int printed = 0, j;
  386. struct perf_evsel *counter;
  387. int snap = !display_weighted ? sym_counter : 0;
  388. float samples_per_sec = samples/delay_secs;
  389. float ksamples_per_sec = kernel_samples/delay_secs;
  390. float us_samples_per_sec = (us_samples)/delay_secs;
  391. float guest_kernel_samples_per_sec = (guest_kernel_samples)/delay_secs;
  392. float guest_us_samples_per_sec = (guest_us_samples)/delay_secs;
  393. float esamples_percent = (100.0*exact_samples)/samples;
  394. float sum_ksamples = 0.0;
  395. struct sym_entry *syme, *n;
  396. struct rb_root tmp = RB_ROOT;
  397. struct rb_node *nd;
  398. int sym_width = 0, dso_width = 0, dso_short_width = 0;
  399. const int win_width = winsize.ws_col - 1;
  400. samples = us_samples = kernel_samples = exact_samples = 0;
  401. guest_kernel_samples = guest_us_samples = 0;
  402. /* Sort the active symbols */
  403. pthread_mutex_lock(&active_symbols_lock);
  404. syme = list_entry(active_symbols.next, struct sym_entry, node);
  405. pthread_mutex_unlock(&active_symbols_lock);
  406. list_for_each_entry_safe_from(syme, n, &active_symbols, node) {
  407. syme->snap_count = syme->count[snap];
  408. if (syme->snap_count != 0) {
  409. if ((hide_user_symbols &&
  410. syme->origin == PERF_RECORD_MISC_USER) ||
  411. (hide_kernel_symbols &&
  412. syme->origin == PERF_RECORD_MISC_KERNEL)) {
  413. list_remove_active_sym(syme);
  414. continue;
  415. }
  416. syme->weight = sym_weight(syme);
  417. rb_insert_active_sym(&tmp, syme);
  418. sum_ksamples += syme->snap_count;
  419. for (j = 0; j < evsel_list->nr_entries; j++)
  420. syme->count[j] = zero ? 0 : syme->count[j] * 7 / 8;
  421. } else
  422. list_remove_active_sym(syme);
  423. }
  424. puts(CONSOLE_CLEAR);
  425. printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
  426. if (!perf_guest) {
  427. printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
  428. " exact: %4.1f%% [",
  429. samples_per_sec,
  430. 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
  431. samples_per_sec)),
  432. esamples_percent);
  433. } else {
  434. printf(" PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
  435. " guest kernel:%4.1f%% guest us:%4.1f%%"
  436. " exact: %4.1f%% [",
  437. samples_per_sec,
  438. 100.0 - (100.0 * ((samples_per_sec-ksamples_per_sec) /
  439. samples_per_sec)),
  440. 100.0 - (100.0 * ((samples_per_sec-us_samples_per_sec) /
  441. samples_per_sec)),
  442. 100.0 - (100.0 * ((samples_per_sec -
  443. guest_kernel_samples_per_sec) /
  444. samples_per_sec)),
  445. 100.0 - (100.0 * ((samples_per_sec -
  446. guest_us_samples_per_sec) /
  447. samples_per_sec)),
  448. esamples_percent);
  449. }
  450. if (evsel_list->nr_entries == 1 || !display_weighted) {
  451. struct perf_evsel *first;
  452. first = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  453. printf("%" PRIu64, (uint64_t)first->attr.sample_period);
  454. if (freq)
  455. printf("Hz ");
  456. else
  457. printf(" ");
  458. }
  459. if (!display_weighted)
  460. printf("%s", event_name(sym_evsel));
  461. else list_for_each_entry(counter, &evsel_list->entries, node) {
  462. if (counter->idx)
  463. printf("/");
  464. printf("%s", event_name(counter));
  465. }
  466. printf( "], ");
  467. if (target_pid != -1)
  468. printf(" (target_pid: %d", target_pid);
  469. else if (target_tid != -1)
  470. printf(" (target_tid: %d", target_tid);
  471. else
  472. printf(" (all");
  473. if (cpu_list)
  474. printf(", CPU%s: %s)\n", cpus->nr > 1 ? "s" : "", cpu_list);
  475. else {
  476. if (target_tid != -1)
  477. printf(")\n");
  478. else
  479. printf(", %d CPU%s)\n", cpus->nr, cpus->nr > 1 ? "s" : "");
  480. }
  481. printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
  482. if (sym_filter_entry) {
  483. show_details(sym_filter_entry);
  484. return;
  485. }
  486. /*
  487. * Find the longest symbol name that will be displayed
  488. */
  489. for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
  490. syme = rb_entry(nd, struct sym_entry, rb_node);
  491. if (++printed > print_entries ||
  492. (int)syme->snap_count < count_filter)
  493. continue;
  494. if (syme->map->dso->long_name_len > dso_width)
  495. dso_width = syme->map->dso->long_name_len;
  496. if (syme->map->dso->short_name_len > dso_short_width)
  497. dso_short_width = syme->map->dso->short_name_len;
  498. if (syme->name_len > sym_width)
  499. sym_width = syme->name_len;
  500. }
  501. printed = 0;
  502. if (sym_width + dso_width > winsize.ws_col - 29) {
  503. dso_width = dso_short_width;
  504. if (sym_width + dso_width > winsize.ws_col - 29)
  505. sym_width = winsize.ws_col - dso_width - 29;
  506. }
  507. putchar('\n');
  508. if (evsel_list->nr_entries == 1)
  509. printf(" samples pcnt");
  510. else
  511. printf(" weight samples pcnt");
  512. if (verbose)
  513. printf(" RIP ");
  514. printf(" %-*.*s DSO\n", sym_width, sym_width, "function");
  515. printf(" %s _______ _____",
  516. evsel_list->nr_entries == 1 ? " " : "______");
  517. if (verbose)
  518. printf(" ________________");
  519. printf(" %-*.*s", sym_width, sym_width, graph_line);
  520. printf(" %-*.*s", dso_width, dso_width, graph_line);
  521. puts("\n");
  522. for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
  523. struct symbol *sym;
  524. double pcnt;
  525. syme = rb_entry(nd, struct sym_entry, rb_node);
  526. sym = sym_entry__symbol(syme);
  527. if (++printed > print_entries || (int)syme->snap_count < count_filter)
  528. continue;
  529. pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) /
  530. sum_ksamples));
  531. if (evsel_list->nr_entries == 1 || !display_weighted)
  532. printf("%20.2f ", syme->weight);
  533. else
  534. printf("%9.1f %10ld ", syme->weight, syme->snap_count);
  535. percent_color_fprintf(stdout, "%4.1f%%", pcnt);
  536. if (verbose)
  537. printf(" %016" PRIx64, sym->start);
  538. printf(" %-*.*s", sym_width, sym_width, sym->name);
  539. printf(" %-*.*s\n", dso_width, dso_width,
  540. dso_width >= syme->map->dso->long_name_len ?
  541. syme->map->dso->long_name :
  542. syme->map->dso->short_name);
  543. }
  544. }
  545. static void prompt_integer(int *target, const char *msg)
  546. {
  547. char *buf = malloc(0), *p;
  548. size_t dummy = 0;
  549. int tmp;
  550. fprintf(stdout, "\n%s: ", msg);
  551. if (getline(&buf, &dummy, stdin) < 0)
  552. return;
  553. p = strchr(buf, '\n');
  554. if (p)
  555. *p = 0;
  556. p = buf;
  557. while(*p) {
  558. if (!isdigit(*p))
  559. goto out_free;
  560. p++;
  561. }
  562. tmp = strtoul(buf, NULL, 10);
  563. *target = tmp;
  564. out_free:
  565. free(buf);
  566. }
  567. static void prompt_percent(int *target, const char *msg)
  568. {
  569. int tmp = 0;
  570. prompt_integer(&tmp, msg);
  571. if (tmp >= 0 && tmp <= 100)
  572. *target = tmp;
  573. }
  574. static void prompt_symbol(struct sym_entry **target, const char *msg)
  575. {
  576. char *buf = malloc(0), *p;
  577. struct sym_entry *syme = *target, *n, *found = NULL;
  578. size_t dummy = 0;
  579. /* zero counters of active symbol */
  580. if (syme) {
  581. pthread_mutex_lock(&syme->src->lock);
  582. __zero_source_counters(syme);
  583. *target = NULL;
  584. pthread_mutex_unlock(&syme->src->lock);
  585. }
  586. fprintf(stdout, "\n%s: ", msg);
  587. if (getline(&buf, &dummy, stdin) < 0)
  588. goto out_free;
  589. p = strchr(buf, '\n');
  590. if (p)
  591. *p = 0;
  592. pthread_mutex_lock(&active_symbols_lock);
  593. syme = list_entry(active_symbols.next, struct sym_entry, node);
  594. pthread_mutex_unlock(&active_symbols_lock);
  595. list_for_each_entry_safe_from(syme, n, &active_symbols, node) {
  596. struct symbol *sym = sym_entry__symbol(syme);
  597. if (!strcmp(buf, sym->name)) {
  598. found = syme;
  599. break;
  600. }
  601. }
  602. if (!found) {
  603. fprintf(stderr, "Sorry, %s is not active.\n", buf);
  604. sleep(1);
  605. return;
  606. } else
  607. parse_source(found);
  608. out_free:
  609. free(buf);
  610. }
  611. static void print_mapped_keys(void)
  612. {
  613. char *name = NULL;
  614. if (sym_filter_entry) {
  615. struct symbol *sym = sym_entry__symbol(sym_filter_entry);
  616. name = sym->name;
  617. }
  618. fprintf(stdout, "\nMapped keys:\n");
  619. fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", delay_secs);
  620. fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", print_entries);
  621. if (evsel_list->nr_entries > 1)
  622. fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(sym_evsel));
  623. fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
  624. fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
  625. fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
  626. fprintf(stdout, "\t[S] stop annotation.\n");
  627. if (evsel_list->nr_entries > 1)
  628. fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0);
  629. fprintf(stdout,
  630. "\t[K] hide kernel_symbols symbols. \t(%s)\n",
  631. hide_kernel_symbols ? "yes" : "no");
  632. fprintf(stdout,
  633. "\t[U] hide user symbols. \t(%s)\n",
  634. hide_user_symbols ? "yes" : "no");
  635. fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", zero ? 1 : 0);
  636. fprintf(stdout, "\t[qQ] quit.\n");
  637. }
  638. static int key_mapped(int c)
  639. {
  640. switch (c) {
  641. case 'd':
  642. case 'e':
  643. case 'f':
  644. case 'z':
  645. case 'q':
  646. case 'Q':
  647. case 'K':
  648. case 'U':
  649. case 'F':
  650. case 's':
  651. case 'S':
  652. return 1;
  653. case 'E':
  654. case 'w':
  655. return evsel_list->nr_entries > 1 ? 1 : 0;
  656. default:
  657. break;
  658. }
  659. return 0;
  660. }
  661. static void handle_keypress(struct perf_session *session, int c)
  662. {
  663. if (!key_mapped(c)) {
  664. struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
  665. struct termios tc, save;
  666. print_mapped_keys();
  667. fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
  668. fflush(stdout);
  669. tcgetattr(0, &save);
  670. tc = save;
  671. tc.c_lflag &= ~(ICANON | ECHO);
  672. tc.c_cc[VMIN] = 0;
  673. tc.c_cc[VTIME] = 0;
  674. tcsetattr(0, TCSANOW, &tc);
  675. poll(&stdin_poll, 1, -1);
  676. c = getc(stdin);
  677. tcsetattr(0, TCSAFLUSH, &save);
  678. if (!key_mapped(c))
  679. return;
  680. }
  681. switch (c) {
  682. case 'd':
  683. prompt_integer(&delay_secs, "Enter display delay");
  684. if (delay_secs < 1)
  685. delay_secs = 1;
  686. break;
  687. case 'e':
  688. prompt_integer(&print_entries, "Enter display entries (lines)");
  689. if (print_entries == 0) {
  690. sig_winch_handler(SIGWINCH);
  691. signal(SIGWINCH, sig_winch_handler);
  692. } else
  693. signal(SIGWINCH, SIG_DFL);
  694. break;
  695. case 'E':
  696. if (evsel_list->nr_entries > 1) {
  697. fprintf(stderr, "\nAvailable events:");
  698. list_for_each_entry(sym_evsel, &evsel_list->entries, node)
  699. fprintf(stderr, "\n\t%d %s", sym_evsel->idx, event_name(sym_evsel));
  700. prompt_integer(&sym_counter, "Enter details event counter");
  701. if (sym_counter >= evsel_list->nr_entries) {
  702. sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  703. sym_counter = 0;
  704. fprintf(stderr, "Sorry, no such event, using %s.\n", event_name(sym_evsel));
  705. sleep(1);
  706. break;
  707. }
  708. list_for_each_entry(sym_evsel, &evsel_list->entries, node)
  709. if (sym_evsel->idx == sym_counter)
  710. break;
  711. } else sym_counter = 0;
  712. break;
  713. case 'f':
  714. prompt_integer(&count_filter, "Enter display event count filter");
  715. break;
  716. case 'F':
  717. prompt_percent(&sym_pcnt_filter, "Enter details display event filter (percent)");
  718. break;
  719. case 'K':
  720. hide_kernel_symbols = !hide_kernel_symbols;
  721. break;
  722. case 'q':
  723. case 'Q':
  724. printf("exiting.\n");
  725. if (dump_symtab)
  726. perf_session__fprintf_dsos(session, stderr);
  727. exit(0);
  728. case 's':
  729. prompt_symbol(&sym_filter_entry, "Enter details symbol");
  730. break;
  731. case 'S':
  732. if (!sym_filter_entry)
  733. break;
  734. else {
  735. struct sym_entry *syme = sym_filter_entry;
  736. pthread_mutex_lock(&syme->src->lock);
  737. sym_filter_entry = NULL;
  738. __zero_source_counters(syme);
  739. pthread_mutex_unlock(&syme->src->lock);
  740. }
  741. break;
  742. case 'U':
  743. hide_user_symbols = !hide_user_symbols;
  744. break;
  745. case 'w':
  746. display_weighted = ~display_weighted;
  747. break;
  748. case 'z':
  749. zero = !zero;
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. static void *display_thread(void *arg __used)
  756. {
  757. struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
  758. struct termios tc, save;
  759. int delay_msecs, c;
  760. struct perf_session *session = (struct perf_session *) arg;
  761. tcgetattr(0, &save);
  762. tc = save;
  763. tc.c_lflag &= ~(ICANON | ECHO);
  764. tc.c_cc[VMIN] = 0;
  765. tc.c_cc[VTIME] = 0;
  766. repeat:
  767. delay_msecs = delay_secs * 1000;
  768. tcsetattr(0, TCSANOW, &tc);
  769. /* trash return*/
  770. getc(stdin);
  771. do {
  772. print_sym_table();
  773. } while (!poll(&stdin_poll, 1, delay_msecs) == 1);
  774. c = getc(stdin);
  775. tcsetattr(0, TCSAFLUSH, &save);
  776. handle_keypress(session, c);
  777. goto repeat;
  778. return NULL;
  779. }
  780. /* Tag samples to be skipped. */
  781. static const char *skip_symbols[] = {
  782. "default_idle",
  783. "native_safe_halt",
  784. "cpu_idle",
  785. "enter_idle",
  786. "exit_idle",
  787. "mwait_idle",
  788. "mwait_idle_with_hints",
  789. "poll_idle",
  790. "ppc64_runlatch_off",
  791. "pseries_dedicated_idle_sleep",
  792. NULL
  793. };
  794. static int symbol_filter(struct map *map, struct symbol *sym)
  795. {
  796. struct sym_entry *syme;
  797. const char *name = sym->name;
  798. int i;
  799. /*
  800. * ppc64 uses function descriptors and appends a '.' to the
  801. * start of every instruction address. Remove it.
  802. */
  803. if (name[0] == '.')
  804. name++;
  805. if (!strcmp(name, "_text") ||
  806. !strcmp(name, "_etext") ||
  807. !strcmp(name, "_sinittext") ||
  808. !strncmp("init_module", name, 11) ||
  809. !strncmp("cleanup_module", name, 14) ||
  810. strstr(name, "_text_start") ||
  811. strstr(name, "_text_end"))
  812. return 1;
  813. syme = symbol__priv(sym);
  814. syme->map = map;
  815. syme->src = NULL;
  816. if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter)) {
  817. /* schedule initial sym_filter_entry setup */
  818. sym_filter_entry_sched = syme;
  819. sym_filter = NULL;
  820. }
  821. for (i = 0; skip_symbols[i]; i++) {
  822. if (!strcmp(skip_symbols[i], name)) {
  823. syme->skip = 1;
  824. break;
  825. }
  826. }
  827. if (!syme->skip)
  828. syme->name_len = strlen(sym->name);
  829. return 0;
  830. }
  831. static void event__process_sample(const event_t *self,
  832. struct sample_data *sample,
  833. struct perf_session *session)
  834. {
  835. u64 ip = self->ip.ip;
  836. struct sym_entry *syme;
  837. struct addr_location al;
  838. struct machine *machine;
  839. u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  840. ++samples;
  841. switch (origin) {
  842. case PERF_RECORD_MISC_USER:
  843. ++us_samples;
  844. if (hide_user_symbols)
  845. return;
  846. machine = perf_session__find_host_machine(session);
  847. break;
  848. case PERF_RECORD_MISC_KERNEL:
  849. ++kernel_samples;
  850. if (hide_kernel_symbols)
  851. return;
  852. machine = perf_session__find_host_machine(session);
  853. break;
  854. case PERF_RECORD_MISC_GUEST_KERNEL:
  855. ++guest_kernel_samples;
  856. machine = perf_session__find_machine(session, self->ip.pid);
  857. break;
  858. case PERF_RECORD_MISC_GUEST_USER:
  859. ++guest_us_samples;
  860. /*
  861. * TODO: we don't process guest user from host side
  862. * except simple counting.
  863. */
  864. return;
  865. default:
  866. return;
  867. }
  868. if (!machine && perf_guest) {
  869. pr_err("Can't find guest [%d]'s kernel information\n",
  870. self->ip.pid);
  871. return;
  872. }
  873. if (self->header.misc & PERF_RECORD_MISC_EXACT_IP)
  874. exact_samples++;
  875. if (event__preprocess_sample(self, session, &al, sample,
  876. symbol_filter) < 0 ||
  877. al.filtered)
  878. return;
  879. if (al.sym == NULL) {
  880. /*
  881. * As we do lazy loading of symtabs we only will know if the
  882. * specified vmlinux file is invalid when we actually have a
  883. * hit in kernel space and then try to load it. So if we get
  884. * here and there are _no_ symbols in the DSO backing the
  885. * kernel map, bail out.
  886. *
  887. * We may never get here, for instance, if we use -K/
  888. * --hide-kernel-symbols, even if the user specifies an
  889. * invalid --vmlinux ;-)
  890. */
  891. if (al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
  892. RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
  893. pr_err("The %s file can't be used\n",
  894. symbol_conf.vmlinux_name);
  895. exit(1);
  896. }
  897. return;
  898. }
  899. /* let's see, whether we need to install initial sym_filter_entry */
  900. if (sym_filter_entry_sched) {
  901. sym_filter_entry = sym_filter_entry_sched;
  902. sym_filter_entry_sched = NULL;
  903. if (parse_source(sym_filter_entry) < 0) {
  904. struct symbol *sym = sym_entry__symbol(sym_filter_entry);
  905. pr_err("Can't annotate %s", sym->name);
  906. if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) {
  907. pr_err(": No vmlinux file was found in the path:\n");
  908. machine__fprintf_vmlinux_path(machine, stderr);
  909. } else
  910. pr_err(".\n");
  911. exit(1);
  912. }
  913. }
  914. syme = symbol__priv(al.sym);
  915. if (!syme->skip) {
  916. struct perf_evsel *evsel;
  917. syme->origin = origin;
  918. evsel = perf_evlist__id2evsel(evsel_list, sample->id);
  919. assert(evsel != NULL);
  920. syme->count[evsel->idx]++;
  921. record_precise_ip(syme, evsel->idx, ip);
  922. pthread_mutex_lock(&active_symbols_lock);
  923. if (list_empty(&syme->node) || !syme->node.next)
  924. __list_insert_active_sym(syme);
  925. pthread_mutex_unlock(&active_symbols_lock);
  926. }
  927. }
  928. static void perf_session__mmap_read_cpu(struct perf_session *self, int cpu)
  929. {
  930. struct sample_data sample;
  931. event_t *event;
  932. while ((event = perf_evlist__read_on_cpu(evsel_list, cpu)) != NULL) {
  933. event__parse_sample(event, self, &sample);
  934. if (event->header.type == PERF_RECORD_SAMPLE)
  935. event__process_sample(event, &sample, self);
  936. else
  937. event__process(event, &sample, self);
  938. }
  939. }
  940. static void perf_session__mmap_read(struct perf_session *self)
  941. {
  942. int i;
  943. for (i = 0; i < cpus->nr; i++)
  944. perf_session__mmap_read_cpu(self, i);
  945. }
  946. static void start_counters(struct perf_evlist *evlist)
  947. {
  948. struct perf_evsel *counter;
  949. list_for_each_entry(counter, &evlist->entries, node) {
  950. struct perf_event_attr *attr = &counter->attr;
  951. attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
  952. if (freq) {
  953. attr->sample_type |= PERF_SAMPLE_PERIOD;
  954. attr->freq = 1;
  955. attr->sample_freq = freq;
  956. }
  957. if (evlist->nr_entries > 1) {
  958. attr->sample_type |= PERF_SAMPLE_ID;
  959. attr->read_format |= PERF_FORMAT_ID;
  960. }
  961. attr->mmap = 1;
  962. try_again:
  963. if (perf_evsel__open(counter, cpus, threads, group, inherit) < 0) {
  964. int err = errno;
  965. if (err == EPERM || err == EACCES)
  966. die("Permission error - are you root?\n"
  967. "\t Consider tweaking"
  968. " /proc/sys/kernel/perf_event_paranoid.\n");
  969. /*
  970. * If it's cycles then fall back to hrtimer
  971. * based cpu-clock-tick sw counter, which
  972. * is always available even if no PMU support:
  973. */
  974. if (attr->type == PERF_TYPE_HARDWARE &&
  975. attr->config == PERF_COUNT_HW_CPU_CYCLES) {
  976. if (verbose)
  977. warning(" ... trying to fall back to cpu-clock-ticks\n");
  978. attr->type = PERF_TYPE_SOFTWARE;
  979. attr->config = PERF_COUNT_SW_CPU_CLOCK;
  980. goto try_again;
  981. }
  982. printf("\n");
  983. error("sys_perf_event_open() syscall returned with %d "
  984. "(%s). /bin/dmesg may provide additional information.\n",
  985. err, strerror(err));
  986. die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
  987. exit(-1);
  988. }
  989. }
  990. if (perf_evlist__mmap(evlist, cpus, threads, mmap_pages, true) < 0)
  991. die("failed to mmap with %d (%s)\n", errno, strerror(errno));
  992. }
  993. static int __cmd_top(void)
  994. {
  995. pthread_t thread;
  996. struct perf_evsel *first;
  997. int ret;
  998. /*
  999. * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
  1000. * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
  1001. */
  1002. struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false, NULL);
  1003. if (session == NULL)
  1004. return -ENOMEM;
  1005. if (target_tid != -1)
  1006. event__synthesize_thread(target_tid, event__process, session);
  1007. else
  1008. event__synthesize_threads(event__process, session);
  1009. start_counters(evsel_list);
  1010. first = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  1011. perf_session__set_sample_type(session, first->attr.sample_type);
  1012. /* Wait for a minimal set of events before starting the snapshot */
  1013. poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
  1014. perf_session__mmap_read(session);
  1015. if (pthread_create(&thread, NULL, display_thread, session)) {
  1016. printf("Could not create display thread.\n");
  1017. exit(-1);
  1018. }
  1019. if (realtime_prio) {
  1020. struct sched_param param;
  1021. param.sched_priority = realtime_prio;
  1022. if (sched_setscheduler(0, SCHED_FIFO, &param)) {
  1023. printf("Could not set realtime priority.\n");
  1024. exit(-1);
  1025. }
  1026. }
  1027. while (1) {
  1028. int hits = samples;
  1029. perf_session__mmap_read(session);
  1030. if (hits == samples)
  1031. ret = poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
  1032. }
  1033. return 0;
  1034. }
  1035. static const char * const top_usage[] = {
  1036. "perf top [<options>]",
  1037. NULL
  1038. };
  1039. static const struct option options[] = {
  1040. OPT_CALLBACK('e', "event", &evsel_list, "event",
  1041. "event selector. use 'perf list' to list available events",
  1042. parse_events),
  1043. OPT_INTEGER('c', "count", &default_interval,
  1044. "event period to sample"),
  1045. OPT_INTEGER('p', "pid", &target_pid,
  1046. "profile events on existing process id"),
  1047. OPT_INTEGER('t', "tid", &target_tid,
  1048. "profile events on existing thread id"),
  1049. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  1050. "system-wide collection from all CPUs"),
  1051. OPT_STRING('C', "cpu", &cpu_list, "cpu",
  1052. "list of cpus to monitor"),
  1053. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  1054. "file", "vmlinux pathname"),
  1055. OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols,
  1056. "hide kernel symbols"),
  1057. OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"),
  1058. OPT_INTEGER('r', "realtime", &realtime_prio,
  1059. "collect data with this RT SCHED_FIFO priority"),
  1060. OPT_INTEGER('d', "delay", &delay_secs,
  1061. "number of seconds to delay between refreshes"),
  1062. OPT_BOOLEAN('D', "dump-symtab", &dump_symtab,
  1063. "dump the symbol table used for profiling"),
  1064. OPT_INTEGER('f', "count-filter", &count_filter,
  1065. "only display functions with more events than this"),
  1066. OPT_BOOLEAN('g', "group", &group,
  1067. "put the counters into a counter group"),
  1068. OPT_BOOLEAN('i', "inherit", &inherit,
  1069. "child tasks inherit counters"),
  1070. OPT_STRING('s', "sym-annotate", &sym_filter, "symbol name",
  1071. "symbol to annotate"),
  1072. OPT_BOOLEAN('z', "zero", &zero,
  1073. "zero history across updates"),
  1074. OPT_INTEGER('F', "freq", &freq,
  1075. "profile at this frequency"),
  1076. OPT_INTEGER('E', "entries", &print_entries,
  1077. "display this many functions"),
  1078. OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols,
  1079. "hide user symbols"),
  1080. OPT_INCR('v', "verbose", &verbose,
  1081. "be more verbose (show counter open errors, etc)"),
  1082. OPT_END()
  1083. };
  1084. int cmd_top(int argc, const char **argv, const char *prefix __used)
  1085. {
  1086. struct perf_evsel *pos;
  1087. int status = -ENOMEM;
  1088. evsel_list = perf_evlist__new();
  1089. if (evsel_list == NULL)
  1090. return -ENOMEM;
  1091. page_size = sysconf(_SC_PAGE_SIZE);
  1092. argc = parse_options(argc, argv, options, top_usage, 0);
  1093. if (argc)
  1094. usage_with_options(top_usage, options);
  1095. if (target_pid != -1)
  1096. target_tid = target_pid;
  1097. threads = thread_map__new(target_pid, target_tid);
  1098. if (threads == NULL) {
  1099. pr_err("Problems finding threads of monitor\n");
  1100. usage_with_options(top_usage, options);
  1101. }
  1102. /* CPU and PID are mutually exclusive */
  1103. if (target_tid > 0 && cpu_list) {
  1104. printf("WARNING: PID switch overriding CPU\n");
  1105. sleep(1);
  1106. cpu_list = NULL;
  1107. }
  1108. if (!evsel_list->nr_entries &&
  1109. perf_evlist__add_default(evsel_list) < 0) {
  1110. pr_err("Not enough memory for event selector list\n");
  1111. return -ENOMEM;
  1112. }
  1113. if (delay_secs < 1)
  1114. delay_secs = 1;
  1115. /*
  1116. * User specified count overrides default frequency.
  1117. */
  1118. if (default_interval)
  1119. freq = 0;
  1120. else if (freq) {
  1121. default_interval = freq;
  1122. } else {
  1123. fprintf(stderr, "frequency and count are zero, aborting\n");
  1124. exit(EXIT_FAILURE);
  1125. }
  1126. if (target_tid != -1)
  1127. cpus = cpu_map__dummy_new();
  1128. else
  1129. cpus = cpu_map__new(cpu_list);
  1130. if (cpus == NULL)
  1131. usage_with_options(top_usage, options);
  1132. list_for_each_entry(pos, &evsel_list->entries, node) {
  1133. if (perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0)
  1134. goto out_free_fd;
  1135. /*
  1136. * Fill in the ones not specifically initialized via -c:
  1137. */
  1138. if (pos->attr.sample_period)
  1139. continue;
  1140. pos->attr.sample_period = default_interval;
  1141. }
  1142. if (perf_evlist__alloc_pollfd(evsel_list, cpus->nr, threads->nr) < 0 ||
  1143. perf_evlist__alloc_mmap(evsel_list, cpus->nr) < 0)
  1144. goto out_free_fd;
  1145. sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  1146. symbol_conf.priv_size = (sizeof(struct sym_entry) +
  1147. (evsel_list->nr_entries + 1) * sizeof(unsigned long));
  1148. symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
  1149. if (symbol__init() < 0)
  1150. return -1;
  1151. get_term_dimensions(&winsize);
  1152. if (print_entries == 0) {
  1153. update_print_entries(&winsize);
  1154. signal(SIGWINCH, sig_winch_handler);
  1155. }
  1156. status = __cmd_top();
  1157. out_free_fd:
  1158. perf_evlist__delete(evsel_list);
  1159. return status;
  1160. }