builtin-top.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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/symbol.h"
  22. #include "util/color.h"
  23. #include "util/util.h"
  24. #include "util/rbtree.h"
  25. #include "util/parse-options.h"
  26. #include "util/parse-events.h"
  27. #include <assert.h>
  28. #include <fcntl.h>
  29. #include <stdio.h>
  30. #include <errno.h>
  31. #include <time.h>
  32. #include <sched.h>
  33. #include <pthread.h>
  34. #include <sys/syscall.h>
  35. #include <sys/ioctl.h>
  36. #include <sys/poll.h>
  37. #include <sys/prctl.h>
  38. #include <sys/wait.h>
  39. #include <sys/uio.h>
  40. #include <sys/mman.h>
  41. #include <linux/unistd.h>
  42. #include <linux/types.h>
  43. static int system_wide = 0;
  44. static __u64 default_event_id[MAX_COUNTERS] = {
  45. EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK),
  46. EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CONTEXT_SWITCHES),
  47. EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS),
  48. EID(PERF_TYPE_SOFTWARE, PERF_COUNT_PAGE_FAULTS),
  49. EID(PERF_TYPE_HARDWARE, PERF_COUNT_CPU_CYCLES),
  50. EID(PERF_TYPE_HARDWARE, PERF_COUNT_INSTRUCTIONS),
  51. EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_REFERENCES),
  52. EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_MISSES),
  53. };
  54. static int default_interval = 100000;
  55. static int event_count[MAX_COUNTERS];
  56. static int fd[MAX_NR_CPUS][MAX_COUNTERS];
  57. static __u64 count_filter = 5;
  58. static int print_entries = 15;
  59. static int target_pid = -1;
  60. static int profile_cpu = -1;
  61. static int nr_cpus = 0;
  62. static unsigned int realtime_prio = 0;
  63. static int group = 0;
  64. static unsigned int page_size;
  65. static unsigned int mmap_pages = 16;
  66. static int use_mmap = 0;
  67. static int use_munmap = 0;
  68. static int freq = 0;
  69. static char *sym_filter;
  70. static unsigned long filter_start;
  71. static unsigned long filter_end;
  72. static int delay_secs = 2;
  73. static int zero;
  74. static int dump_symtab;
  75. static const unsigned int default_count[] = {
  76. 1000000,
  77. 1000000,
  78. 10000,
  79. 10000,
  80. 1000000,
  81. 10000,
  82. };
  83. /*
  84. * Symbols
  85. */
  86. static uint64_t min_ip;
  87. static uint64_t max_ip = -1ll;
  88. struct sym_entry {
  89. struct rb_node rb_node;
  90. struct list_head node;
  91. unsigned long count[MAX_COUNTERS];
  92. unsigned long snap_count;
  93. double weight;
  94. int skip;
  95. };
  96. struct sym_entry *sym_filter_entry;
  97. struct dso *kernel_dso;
  98. /*
  99. * Symbols will be added here in record_ip and will get out
  100. * after decayed.
  101. */
  102. static LIST_HEAD(active_symbols);
  103. static pthread_mutex_t active_symbols_lock = PTHREAD_MUTEX_INITIALIZER;
  104. /*
  105. * Ordering weight: count-1 * count-2 * ... / count-n
  106. */
  107. static double sym_weight(const struct sym_entry *sym)
  108. {
  109. double weight = sym->snap_count;
  110. int counter;
  111. for (counter = 1; counter < nr_counters-1; counter++)
  112. weight *= sym->count[counter];
  113. weight /= (sym->count[counter] + 1);
  114. return weight;
  115. }
  116. static long events;
  117. static long userspace_events;
  118. static const char CONSOLE_CLEAR[] = "";
  119. static void __list_insert_active_sym(struct sym_entry *syme)
  120. {
  121. list_add(&syme->node, &active_symbols);
  122. }
  123. static void list_remove_active_sym(struct sym_entry *syme)
  124. {
  125. pthread_mutex_lock(&active_symbols_lock);
  126. list_del_init(&syme->node);
  127. pthread_mutex_unlock(&active_symbols_lock);
  128. }
  129. static void rb_insert_active_sym(struct rb_root *tree, struct sym_entry *se)
  130. {
  131. struct rb_node **p = &tree->rb_node;
  132. struct rb_node *parent = NULL;
  133. struct sym_entry *iter;
  134. while (*p != NULL) {
  135. parent = *p;
  136. iter = rb_entry(parent, struct sym_entry, rb_node);
  137. if (se->weight > iter->weight)
  138. p = &(*p)->rb_left;
  139. else
  140. p = &(*p)->rb_right;
  141. }
  142. rb_link_node(&se->rb_node, parent, p);
  143. rb_insert_color(&se->rb_node, tree);
  144. }
  145. static void print_sym_table(void)
  146. {
  147. int printed = 0, j;
  148. int counter;
  149. float events_per_sec = events/delay_secs;
  150. float kevents_per_sec = (events-userspace_events)/delay_secs;
  151. float sum_kevents = 0.0;
  152. struct sym_entry *syme, *n;
  153. struct rb_root tmp = RB_ROOT;
  154. struct rb_node *nd;
  155. events = userspace_events = 0;
  156. /* Sort the active symbols */
  157. pthread_mutex_lock(&active_symbols_lock);
  158. syme = list_entry(active_symbols.next, struct sym_entry, node);
  159. pthread_mutex_unlock(&active_symbols_lock);
  160. list_for_each_entry_safe_from(syme, n, &active_symbols, node) {
  161. syme->snap_count = syme->count[0];
  162. if (syme->snap_count != 0) {
  163. syme->weight = sym_weight(syme);
  164. rb_insert_active_sym(&tmp, syme);
  165. sum_kevents += syme->snap_count;
  166. for (j = 0; j < nr_counters; j++)
  167. syme->count[j] = zero ? 0 : syme->count[j] * 7 / 8;
  168. } else
  169. list_remove_active_sym(syme);
  170. }
  171. write(1, CONSOLE_CLEAR, strlen(CONSOLE_CLEAR));
  172. printf(
  173. "------------------------------------------------------------------------------\n");
  174. printf( " PerfTop:%8.0f irqs/sec kernel:%4.1f%% [",
  175. events_per_sec,
  176. 100.0 - (100.0*((events_per_sec-kevents_per_sec)/events_per_sec)));
  177. if (nr_counters == 1)
  178. printf("%d ", event_count[0]);
  179. for (counter = 0; counter < nr_counters; counter++) {
  180. if (counter)
  181. printf("/");
  182. printf("%s", event_name(counter));
  183. }
  184. printf( "], ");
  185. if (target_pid != -1)
  186. printf(" (target_pid: %d", target_pid);
  187. else
  188. printf(" (all");
  189. if (profile_cpu != -1)
  190. printf(", cpu: %d)\n", profile_cpu);
  191. else {
  192. if (target_pid != -1)
  193. printf(")\n");
  194. else
  195. printf(", %d CPUs)\n", nr_cpus);
  196. }
  197. printf("------------------------------------------------------------------------------\n\n");
  198. if (nr_counters == 1)
  199. printf(" events pcnt");
  200. else
  201. printf(" weight events pcnt");
  202. printf(" RIP kernel function\n"
  203. " ______ ______ _____ ________________ _______________\n\n"
  204. );
  205. for (nd = rb_first(&tmp); nd; nd = rb_next(nd)) {
  206. struct sym_entry *syme = rb_entry(nd, struct sym_entry, rb_node);
  207. struct symbol *sym = (struct symbol *)(syme + 1);
  208. char *color = PERF_COLOR_NORMAL;
  209. double pcnt;
  210. if (++printed > print_entries || syme->snap_count < count_filter)
  211. continue;
  212. pcnt = 100.0 - (100.0 * ((sum_kevents - syme->snap_count) /
  213. sum_kevents));
  214. /*
  215. * We color high-overhead entries in red, low-overhead
  216. * entries in green - and keep the middle ground normal:
  217. */
  218. if (pcnt >= 5.0)
  219. color = PERF_COLOR_RED;
  220. if (pcnt < 0.5)
  221. color = PERF_COLOR_GREEN;
  222. if (nr_counters == 1)
  223. printf("%19.2f - ", syme->weight);
  224. else
  225. printf("%8.1f %10ld - ", syme->weight, syme->snap_count);
  226. color_fprintf(stdout, color, "%4.1f%%", pcnt);
  227. printf(" - %016llx : %s\n", sym->start, sym->name);
  228. }
  229. {
  230. struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
  231. if (poll(&stdin_poll, 1, 0) == 1) {
  232. printf("key pressed - exiting.\n");
  233. exit(0);
  234. }
  235. }
  236. }
  237. static void *display_thread(void *arg)
  238. {
  239. printf("PerfTop refresh period: %d seconds\n", delay_secs);
  240. while (!sleep(delay_secs))
  241. print_sym_table();
  242. return NULL;
  243. }
  244. static int symbol_filter(struct dso *self, struct symbol *sym)
  245. {
  246. static int filter_match;
  247. struct sym_entry *syme;
  248. const char *name = sym->name;
  249. if (!strcmp(name, "_text") ||
  250. !strcmp(name, "_etext") ||
  251. !strcmp(name, "_sinittext") ||
  252. !strncmp("init_module", name, 11) ||
  253. !strncmp("cleanup_module", name, 14) ||
  254. strstr(name, "_text_start") ||
  255. strstr(name, "_text_end"))
  256. return 1;
  257. syme = dso__sym_priv(self, sym);
  258. /* Tag events to be skipped. */
  259. if (!strcmp("default_idle", name) ||
  260. !strcmp("cpu_idle", name) ||
  261. !strcmp("enter_idle", name) ||
  262. !strcmp("exit_idle", name) ||
  263. !strcmp("mwait_idle", name))
  264. syme->skip = 1;
  265. if (filter_match == 1) {
  266. filter_end = sym->start;
  267. filter_match = -1;
  268. if (filter_end - filter_start > 10000) {
  269. fprintf(stderr,
  270. "hm, too large filter symbol <%s> - skipping.\n",
  271. sym_filter);
  272. fprintf(stderr, "symbol filter start: %016lx\n",
  273. filter_start);
  274. fprintf(stderr, " end: %016lx\n",
  275. filter_end);
  276. filter_end = filter_start = 0;
  277. sym_filter = NULL;
  278. sleep(1);
  279. }
  280. }
  281. if (filter_match == 0 && sym_filter && !strcmp(name, sym_filter)) {
  282. filter_match = 1;
  283. filter_start = sym->start;
  284. }
  285. return 0;
  286. }
  287. static int parse_symbols(void)
  288. {
  289. struct rb_node *node;
  290. struct symbol *sym;
  291. kernel_dso = dso__new("[kernel]", sizeof(struct sym_entry));
  292. if (kernel_dso == NULL)
  293. return -1;
  294. if (dso__load_kernel(kernel_dso, NULL, symbol_filter, 1) != 0)
  295. goto out_delete_dso;
  296. node = rb_first(&kernel_dso->syms);
  297. sym = rb_entry(node, struct symbol, rb_node);
  298. min_ip = sym->start;
  299. node = rb_last(&kernel_dso->syms);
  300. sym = rb_entry(node, struct symbol, rb_node);
  301. max_ip = sym->end;
  302. if (dump_symtab)
  303. dso__fprintf(kernel_dso, stderr);
  304. return 0;
  305. out_delete_dso:
  306. dso__delete(kernel_dso);
  307. kernel_dso = NULL;
  308. return -1;
  309. }
  310. #define TRACE_COUNT 3
  311. /*
  312. * Binary search in the histogram table and record the hit:
  313. */
  314. static void record_ip(uint64_t ip, int counter)
  315. {
  316. struct symbol *sym = dso__find_symbol(kernel_dso, ip);
  317. if (sym != NULL) {
  318. struct sym_entry *syme = dso__sym_priv(kernel_dso, sym);
  319. if (!syme->skip) {
  320. syme->count[counter]++;
  321. pthread_mutex_lock(&active_symbols_lock);
  322. if (list_empty(&syme->node) || !syme->node.next)
  323. __list_insert_active_sym(syme);
  324. pthread_mutex_unlock(&active_symbols_lock);
  325. return;
  326. }
  327. }
  328. events--;
  329. }
  330. static void process_event(uint64_t ip, int counter)
  331. {
  332. events++;
  333. if (ip < min_ip || ip > max_ip) {
  334. userspace_events++;
  335. return;
  336. }
  337. record_ip(ip, counter);
  338. }
  339. struct mmap_data {
  340. int counter;
  341. void *base;
  342. unsigned int mask;
  343. unsigned int prev;
  344. };
  345. static unsigned int mmap_read_head(struct mmap_data *md)
  346. {
  347. struct perf_counter_mmap_page *pc = md->base;
  348. int head;
  349. head = pc->data_head;
  350. rmb();
  351. return head;
  352. }
  353. struct timeval last_read, this_read;
  354. static void mmap_read(struct mmap_data *md)
  355. {
  356. unsigned int head = mmap_read_head(md);
  357. unsigned int old = md->prev;
  358. unsigned char *data = md->base + page_size;
  359. int diff;
  360. gettimeofday(&this_read, NULL);
  361. /*
  362. * If we're further behind than half the buffer, there's a chance
  363. * the writer will bite our tail and screw up the events under us.
  364. *
  365. * If we somehow ended up ahead of the head, we got messed up.
  366. *
  367. * In either case, truncate and restart at head.
  368. */
  369. diff = head - old;
  370. if (diff > md->mask / 2 || diff < 0) {
  371. struct timeval iv;
  372. unsigned long msecs;
  373. timersub(&this_read, &last_read, &iv);
  374. msecs = iv.tv_sec*1000 + iv.tv_usec/1000;
  375. fprintf(stderr, "WARNING: failed to keep up with mmap data."
  376. " Last read %lu msecs ago.\n", msecs);
  377. /*
  378. * head points to a known good entry, start there.
  379. */
  380. old = head;
  381. }
  382. last_read = this_read;
  383. for (; old != head;) {
  384. struct ip_event {
  385. struct perf_event_header header;
  386. __u64 ip;
  387. __u32 pid, target_pid;
  388. };
  389. struct mmap_event {
  390. struct perf_event_header header;
  391. __u32 pid, target_pid;
  392. __u64 start;
  393. __u64 len;
  394. __u64 pgoff;
  395. char filename[PATH_MAX];
  396. };
  397. typedef union event_union {
  398. struct perf_event_header header;
  399. struct ip_event ip;
  400. struct mmap_event mmap;
  401. } event_t;
  402. event_t *event = (event_t *)&data[old & md->mask];
  403. event_t event_copy;
  404. size_t size = event->header.size;
  405. /*
  406. * Event straddles the mmap boundary -- header should always
  407. * be inside due to u64 alignment of output.
  408. */
  409. if ((old & md->mask) + size != ((old + size) & md->mask)) {
  410. unsigned int offset = old;
  411. unsigned int len = min(sizeof(*event), size), cpy;
  412. void *dst = &event_copy;
  413. do {
  414. cpy = min(md->mask + 1 - (offset & md->mask), len);
  415. memcpy(dst, &data[offset & md->mask], cpy);
  416. offset += cpy;
  417. dst += cpy;
  418. len -= cpy;
  419. } while (len);
  420. event = &event_copy;
  421. }
  422. old += size;
  423. if (event->header.misc & PERF_EVENT_MISC_OVERFLOW) {
  424. if (event->header.type & PERF_SAMPLE_IP)
  425. process_event(event->ip.ip, md->counter);
  426. } else {
  427. switch (event->header.type) {
  428. case PERF_EVENT_MMAP:
  429. case PERF_EVENT_MUNMAP:
  430. printf("%s: %Lu %Lu %Lu %s\n",
  431. event->header.type == PERF_EVENT_MMAP
  432. ? "mmap" : "munmap",
  433. event->mmap.start,
  434. event->mmap.len,
  435. event->mmap.pgoff,
  436. event->mmap.filename);
  437. break;
  438. }
  439. }
  440. }
  441. md->prev = old;
  442. }
  443. static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS];
  444. static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
  445. static int __cmd_top(void)
  446. {
  447. struct perf_counter_attr attr;
  448. pthread_t thread;
  449. int i, counter, group_fd, nr_poll = 0;
  450. unsigned int cpu;
  451. int ret;
  452. for (i = 0; i < nr_cpus; i++) {
  453. group_fd = -1;
  454. for (counter = 0; counter < nr_counters; counter++) {
  455. cpu = profile_cpu;
  456. if (target_pid == -1 && profile_cpu == -1)
  457. cpu = i;
  458. memset(&attr, 0, sizeof(attr));
  459. attr.config = event_id[counter];
  460. attr.sample_period = event_count[counter];
  461. attr.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_TID;
  462. attr.mmap = use_mmap;
  463. attr.munmap = use_munmap;
  464. attr.freq = freq;
  465. fd[i][counter] = sys_perf_counter_open(&attr, target_pid, cpu, group_fd, 0);
  466. if (fd[i][counter] < 0) {
  467. int err = errno;
  468. error("syscall returned with %d (%s)\n",
  469. fd[i][counter], strerror(err));
  470. if (err == EPERM)
  471. printf("Are you root?\n");
  472. exit(-1);
  473. }
  474. assert(fd[i][counter] >= 0);
  475. fcntl(fd[i][counter], F_SETFL, O_NONBLOCK);
  476. /*
  477. * First counter acts as the group leader:
  478. */
  479. if (group && group_fd == -1)
  480. group_fd = fd[i][counter];
  481. event_array[nr_poll].fd = fd[i][counter];
  482. event_array[nr_poll].events = POLLIN;
  483. nr_poll++;
  484. mmap_array[i][counter].counter = counter;
  485. mmap_array[i][counter].prev = 0;
  486. mmap_array[i][counter].mask = mmap_pages*page_size - 1;
  487. mmap_array[i][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
  488. PROT_READ, MAP_SHARED, fd[i][counter], 0);
  489. if (mmap_array[i][counter].base == MAP_FAILED)
  490. die("failed to mmap with %d (%s)\n", errno, strerror(errno));
  491. }
  492. }
  493. if (pthread_create(&thread, NULL, display_thread, NULL)) {
  494. printf("Could not create display thread.\n");
  495. exit(-1);
  496. }
  497. if (realtime_prio) {
  498. struct sched_param param;
  499. param.sched_priority = realtime_prio;
  500. if (sched_setscheduler(0, SCHED_FIFO, &param)) {
  501. printf("Could not set realtime priority.\n");
  502. exit(-1);
  503. }
  504. }
  505. while (1) {
  506. int hits = events;
  507. for (i = 0; i < nr_cpus; i++) {
  508. for (counter = 0; counter < nr_counters; counter++)
  509. mmap_read(&mmap_array[i][counter]);
  510. }
  511. if (hits == events)
  512. ret = poll(event_array, nr_poll, 100);
  513. }
  514. return 0;
  515. }
  516. static const char * const top_usage[] = {
  517. "perf top [<options>]",
  518. NULL
  519. };
  520. static char events_help_msg[EVENTS_HELP_MAX];
  521. static const struct option options[] = {
  522. OPT_CALLBACK('e', "event", NULL, "event",
  523. events_help_msg, parse_events),
  524. OPT_INTEGER('c', "count", &default_interval,
  525. "event period to sample"),
  526. OPT_INTEGER('p', "pid", &target_pid,
  527. "profile events on existing pid"),
  528. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  529. "system-wide collection from all CPUs"),
  530. OPT_INTEGER('C', "CPU", &profile_cpu,
  531. "CPU to profile on"),
  532. OPT_INTEGER('m', "mmap-pages", &mmap_pages,
  533. "number of mmap data pages"),
  534. OPT_INTEGER('r', "realtime", &realtime_prio,
  535. "collect data with this RT SCHED_FIFO priority"),
  536. OPT_INTEGER('d', "delay", &delay_secs,
  537. "number of seconds to delay between refreshes"),
  538. OPT_BOOLEAN('D', "dump-symtab", &dump_symtab,
  539. "dump the symbol table used for profiling"),
  540. OPT_INTEGER('f', "count-filter", &count_filter,
  541. "only display functions with more events than this"),
  542. OPT_BOOLEAN('g', "group", &group,
  543. "put the counters into a counter group"),
  544. OPT_STRING('s', "sym-filter", &sym_filter, "pattern",
  545. "only display symbols matchig this pattern"),
  546. OPT_BOOLEAN('z', "zero", &group,
  547. "zero history across updates"),
  548. OPT_BOOLEAN('M', "use-mmap", &use_mmap,
  549. "track mmap events"),
  550. OPT_BOOLEAN('U', "use-munmap", &use_munmap,
  551. "track munmap events"),
  552. OPT_INTEGER('F', "freq", &freq,
  553. "profile at this frequency"),
  554. OPT_INTEGER('E', "entries", &print_entries,
  555. "display this many functions"),
  556. OPT_END()
  557. };
  558. int cmd_top(int argc, const char **argv, const char *prefix)
  559. {
  560. int counter;
  561. page_size = sysconf(_SC_PAGE_SIZE);
  562. create_events_help(events_help_msg);
  563. memcpy(event_id, default_event_id, sizeof(default_event_id));
  564. argc = parse_options(argc, argv, options, top_usage, 0);
  565. if (argc)
  566. usage_with_options(top_usage, options);
  567. if (freq) {
  568. default_interval = freq;
  569. freq = 1;
  570. }
  571. /* CPU and PID are mutually exclusive */
  572. if (target_pid != -1 && profile_cpu != -1) {
  573. printf("WARNING: PID switch overriding CPU\n");
  574. sleep(1);
  575. profile_cpu = -1;
  576. }
  577. if (!nr_counters) {
  578. nr_counters = 1;
  579. event_id[0] = 0;
  580. }
  581. for (counter = 0; counter < nr_counters; counter++) {
  582. if (event_count[counter])
  583. continue;
  584. event_count[counter] = default_interval;
  585. }
  586. nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
  587. assert(nr_cpus <= MAX_NR_CPUS);
  588. assert(nr_cpus >= 0);
  589. if (target_pid != -1 || profile_cpu != -1)
  590. nr_cpus = 1;
  591. parse_symbols();
  592. return __cmd_top();
  593. }