builtin-top.c 17 KB

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