builtin-top.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  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(struct perf_session *session)
  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. 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 (session->hists.stats.total_lost != 0) {
  482. color_fprintf(stdout, PERF_COLOR_RED, "WARNING:");
  483. printf(" LOST %" PRIu64 " events, Check IO/CPU overload\n",
  484. session->hists.stats.total_lost);
  485. }
  486. if (sym_filter_entry) {
  487. show_details(sym_filter_entry);
  488. return;
  489. }
  490. /*
  491. * Find the longest symbol name that will be displayed
  492. */
  493. for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
  494. syme = rb_entry(nd, struct sym_entry, rb_node);
  495. if (++printed > print_entries ||
  496. (int)syme->snap_count < count_filter)
  497. continue;
  498. if (syme->map->dso->long_name_len > dso_width)
  499. dso_width = syme->map->dso->long_name_len;
  500. if (syme->map->dso->short_name_len > dso_short_width)
  501. dso_short_width = syme->map->dso->short_name_len;
  502. if (syme->name_len > sym_width)
  503. sym_width = syme->name_len;
  504. }
  505. printed = 0;
  506. if (sym_width + dso_width > winsize.ws_col - 29) {
  507. dso_width = dso_short_width;
  508. if (sym_width + dso_width > winsize.ws_col - 29)
  509. sym_width = winsize.ws_col - dso_width - 29;
  510. }
  511. putchar('\n');
  512. if (evsel_list->nr_entries == 1)
  513. printf(" samples pcnt");
  514. else
  515. printf(" weight samples pcnt");
  516. if (verbose)
  517. printf(" RIP ");
  518. printf(" %-*.*s DSO\n", sym_width, sym_width, "function");
  519. printf(" %s _______ _____",
  520. evsel_list->nr_entries == 1 ? " " : "______");
  521. if (verbose)
  522. printf(" ________________");
  523. printf(" %-*.*s", sym_width, sym_width, graph_line);
  524. printf(" %-*.*s", dso_width, dso_width, graph_line);
  525. puts("\n");
  526. for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
  527. struct symbol *sym;
  528. double pcnt;
  529. syme = rb_entry(nd, struct sym_entry, rb_node);
  530. sym = sym_entry__symbol(syme);
  531. if (++printed > print_entries || (int)syme->snap_count < count_filter)
  532. continue;
  533. pcnt = 100.0 - (100.0 * ((sum_ksamples - syme->snap_count) /
  534. sum_ksamples));
  535. if (evsel_list->nr_entries == 1 || !display_weighted)
  536. printf("%20.2f ", syme->weight);
  537. else
  538. printf("%9.1f %10ld ", syme->weight, syme->snap_count);
  539. percent_color_fprintf(stdout, "%4.1f%%", pcnt);
  540. if (verbose)
  541. printf(" %016" PRIx64, sym->start);
  542. printf(" %-*.*s", sym_width, sym_width, sym->name);
  543. printf(" %-*.*s\n", dso_width, dso_width,
  544. dso_width >= syme->map->dso->long_name_len ?
  545. syme->map->dso->long_name :
  546. syme->map->dso->short_name);
  547. }
  548. }
  549. static void prompt_integer(int *target, const char *msg)
  550. {
  551. char *buf = malloc(0), *p;
  552. size_t dummy = 0;
  553. int tmp;
  554. fprintf(stdout, "\n%s: ", msg);
  555. if (getline(&buf, &dummy, stdin) < 0)
  556. return;
  557. p = strchr(buf, '\n');
  558. if (p)
  559. *p = 0;
  560. p = buf;
  561. while(*p) {
  562. if (!isdigit(*p))
  563. goto out_free;
  564. p++;
  565. }
  566. tmp = strtoul(buf, NULL, 10);
  567. *target = tmp;
  568. out_free:
  569. free(buf);
  570. }
  571. static void prompt_percent(int *target, const char *msg)
  572. {
  573. int tmp = 0;
  574. prompt_integer(&tmp, msg);
  575. if (tmp >= 0 && tmp <= 100)
  576. *target = tmp;
  577. }
  578. static void prompt_symbol(struct sym_entry **target, const char *msg)
  579. {
  580. char *buf = malloc(0), *p;
  581. struct sym_entry *syme = *target, *n, *found = NULL;
  582. size_t dummy = 0;
  583. /* zero counters of active symbol */
  584. if (syme) {
  585. pthread_mutex_lock(&syme->src->lock);
  586. __zero_source_counters(syme);
  587. *target = NULL;
  588. pthread_mutex_unlock(&syme->src->lock);
  589. }
  590. fprintf(stdout, "\n%s: ", msg);
  591. if (getline(&buf, &dummy, stdin) < 0)
  592. goto out_free;
  593. p = strchr(buf, '\n');
  594. if (p)
  595. *p = 0;
  596. pthread_mutex_lock(&active_symbols_lock);
  597. syme = list_entry(active_symbols.next, struct sym_entry, node);
  598. pthread_mutex_unlock(&active_symbols_lock);
  599. list_for_each_entry_safe_from(syme, n, &active_symbols, node) {
  600. struct symbol *sym = sym_entry__symbol(syme);
  601. if (!strcmp(buf, sym->name)) {
  602. found = syme;
  603. break;
  604. }
  605. }
  606. if (!found) {
  607. fprintf(stderr, "Sorry, %s is not active.\n", buf);
  608. sleep(1);
  609. return;
  610. } else
  611. parse_source(found);
  612. out_free:
  613. free(buf);
  614. }
  615. static void print_mapped_keys(void)
  616. {
  617. char *name = NULL;
  618. if (sym_filter_entry) {
  619. struct symbol *sym = sym_entry__symbol(sym_filter_entry);
  620. name = sym->name;
  621. }
  622. fprintf(stdout, "\nMapped keys:\n");
  623. fprintf(stdout, "\t[d] display refresh delay. \t(%d)\n", delay_secs);
  624. fprintf(stdout, "\t[e] display entries (lines). \t(%d)\n", print_entries);
  625. if (evsel_list->nr_entries > 1)
  626. fprintf(stdout, "\t[E] active event counter. \t(%s)\n", event_name(sym_evsel));
  627. fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
  628. fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
  629. fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
  630. fprintf(stdout, "\t[S] stop annotation.\n");
  631. if (evsel_list->nr_entries > 1)
  632. fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0);
  633. fprintf(stdout,
  634. "\t[K] hide kernel_symbols symbols. \t(%s)\n",
  635. hide_kernel_symbols ? "yes" : "no");
  636. fprintf(stdout,
  637. "\t[U] hide user symbols. \t(%s)\n",
  638. hide_user_symbols ? "yes" : "no");
  639. fprintf(stdout, "\t[z] toggle sample zeroing. \t(%d)\n", zero ? 1 : 0);
  640. fprintf(stdout, "\t[qQ] quit.\n");
  641. }
  642. static int key_mapped(int c)
  643. {
  644. switch (c) {
  645. case 'd':
  646. case 'e':
  647. case 'f':
  648. case 'z':
  649. case 'q':
  650. case 'Q':
  651. case 'K':
  652. case 'U':
  653. case 'F':
  654. case 's':
  655. case 'S':
  656. return 1;
  657. case 'E':
  658. case 'w':
  659. return evsel_list->nr_entries > 1 ? 1 : 0;
  660. default:
  661. break;
  662. }
  663. return 0;
  664. }
  665. static void handle_keypress(struct perf_session *session, int c)
  666. {
  667. if (!key_mapped(c)) {
  668. struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
  669. struct termios tc, save;
  670. print_mapped_keys();
  671. fprintf(stdout, "\nEnter selection, or unmapped key to continue: ");
  672. fflush(stdout);
  673. tcgetattr(0, &save);
  674. tc = save;
  675. tc.c_lflag &= ~(ICANON | ECHO);
  676. tc.c_cc[VMIN] = 0;
  677. tc.c_cc[VTIME] = 0;
  678. tcsetattr(0, TCSANOW, &tc);
  679. poll(&stdin_poll, 1, -1);
  680. c = getc(stdin);
  681. tcsetattr(0, TCSAFLUSH, &save);
  682. if (!key_mapped(c))
  683. return;
  684. }
  685. switch (c) {
  686. case 'd':
  687. prompt_integer(&delay_secs, "Enter display delay");
  688. if (delay_secs < 1)
  689. delay_secs = 1;
  690. break;
  691. case 'e':
  692. prompt_integer(&print_entries, "Enter display entries (lines)");
  693. if (print_entries == 0) {
  694. sig_winch_handler(SIGWINCH);
  695. signal(SIGWINCH, sig_winch_handler);
  696. } else
  697. signal(SIGWINCH, SIG_DFL);
  698. break;
  699. case 'E':
  700. if (evsel_list->nr_entries > 1) {
  701. fprintf(stderr, "\nAvailable events:");
  702. list_for_each_entry(sym_evsel, &evsel_list->entries, node)
  703. fprintf(stderr, "\n\t%d %s", sym_evsel->idx, event_name(sym_evsel));
  704. prompt_integer(&sym_counter, "Enter details event counter");
  705. if (sym_counter >= evsel_list->nr_entries) {
  706. sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  707. sym_counter = 0;
  708. fprintf(stderr, "Sorry, no such event, using %s.\n", event_name(sym_evsel));
  709. sleep(1);
  710. break;
  711. }
  712. list_for_each_entry(sym_evsel, &evsel_list->entries, node)
  713. if (sym_evsel->idx == sym_counter)
  714. break;
  715. } else sym_counter = 0;
  716. break;
  717. case 'f':
  718. prompt_integer(&count_filter, "Enter display event count filter");
  719. break;
  720. case 'F':
  721. prompt_percent(&sym_pcnt_filter, "Enter details display event filter (percent)");
  722. break;
  723. case 'K':
  724. hide_kernel_symbols = !hide_kernel_symbols;
  725. break;
  726. case 'q':
  727. case 'Q':
  728. printf("exiting.\n");
  729. if (dump_symtab)
  730. perf_session__fprintf_dsos(session, stderr);
  731. exit(0);
  732. case 's':
  733. prompt_symbol(&sym_filter_entry, "Enter details symbol");
  734. break;
  735. case 'S':
  736. if (!sym_filter_entry)
  737. break;
  738. else {
  739. struct sym_entry *syme = sym_filter_entry;
  740. pthread_mutex_lock(&syme->src->lock);
  741. sym_filter_entry = NULL;
  742. __zero_source_counters(syme);
  743. pthread_mutex_unlock(&syme->src->lock);
  744. }
  745. break;
  746. case 'U':
  747. hide_user_symbols = !hide_user_symbols;
  748. break;
  749. case 'w':
  750. display_weighted = ~display_weighted;
  751. break;
  752. case 'z':
  753. zero = !zero;
  754. break;
  755. default:
  756. break;
  757. }
  758. }
  759. static void *display_thread(void *arg __used)
  760. {
  761. struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
  762. struct termios tc, save;
  763. int delay_msecs, c;
  764. struct perf_session *session = (struct perf_session *) arg;
  765. tcgetattr(0, &save);
  766. tc = save;
  767. tc.c_lflag &= ~(ICANON | ECHO);
  768. tc.c_cc[VMIN] = 0;
  769. tc.c_cc[VTIME] = 0;
  770. repeat:
  771. delay_msecs = delay_secs * 1000;
  772. tcsetattr(0, TCSANOW, &tc);
  773. /* trash return*/
  774. getc(stdin);
  775. do {
  776. print_sym_table(session);
  777. } while (!poll(&stdin_poll, 1, delay_msecs) == 1);
  778. c = getc(stdin);
  779. tcsetattr(0, TCSAFLUSH, &save);
  780. handle_keypress(session, c);
  781. goto repeat;
  782. return NULL;
  783. }
  784. /* Tag samples to be skipped. */
  785. static const char *skip_symbols[] = {
  786. "default_idle",
  787. "native_safe_halt",
  788. "cpu_idle",
  789. "enter_idle",
  790. "exit_idle",
  791. "mwait_idle",
  792. "mwait_idle_with_hints",
  793. "poll_idle",
  794. "ppc64_runlatch_off",
  795. "pseries_dedicated_idle_sleep",
  796. NULL
  797. };
  798. static int symbol_filter(struct map *map, struct symbol *sym)
  799. {
  800. struct sym_entry *syme;
  801. const char *name = sym->name;
  802. int i;
  803. /*
  804. * ppc64 uses function descriptors and appends a '.' to the
  805. * start of every instruction address. Remove it.
  806. */
  807. if (name[0] == '.')
  808. name++;
  809. if (!strcmp(name, "_text") ||
  810. !strcmp(name, "_etext") ||
  811. !strcmp(name, "_sinittext") ||
  812. !strncmp("init_module", name, 11) ||
  813. !strncmp("cleanup_module", name, 14) ||
  814. strstr(name, "_text_start") ||
  815. strstr(name, "_text_end"))
  816. return 1;
  817. syme = symbol__priv(sym);
  818. syme->map = map;
  819. syme->src = NULL;
  820. if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter)) {
  821. /* schedule initial sym_filter_entry setup */
  822. sym_filter_entry_sched = syme;
  823. sym_filter = NULL;
  824. }
  825. for (i = 0; skip_symbols[i]; i++) {
  826. if (!strcmp(skip_symbols[i], name)) {
  827. syme->skip = 1;
  828. break;
  829. }
  830. }
  831. if (!syme->skip)
  832. syme->name_len = strlen(sym->name);
  833. return 0;
  834. }
  835. static void event__process_sample(const event_t *self,
  836. struct perf_sample *sample,
  837. struct perf_session *session)
  838. {
  839. u64 ip = self->ip.ip;
  840. struct sym_entry *syme;
  841. struct addr_location al;
  842. struct machine *machine;
  843. u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
  844. ++samples;
  845. switch (origin) {
  846. case PERF_RECORD_MISC_USER:
  847. ++us_samples;
  848. if (hide_user_symbols)
  849. return;
  850. machine = perf_session__find_host_machine(session);
  851. break;
  852. case PERF_RECORD_MISC_KERNEL:
  853. ++kernel_samples;
  854. if (hide_kernel_symbols)
  855. return;
  856. machine = perf_session__find_host_machine(session);
  857. break;
  858. case PERF_RECORD_MISC_GUEST_KERNEL:
  859. ++guest_kernel_samples;
  860. machine = perf_session__find_machine(session, self->ip.pid);
  861. break;
  862. case PERF_RECORD_MISC_GUEST_USER:
  863. ++guest_us_samples;
  864. /*
  865. * TODO: we don't process guest user from host side
  866. * except simple counting.
  867. */
  868. return;
  869. default:
  870. return;
  871. }
  872. if (!machine && perf_guest) {
  873. pr_err("Can't find guest [%d]'s kernel information\n",
  874. self->ip.pid);
  875. return;
  876. }
  877. if (self->header.misc & PERF_RECORD_MISC_EXACT_IP)
  878. exact_samples++;
  879. if (event__preprocess_sample(self, session, &al, sample,
  880. symbol_filter) < 0 ||
  881. al.filtered)
  882. return;
  883. if (al.sym == NULL) {
  884. /*
  885. * As we do lazy loading of symtabs we only will know if the
  886. * specified vmlinux file is invalid when we actually have a
  887. * hit in kernel space and then try to load it. So if we get
  888. * here and there are _no_ symbols in the DSO backing the
  889. * kernel map, bail out.
  890. *
  891. * We may never get here, for instance, if we use -K/
  892. * --hide-kernel-symbols, even if the user specifies an
  893. * invalid --vmlinux ;-)
  894. */
  895. if (al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
  896. RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
  897. pr_err("The %s file can't be used\n",
  898. symbol_conf.vmlinux_name);
  899. exit(1);
  900. }
  901. return;
  902. }
  903. /* let's see, whether we need to install initial sym_filter_entry */
  904. if (sym_filter_entry_sched) {
  905. sym_filter_entry = sym_filter_entry_sched;
  906. sym_filter_entry_sched = NULL;
  907. if (parse_source(sym_filter_entry) < 0) {
  908. struct symbol *sym = sym_entry__symbol(sym_filter_entry);
  909. pr_err("Can't annotate %s", sym->name);
  910. if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) {
  911. pr_err(": No vmlinux file was found in the path:\n");
  912. machine__fprintf_vmlinux_path(machine, stderr);
  913. } else
  914. pr_err(".\n");
  915. exit(1);
  916. }
  917. }
  918. syme = symbol__priv(al.sym);
  919. if (!syme->skip) {
  920. struct perf_evsel *evsel;
  921. syme->origin = origin;
  922. evsel = perf_evlist__id2evsel(evsel_list, sample->id);
  923. assert(evsel != NULL);
  924. syme->count[evsel->idx]++;
  925. record_precise_ip(syme, evsel->idx, ip);
  926. pthread_mutex_lock(&active_symbols_lock);
  927. if (list_empty(&syme->node) || !syme->node.next)
  928. __list_insert_active_sym(syme);
  929. pthread_mutex_unlock(&active_symbols_lock);
  930. }
  931. }
  932. static void perf_session__mmap_read_cpu(struct perf_session *self, int cpu)
  933. {
  934. struct perf_sample sample;
  935. event_t *event;
  936. while ((event = perf_evlist__read_on_cpu(evsel_list, cpu)) != NULL) {
  937. perf_session__parse_sample(self, event, &sample);
  938. if (event->header.type == PERF_RECORD_SAMPLE)
  939. event__process_sample(event, &sample, self);
  940. else
  941. event__process(event, &sample, self);
  942. }
  943. }
  944. static void perf_session__mmap_read(struct perf_session *self)
  945. {
  946. int i;
  947. for (i = 0; i < cpus->nr; i++)
  948. perf_session__mmap_read_cpu(self, i);
  949. }
  950. static void start_counters(struct perf_evlist *evlist)
  951. {
  952. struct perf_evsel *counter;
  953. list_for_each_entry(counter, &evlist->entries, node) {
  954. struct perf_event_attr *attr = &counter->attr;
  955. attr->sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
  956. if (freq) {
  957. attr->sample_type |= PERF_SAMPLE_PERIOD;
  958. attr->freq = 1;
  959. attr->sample_freq = freq;
  960. }
  961. if (evlist->nr_entries > 1) {
  962. attr->sample_type |= PERF_SAMPLE_ID;
  963. attr->read_format |= PERF_FORMAT_ID;
  964. }
  965. attr->mmap = 1;
  966. try_again:
  967. if (perf_evsel__open(counter, cpus, threads, group, inherit) < 0) {
  968. int err = errno;
  969. if (err == EPERM || err == EACCES)
  970. die("Permission error - are you root?\n"
  971. "\t Consider tweaking"
  972. " /proc/sys/kernel/perf_event_paranoid.\n");
  973. /*
  974. * If it's cycles then fall back to hrtimer
  975. * based cpu-clock-tick sw counter, which
  976. * is always available even if no PMU support:
  977. */
  978. if (attr->type == PERF_TYPE_HARDWARE &&
  979. attr->config == PERF_COUNT_HW_CPU_CYCLES) {
  980. if (verbose)
  981. warning(" ... trying to fall back to cpu-clock-ticks\n");
  982. attr->type = PERF_TYPE_SOFTWARE;
  983. attr->config = PERF_COUNT_SW_CPU_CLOCK;
  984. goto try_again;
  985. }
  986. printf("\n");
  987. error("sys_perf_event_open() syscall returned with %d "
  988. "(%s). /bin/dmesg may provide additional information.\n",
  989. err, strerror(err));
  990. die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
  991. exit(-1);
  992. }
  993. }
  994. if (perf_evlist__mmap(evlist, cpus, threads, mmap_pages, false) < 0)
  995. die("failed to mmap with %d (%s)\n", errno, strerror(errno));
  996. }
  997. static int __cmd_top(void)
  998. {
  999. pthread_t thread;
  1000. struct perf_evsel *first;
  1001. int ret;
  1002. /*
  1003. * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
  1004. * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
  1005. */
  1006. struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false, NULL);
  1007. if (session == NULL)
  1008. return -ENOMEM;
  1009. if (target_tid != -1)
  1010. event__synthesize_thread(target_tid, event__process, session);
  1011. else
  1012. event__synthesize_threads(event__process, session);
  1013. start_counters(evsel_list);
  1014. first = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  1015. perf_session__set_sample_type(session, first->attr.sample_type);
  1016. /* Wait for a minimal set of events before starting the snapshot */
  1017. poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
  1018. perf_session__mmap_read(session);
  1019. if (pthread_create(&thread, NULL, display_thread, session)) {
  1020. printf("Could not create display thread.\n");
  1021. exit(-1);
  1022. }
  1023. if (realtime_prio) {
  1024. struct sched_param param;
  1025. param.sched_priority = realtime_prio;
  1026. if (sched_setscheduler(0, SCHED_FIFO, &param)) {
  1027. printf("Could not set realtime priority.\n");
  1028. exit(-1);
  1029. }
  1030. }
  1031. while (1) {
  1032. int hits = samples;
  1033. perf_session__mmap_read(session);
  1034. if (hits == samples)
  1035. ret = poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
  1036. }
  1037. return 0;
  1038. }
  1039. static const char * const top_usage[] = {
  1040. "perf top [<options>]",
  1041. NULL
  1042. };
  1043. static const struct option options[] = {
  1044. OPT_CALLBACK('e', "event", &evsel_list, "event",
  1045. "event selector. use 'perf list' to list available events",
  1046. parse_events),
  1047. OPT_INTEGER('c', "count", &default_interval,
  1048. "event period to sample"),
  1049. OPT_INTEGER('p', "pid", &target_pid,
  1050. "profile events on existing process id"),
  1051. OPT_INTEGER('t', "tid", &target_tid,
  1052. "profile events on existing thread id"),
  1053. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  1054. "system-wide collection from all CPUs"),
  1055. OPT_STRING('C', "cpu", &cpu_list, "cpu",
  1056. "list of cpus to monitor"),
  1057. OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
  1058. "file", "vmlinux pathname"),
  1059. OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols,
  1060. "hide kernel symbols"),
  1061. OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"),
  1062. OPT_INTEGER('r', "realtime", &realtime_prio,
  1063. "collect data with this RT SCHED_FIFO priority"),
  1064. OPT_INTEGER('d', "delay", &delay_secs,
  1065. "number of seconds to delay between refreshes"),
  1066. OPT_BOOLEAN('D', "dump-symtab", &dump_symtab,
  1067. "dump the symbol table used for profiling"),
  1068. OPT_INTEGER('f', "count-filter", &count_filter,
  1069. "only display functions with more events than this"),
  1070. OPT_BOOLEAN('g', "group", &group,
  1071. "put the counters into a counter group"),
  1072. OPT_BOOLEAN('i', "inherit", &inherit,
  1073. "child tasks inherit counters"),
  1074. OPT_STRING('s', "sym-annotate", &sym_filter, "symbol name",
  1075. "symbol to annotate"),
  1076. OPT_BOOLEAN('z', "zero", &zero,
  1077. "zero history across updates"),
  1078. OPT_INTEGER('F', "freq", &freq,
  1079. "profile at this frequency"),
  1080. OPT_INTEGER('E', "entries", &print_entries,
  1081. "display this many functions"),
  1082. OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols,
  1083. "hide user symbols"),
  1084. OPT_INCR('v', "verbose", &verbose,
  1085. "be more verbose (show counter open errors, etc)"),
  1086. OPT_END()
  1087. };
  1088. int cmd_top(int argc, const char **argv, const char *prefix __used)
  1089. {
  1090. struct perf_evsel *pos;
  1091. int status = -ENOMEM;
  1092. evsel_list = perf_evlist__new();
  1093. if (evsel_list == NULL)
  1094. return -ENOMEM;
  1095. page_size = sysconf(_SC_PAGE_SIZE);
  1096. argc = parse_options(argc, argv, options, top_usage, 0);
  1097. if (argc)
  1098. usage_with_options(top_usage, options);
  1099. if (target_pid != -1)
  1100. target_tid = target_pid;
  1101. threads = thread_map__new(target_pid, target_tid);
  1102. if (threads == NULL) {
  1103. pr_err("Problems finding threads of monitor\n");
  1104. usage_with_options(top_usage, options);
  1105. }
  1106. /* CPU and PID are mutually exclusive */
  1107. if (target_tid > 0 && cpu_list) {
  1108. printf("WARNING: PID switch overriding CPU\n");
  1109. sleep(1);
  1110. cpu_list = NULL;
  1111. }
  1112. if (!evsel_list->nr_entries &&
  1113. perf_evlist__add_default(evsel_list) < 0) {
  1114. pr_err("Not enough memory for event selector list\n");
  1115. return -ENOMEM;
  1116. }
  1117. if (delay_secs < 1)
  1118. delay_secs = 1;
  1119. /*
  1120. * User specified count overrides default frequency.
  1121. */
  1122. if (default_interval)
  1123. freq = 0;
  1124. else if (freq) {
  1125. default_interval = freq;
  1126. } else {
  1127. fprintf(stderr, "frequency and count are zero, aborting\n");
  1128. exit(EXIT_FAILURE);
  1129. }
  1130. if (target_tid != -1)
  1131. cpus = cpu_map__dummy_new();
  1132. else
  1133. cpus = cpu_map__new(cpu_list);
  1134. if (cpus == NULL)
  1135. usage_with_options(top_usage, options);
  1136. list_for_each_entry(pos, &evsel_list->entries, node) {
  1137. if (perf_evsel__alloc_fd(pos, cpus->nr, threads->nr) < 0)
  1138. goto out_free_fd;
  1139. /*
  1140. * Fill in the ones not specifically initialized via -c:
  1141. */
  1142. if (pos->attr.sample_period)
  1143. continue;
  1144. pos->attr.sample_period = default_interval;
  1145. }
  1146. if (perf_evlist__alloc_pollfd(evsel_list, cpus->nr, threads->nr) < 0 ||
  1147. perf_evlist__alloc_mmap(evsel_list, cpus->nr) < 0)
  1148. goto out_free_fd;
  1149. sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node);
  1150. symbol_conf.priv_size = (sizeof(struct sym_entry) +
  1151. (evsel_list->nr_entries + 1) * sizeof(unsigned long));
  1152. symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
  1153. if (symbol__init() < 0)
  1154. return -1;
  1155. get_term_dimensions(&winsize);
  1156. if (print_entries == 0) {
  1157. update_print_entries(&winsize);
  1158. signal(SIGWINCH, sig_winch_handler);
  1159. }
  1160. status = __cmd_top();
  1161. out_free_fd:
  1162. perf_evlist__delete(evsel_list);
  1163. return status;
  1164. }