builtin-top.c 33 KB

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