builtin-top.c 17 KB

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