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