builtin-record.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * builtin-record.c
  3. *
  4. * Builtin record command: Record the profile of a workload
  5. * (or a CPU, or a PID) into the perf.data output file - for
  6. * later analysis via perf report.
  7. */
  8. #include "builtin.h"
  9. #include "perf.h"
  10. #include "util/util.h"
  11. #include "util/parse-options.h"
  12. #include "util/parse-events.h"
  13. #include "util/string.h"
  14. #include "util/header.h"
  15. #include "util/event.h"
  16. #include "util/debug.h"
  17. #include <unistd.h>
  18. #include <sched.h>
  19. #define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
  20. #define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
  21. static int fd[MAX_NR_CPUS][MAX_COUNTERS];
  22. static long default_interval = 100000;
  23. static int nr_cpus = 0;
  24. static unsigned int page_size;
  25. static unsigned int mmap_pages = 128;
  26. static int freq = 1000;
  27. static int output;
  28. static const char *output_name = "perf.data";
  29. static int group = 0;
  30. static unsigned int realtime_prio = 0;
  31. static int raw_samples = 0;
  32. static int system_wide = 0;
  33. static int profile_cpu = -1;
  34. static pid_t target_pid = -1;
  35. static pid_t child_pid = -1;
  36. static int inherit = 1;
  37. static int force = 0;
  38. static int append_file = 0;
  39. static int call_graph = 0;
  40. static int inherit_stat = 0;
  41. static int no_samples = 0;
  42. static int sample_address = 0;
  43. static int multiplex = 0;
  44. static int multiplex_fd = -1;
  45. static long samples = 0;
  46. static struct timeval last_read;
  47. static struct timeval this_read;
  48. static u64 bytes_written = 0;
  49. static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS];
  50. static int nr_poll = 0;
  51. static int nr_cpu = 0;
  52. static int file_new = 1;
  53. struct perf_header *header = NULL;
  54. struct mmap_data {
  55. int counter;
  56. void *base;
  57. unsigned int mask;
  58. unsigned int prev;
  59. };
  60. static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
  61. static unsigned long mmap_read_head(struct mmap_data *md)
  62. {
  63. struct perf_event_mmap_page *pc = md->base;
  64. long head;
  65. head = pc->data_head;
  66. rmb();
  67. return head;
  68. }
  69. static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
  70. {
  71. struct perf_event_mmap_page *pc = md->base;
  72. /*
  73. * ensure all reads are done before we write the tail out.
  74. */
  75. /* mb(); */
  76. pc->data_tail = tail;
  77. }
  78. static void write_output(void *buf, size_t size)
  79. {
  80. while (size) {
  81. int ret = write(output, buf, size);
  82. if (ret < 0)
  83. die("failed to write");
  84. size -= ret;
  85. buf += ret;
  86. bytes_written += ret;
  87. }
  88. }
  89. static void mmap_read(struct mmap_data *md)
  90. {
  91. unsigned int head = mmap_read_head(md);
  92. unsigned int old = md->prev;
  93. unsigned char *data = md->base + page_size;
  94. unsigned long size;
  95. void *buf;
  96. int diff;
  97. gettimeofday(&this_read, NULL);
  98. /*
  99. * If we're further behind than half the buffer, there's a chance
  100. * the writer will bite our tail and mess up the samples under us.
  101. *
  102. * If we somehow ended up ahead of the head, we got messed up.
  103. *
  104. * In either case, truncate and restart at head.
  105. */
  106. diff = head - old;
  107. if (diff < 0) {
  108. struct timeval iv;
  109. unsigned long msecs;
  110. timersub(&this_read, &last_read, &iv);
  111. msecs = iv.tv_sec*1000 + iv.tv_usec/1000;
  112. fprintf(stderr, "WARNING: failed to keep up with mmap data."
  113. " Last read %lu msecs ago.\n", msecs);
  114. /*
  115. * head points to a known good entry, start there.
  116. */
  117. old = head;
  118. }
  119. last_read = this_read;
  120. if (old != head)
  121. samples++;
  122. size = head - old;
  123. if ((old & md->mask) + size != (head & md->mask)) {
  124. buf = &data[old & md->mask];
  125. size = md->mask + 1 - (old & md->mask);
  126. old += size;
  127. write_output(buf, size);
  128. }
  129. buf = &data[old & md->mask];
  130. size = head - old;
  131. old += size;
  132. write_output(buf, size);
  133. md->prev = old;
  134. mmap_write_tail(md, old);
  135. }
  136. static volatile int done = 0;
  137. static volatile int signr = -1;
  138. static void sig_handler(int sig)
  139. {
  140. done = 1;
  141. signr = sig;
  142. }
  143. static void sig_atexit(void)
  144. {
  145. if (child_pid != -1)
  146. kill(child_pid, SIGTERM);
  147. if (signr == -1)
  148. return;
  149. signal(signr, SIG_DFL);
  150. kill(getpid(), signr);
  151. }
  152. static pid_t pid_synthesize_comm_event(pid_t pid, int full)
  153. {
  154. struct comm_event comm_ev;
  155. char filename[PATH_MAX];
  156. char bf[BUFSIZ];
  157. FILE *fp;
  158. size_t size = 0;
  159. DIR *tasks;
  160. struct dirent dirent, *next;
  161. pid_t tgid = 0;
  162. snprintf(filename, sizeof(filename), "/proc/%d/status", pid);
  163. fp = fopen(filename, "r");
  164. if (fp == NULL) {
  165. /*
  166. * We raced with a task exiting - just return:
  167. */
  168. if (verbose)
  169. fprintf(stderr, "couldn't open %s\n", filename);
  170. return 0;
  171. }
  172. memset(&comm_ev, 0, sizeof(comm_ev));
  173. while (!comm_ev.comm[0] || !comm_ev.pid) {
  174. if (fgets(bf, sizeof(bf), fp) == NULL)
  175. goto out_failure;
  176. if (memcmp(bf, "Name:", 5) == 0) {
  177. char *name = bf + 5;
  178. while (*name && isspace(*name))
  179. ++name;
  180. size = strlen(name) - 1;
  181. memcpy(comm_ev.comm, name, size++);
  182. } else if (memcmp(bf, "Tgid:", 5) == 0) {
  183. char *tgids = bf + 5;
  184. while (*tgids && isspace(*tgids))
  185. ++tgids;
  186. tgid = comm_ev.pid = atoi(tgids);
  187. }
  188. }
  189. comm_ev.header.type = PERF_RECORD_COMM;
  190. size = ALIGN(size, sizeof(u64));
  191. comm_ev.header.size = sizeof(comm_ev) - (sizeof(comm_ev.comm) - size);
  192. if (!full) {
  193. comm_ev.tid = pid;
  194. write_output(&comm_ev, comm_ev.header.size);
  195. goto out_fclose;
  196. }
  197. snprintf(filename, sizeof(filename), "/proc/%d/task", pid);
  198. tasks = opendir(filename);
  199. while (!readdir_r(tasks, &dirent, &next) && next) {
  200. char *end;
  201. pid = strtol(dirent.d_name, &end, 10);
  202. if (*end)
  203. continue;
  204. comm_ev.tid = pid;
  205. write_output(&comm_ev, comm_ev.header.size);
  206. }
  207. closedir(tasks);
  208. out_fclose:
  209. fclose(fp);
  210. return tgid;
  211. out_failure:
  212. fprintf(stderr, "couldn't get COMM and pgid, malformed %s\n",
  213. filename);
  214. exit(EXIT_FAILURE);
  215. }
  216. static void pid_synthesize_mmap_samples(pid_t pid, pid_t tgid)
  217. {
  218. char filename[PATH_MAX];
  219. FILE *fp;
  220. snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
  221. fp = fopen(filename, "r");
  222. if (fp == NULL) {
  223. /*
  224. * We raced with a task exiting - just return:
  225. */
  226. if (verbose)
  227. fprintf(stderr, "couldn't open %s\n", filename);
  228. return;
  229. }
  230. while (1) {
  231. char bf[BUFSIZ], *pbf = bf;
  232. struct mmap_event mmap_ev = {
  233. .header = { .type = PERF_RECORD_MMAP },
  234. };
  235. int n;
  236. size_t size;
  237. if (fgets(bf, sizeof(bf), fp) == NULL)
  238. break;
  239. /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
  240. n = hex2u64(pbf, &mmap_ev.start);
  241. if (n < 0)
  242. continue;
  243. pbf += n + 1;
  244. n = hex2u64(pbf, &mmap_ev.len);
  245. if (n < 0)
  246. continue;
  247. pbf += n + 3;
  248. if (*pbf == 'x') { /* vm_exec */
  249. char *execname = strchr(bf, '/');
  250. /* Catch VDSO */
  251. if (execname == NULL)
  252. execname = strstr(bf, "[vdso]");
  253. if (execname == NULL)
  254. continue;
  255. size = strlen(execname);
  256. execname[size - 1] = '\0'; /* Remove \n */
  257. memcpy(mmap_ev.filename, execname, size);
  258. size = ALIGN(size, sizeof(u64));
  259. mmap_ev.len -= mmap_ev.start;
  260. mmap_ev.header.size = (sizeof(mmap_ev) -
  261. (sizeof(mmap_ev.filename) - size));
  262. mmap_ev.pid = tgid;
  263. mmap_ev.tid = pid;
  264. write_output(&mmap_ev, mmap_ev.header.size);
  265. }
  266. }
  267. fclose(fp);
  268. }
  269. static void synthesize_all(void)
  270. {
  271. DIR *proc;
  272. struct dirent dirent, *next;
  273. proc = opendir("/proc");
  274. while (!readdir_r(proc, &dirent, &next) && next) {
  275. char *end;
  276. pid_t pid, tgid;
  277. pid = strtol(dirent.d_name, &end, 10);
  278. if (*end) /* only interested in proper numerical dirents */
  279. continue;
  280. tgid = pid_synthesize_comm_event(pid, 1);
  281. pid_synthesize_mmap_samples(pid, tgid);
  282. }
  283. closedir(proc);
  284. }
  285. static int group_fd;
  286. static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int nr)
  287. {
  288. struct perf_header_attr *h_attr;
  289. if (nr < header->attrs) {
  290. h_attr = header->attr[nr];
  291. } else {
  292. h_attr = perf_header_attr__new(a);
  293. perf_header__add_attr(header, h_attr);
  294. }
  295. return h_attr;
  296. }
  297. static void create_counter(int counter, int cpu, pid_t pid)
  298. {
  299. struct perf_event_attr *attr = attrs + counter;
  300. struct perf_header_attr *h_attr;
  301. int track = !counter; /* only the first counter needs these */
  302. struct {
  303. u64 count;
  304. u64 time_enabled;
  305. u64 time_running;
  306. u64 id;
  307. } read_data;
  308. attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
  309. PERF_FORMAT_TOTAL_TIME_RUNNING |
  310. PERF_FORMAT_ID;
  311. attr->sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID;
  312. if (freq) {
  313. attr->sample_type |= PERF_SAMPLE_PERIOD;
  314. attr->freq = 1;
  315. attr->sample_freq = freq;
  316. }
  317. if (no_samples)
  318. attr->sample_freq = 0;
  319. if (inherit_stat)
  320. attr->inherit_stat = 1;
  321. if (sample_address)
  322. attr->sample_type |= PERF_SAMPLE_ADDR;
  323. if (call_graph)
  324. attr->sample_type |= PERF_SAMPLE_CALLCHAIN;
  325. if (raw_samples) {
  326. attr->sample_type |= PERF_SAMPLE_TIME;
  327. attr->sample_type |= PERF_SAMPLE_RAW;
  328. attr->sample_type |= PERF_SAMPLE_CPU;
  329. }
  330. attr->mmap = track;
  331. attr->comm = track;
  332. attr->inherit = (cpu < 0) && inherit;
  333. attr->disabled = 1;
  334. try_again:
  335. fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
  336. if (fd[nr_cpu][counter] < 0) {
  337. int err = errno;
  338. if (err == EPERM)
  339. die("Permission error - are you root?\n");
  340. else if (err == ENODEV && profile_cpu != -1)
  341. die("No such device - did you specify an out-of-range profile CPU?\n");
  342. /*
  343. * If it's cycles then fall back to hrtimer
  344. * based cpu-clock-tick sw counter, which
  345. * is always available even if no PMU support:
  346. */
  347. if (attr->type == PERF_TYPE_HARDWARE
  348. && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
  349. if (verbose)
  350. warning(" ... trying to fall back to cpu-clock-ticks\n");
  351. attr->type = PERF_TYPE_SOFTWARE;
  352. attr->config = PERF_COUNT_SW_CPU_CLOCK;
  353. goto try_again;
  354. }
  355. printf("\n");
  356. error("perfcounter syscall returned with %d (%s)\n",
  357. fd[nr_cpu][counter], strerror(err));
  358. die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
  359. exit(-1);
  360. }
  361. h_attr = get_header_attr(attr, counter);
  362. if (!file_new) {
  363. if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
  364. fprintf(stderr, "incompatible append\n");
  365. exit(-1);
  366. }
  367. }
  368. if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) {
  369. perror("Unable to read perf file descriptor\n");
  370. exit(-1);
  371. }
  372. perf_header_attr__add_id(h_attr, read_data.id);
  373. assert(fd[nr_cpu][counter] >= 0);
  374. fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
  375. /*
  376. * First counter acts as the group leader:
  377. */
  378. if (group && group_fd == -1)
  379. group_fd = fd[nr_cpu][counter];
  380. if (multiplex && multiplex_fd == -1)
  381. multiplex_fd = fd[nr_cpu][counter];
  382. if (multiplex && fd[nr_cpu][counter] != multiplex_fd) {
  383. int ret;
  384. ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
  385. assert(ret != -1);
  386. } else {
  387. event_array[nr_poll].fd = fd[nr_cpu][counter];
  388. event_array[nr_poll].events = POLLIN;
  389. nr_poll++;
  390. mmap_array[nr_cpu][counter].counter = counter;
  391. mmap_array[nr_cpu][counter].prev = 0;
  392. mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1;
  393. mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
  394. PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0);
  395. if (mmap_array[nr_cpu][counter].base == MAP_FAILED) {
  396. error("failed to mmap with %d (%s)\n", errno, strerror(errno));
  397. exit(-1);
  398. }
  399. }
  400. ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
  401. }
  402. static void open_counters(int cpu, pid_t pid)
  403. {
  404. int counter;
  405. group_fd = -1;
  406. for (counter = 0; counter < nr_counters; counter++)
  407. create_counter(counter, cpu, pid);
  408. nr_cpu++;
  409. }
  410. static void atexit_header(void)
  411. {
  412. header->data_size += bytes_written;
  413. perf_header__write(header, output);
  414. }
  415. static int __cmd_record(int argc, const char **argv)
  416. {
  417. int i, counter;
  418. struct stat st;
  419. pid_t pid = 0;
  420. int flags;
  421. int ret;
  422. unsigned long waking = 0;
  423. page_size = sysconf(_SC_PAGE_SIZE);
  424. nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
  425. assert(nr_cpus <= MAX_NR_CPUS);
  426. assert(nr_cpus >= 0);
  427. atexit(sig_atexit);
  428. signal(SIGCHLD, sig_handler);
  429. signal(SIGINT, sig_handler);
  430. if (!stat(output_name, &st) && st.st_size) {
  431. if (!force && !append_file) {
  432. fprintf(stderr, "Error, output file %s exists, use -A to append or -f to overwrite.\n",
  433. output_name);
  434. exit(-1);
  435. }
  436. } else {
  437. append_file = 0;
  438. }
  439. flags = O_CREAT|O_RDWR;
  440. if (append_file)
  441. file_new = 0;
  442. else
  443. flags |= O_TRUNC;
  444. output = open(output_name, flags, S_IRUSR|S_IWUSR);
  445. if (output < 0) {
  446. perror("failed to create output file");
  447. exit(-1);
  448. }
  449. if (!file_new)
  450. header = perf_header__read(output);
  451. else
  452. header = perf_header__new();
  453. if (raw_samples) {
  454. perf_header__set_trace_info();
  455. } else {
  456. for (i = 0; i < nr_counters; i++) {
  457. if (attrs[i].sample_type & PERF_SAMPLE_RAW) {
  458. perf_header__set_trace_info();
  459. break;
  460. }
  461. }
  462. }
  463. atexit(atexit_header);
  464. if (!system_wide) {
  465. pid = target_pid;
  466. if (pid == -1)
  467. pid = getpid();
  468. open_counters(profile_cpu, pid);
  469. } else {
  470. if (profile_cpu != -1) {
  471. open_counters(profile_cpu, target_pid);
  472. } else {
  473. for (i = 0; i < nr_cpus; i++)
  474. open_counters(i, target_pid);
  475. }
  476. }
  477. if (file_new)
  478. perf_header__write(header, output);
  479. if (!system_wide) {
  480. pid_t tgid = pid_synthesize_comm_event(pid, 0);
  481. pid_synthesize_mmap_samples(pid, tgid);
  482. } else
  483. synthesize_all();
  484. if (target_pid == -1 && argc) {
  485. pid = fork();
  486. if (pid < 0)
  487. perror("failed to fork");
  488. if (!pid) {
  489. if (execvp(argv[0], (char **)argv)) {
  490. perror(argv[0]);
  491. exit(-1);
  492. }
  493. }
  494. child_pid = pid;
  495. }
  496. if (realtime_prio) {
  497. struct sched_param param;
  498. param.sched_priority = realtime_prio;
  499. if (sched_setscheduler(0, SCHED_FIFO, &param)) {
  500. printf("Could not set realtime priority.\n");
  501. exit(-1);
  502. }
  503. }
  504. for (;;) {
  505. int hits = samples;
  506. for (i = 0; i < nr_cpu; i++) {
  507. for (counter = 0; counter < nr_counters; counter++) {
  508. if (mmap_array[i][counter].base)
  509. mmap_read(&mmap_array[i][counter]);
  510. }
  511. }
  512. if (hits == samples) {
  513. if (done)
  514. break;
  515. ret = poll(event_array, nr_poll, -1);
  516. waking++;
  517. }
  518. if (done) {
  519. for (i = 0; i < nr_cpu; i++) {
  520. for (counter = 0; counter < nr_counters; counter++)
  521. ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE);
  522. }
  523. }
  524. }
  525. fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);
  526. /*
  527. * Approximate RIP event size: 24 bytes.
  528. */
  529. fprintf(stderr,
  530. "[ perf record: Captured and wrote %.3f MB %s (~%lld samples) ]\n",
  531. (double)bytes_written / 1024.0 / 1024.0,
  532. output_name,
  533. bytes_written / 24);
  534. return 0;
  535. }
  536. static const char * const record_usage[] = {
  537. "perf record [<options>] [<command>]",
  538. "perf record [<options>] -- <command> [<options>]",
  539. NULL
  540. };
  541. static const struct option options[] = {
  542. OPT_CALLBACK('e', "event", NULL, "event",
  543. "event selector. use 'perf list' to list available events",
  544. parse_events),
  545. OPT_INTEGER('p', "pid", &target_pid,
  546. "record events on existing pid"),
  547. OPT_INTEGER('r', "realtime", &realtime_prio,
  548. "collect data with this RT SCHED_FIFO priority"),
  549. OPT_BOOLEAN('R', "raw-samples", &raw_samples,
  550. "collect raw sample records from all opened counters"),
  551. OPT_BOOLEAN('a', "all-cpus", &system_wide,
  552. "system-wide collection from all CPUs"),
  553. OPT_BOOLEAN('A', "append", &append_file,
  554. "append to the output file to do incremental profiling"),
  555. OPT_INTEGER('C', "profile_cpu", &profile_cpu,
  556. "CPU to profile on"),
  557. OPT_BOOLEAN('f', "force", &force,
  558. "overwrite existing data file"),
  559. OPT_LONG('c', "count", &default_interval,
  560. "event period to sample"),
  561. OPT_STRING('o', "output", &output_name, "file",
  562. "output file name"),
  563. OPT_BOOLEAN('i', "inherit", &inherit,
  564. "child tasks inherit counters"),
  565. OPT_INTEGER('F', "freq", &freq,
  566. "profile at this frequency"),
  567. OPT_INTEGER('m', "mmap-pages", &mmap_pages,
  568. "number of mmap data pages"),
  569. OPT_BOOLEAN('g', "call-graph", &call_graph,
  570. "do call-graph (stack chain/backtrace) recording"),
  571. OPT_BOOLEAN('v', "verbose", &verbose,
  572. "be more verbose (show counter open errors, etc)"),
  573. OPT_BOOLEAN('s', "stat", &inherit_stat,
  574. "per thread counts"),
  575. OPT_BOOLEAN('d', "data", &sample_address,
  576. "Sample addresses"),
  577. OPT_BOOLEAN('n', "no-samples", &no_samples,
  578. "don't sample"),
  579. OPT_BOOLEAN('M', "multiplex", &multiplex,
  580. "multiplex counter output in a single channel"),
  581. OPT_END()
  582. };
  583. int cmd_record(int argc, const char **argv, const char *prefix __used)
  584. {
  585. int counter;
  586. argc = parse_options(argc, argv, options, record_usage,
  587. PARSE_OPT_STOP_AT_NON_OPTION);
  588. if (!argc && target_pid == -1 && !system_wide)
  589. usage_with_options(record_usage, options);
  590. if (!nr_counters) {
  591. nr_counters = 1;
  592. attrs[0].type = PERF_TYPE_HARDWARE;
  593. attrs[0].config = PERF_COUNT_HW_CPU_CYCLES;
  594. }
  595. for (counter = 0; counter < nr_counters; counter++) {
  596. if (attrs[counter].sample_period)
  597. continue;
  598. attrs[counter].sample_period = default_interval;
  599. }
  600. return __cmd_record(argc, argv);
  601. }