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