builtin-top.c 17 KB

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