Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 1 | /* |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 2 | * builtin-stat.c |
| 3 | * |
| 4 | * Builtin stat command: Give a precise performance counters summary |
| 5 | * overview about any workload, CPU or specific PID. |
| 6 | * |
| 7 | * Sample output: |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 8 | |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 9 | $ perf stat ~/hackbench 10 |
| 10 | Time: 0.104 |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 11 | |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 12 | Performance counter stats for '/home/mingo/hackbench': |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 13 | |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 14 | 1255.538611 task clock ticks # 10.143 CPU utilization factor |
| 15 | 54011 context switches # 0.043 M/sec |
| 16 | 385 CPU migrations # 0.000 M/sec |
| 17 | 17755 pagefaults # 0.014 M/sec |
| 18 | 3808323185 CPU cycles # 3033.219 M/sec |
| 19 | 1575111190 instructions # 1254.530 M/sec |
| 20 | 17367895 cache references # 13.833 M/sec |
| 21 | 7674421 cache misses # 6.112 M/sec |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 22 | |
Ingo Molnar | bf9e187 | 2009-06-02 23:37:05 +0200 | [diff] [blame] | 23 | Wall-clock time elapsed: 123.786620 msecs |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 24 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 25 | * |
| 26 | * Copyright (C) 2008, Red Hat Inc, Ingo Molnar <mingo@redhat.com> |
| 27 | * |
| 28 | * Improvements and fixes by: |
| 29 | * |
| 30 | * Arjan van de Ven <arjan@linux.intel.com> |
| 31 | * Yanmin Zhang <yanmin.zhang@intel.com> |
| 32 | * Wu Fengguang <fengguang.wu@intel.com> |
| 33 | * Mike Galbraith <efault@gmx.de> |
| 34 | * Paul Mackerras <paulus@samba.org> |
| 35 | * |
| 36 | * Released under the GPL v2. (and only v2, not any later version) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 37 | */ |
| 38 | |
Peter Zijlstra | 1a482f3 | 2009-05-23 18:28:58 +0200 | [diff] [blame] | 39 | #include "perf.h" |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 40 | #include "builtin.h" |
Ingo Molnar | 148be2c | 2009-04-27 08:02:14 +0200 | [diff] [blame] | 41 | #include "util/util.h" |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 42 | #include "util/parse-options.h" |
| 43 | #include "util/parse-events.h" |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 44 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 45 | #include <sys/prctl.h> |
Peter Zijlstra | 16c8a10 | 2009-05-05 17:50:27 +0200 | [diff] [blame] | 46 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 47 | static struct perf_counter_attr default_attrs[MAX_COUNTERS] = { |
| 48 | |
| 49 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_TASK_CLOCK }, |
| 50 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_CONTEXT_SWITCHES }, |
| 51 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_CPU_MIGRATIONS }, |
| 52 | { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_PAGE_FAULTS }, |
| 53 | |
| 54 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CPU_CYCLES }, |
| 55 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_INSTRUCTIONS }, |
| 56 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CACHE_REFERENCES }, |
| 57 | { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CACHE_MISSES }, |
| 58 | }; |
| 59 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 60 | static int system_wide = 0; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 61 | static int inherit = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 62 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 63 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; |
| 64 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 65 | static int target_pid = -1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 66 | static int nr_cpus = 0; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 67 | static unsigned int page_size; |
| 68 | |
Ingo Molnar | 66cf782 | 2009-04-30 13:53:33 +0200 | [diff] [blame] | 69 | static int scale = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 70 | |
| 71 | static const unsigned int default_count[] = { |
| 72 | 1000000, |
| 73 | 1000000, |
| 74 | 10000, |
| 75 | 10000, |
| 76 | 1000000, |
| 77 | 10000, |
| 78 | }; |
| 79 | |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 80 | static __u64 event_res[MAX_COUNTERS][3]; |
| 81 | static __u64 event_scaled[MAX_COUNTERS]; |
| 82 | |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 83 | static __u64 runtime_nsecs; |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 84 | static __u64 walltime_nsecs; |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 85 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 86 | static void create_perfstat_counter(int counter) |
| 87 | { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 88 | struct perf_counter_attr *attr = attrs + counter; |
Peter Zijlstra | 16c8a10 | 2009-05-05 17:50:27 +0200 | [diff] [blame] | 89 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 90 | if (scale) |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 91 | attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
| 92 | PERF_FORMAT_TOTAL_TIME_RUNNING; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 93 | |
| 94 | if (system_wide) { |
| 95 | int cpu; |
| 96 | for (cpu = 0; cpu < nr_cpus; cpu ++) { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 97 | fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 98 | if (fd[cpu][counter] < 0) { |
| 99 | printf("perfstat error: syscall returned with %d (%s)\n", |
| 100 | fd[cpu][counter], strerror(errno)); |
| 101 | exit(-1); |
| 102 | } |
| 103 | } |
| 104 | } else { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 105 | attr->inherit = inherit; |
| 106 | attr->disabled = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 107 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 108 | fd[0][counter] = sys_perf_counter_open(attr, 0, -1, -1, 0); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 109 | if (fd[0][counter] < 0) { |
| 110 | printf("perfstat error: syscall returned with %d (%s)\n", |
| 111 | fd[0][counter], strerror(errno)); |
| 112 | exit(-1); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 117 | /* |
| 118 | * Does the counter have nsecs as a unit? |
| 119 | */ |
| 120 | static inline int nsec_counter(int counter) |
| 121 | { |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 122 | if (attrs[counter].type != PERF_TYPE_SOFTWARE) |
| 123 | return 0; |
| 124 | |
| 125 | if (attrs[counter].config == PERF_COUNT_CPU_CLOCK) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 126 | return 1; |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 127 | |
| 128 | if (attrs[counter].config == PERF_COUNT_TASK_CLOCK) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 129 | return 1; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | /* |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 135 | * Read out the results of a single counter: |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 136 | */ |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 137 | static void read_counter(int counter) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 138 | { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 139 | __u64 *count, single_count[3]; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 140 | ssize_t res; |
| 141 | int cpu, nv; |
| 142 | int scaled; |
| 143 | |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 144 | count = event_res[counter]; |
| 145 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 146 | count[0] = count[1] = count[2] = 0; |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 147 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 148 | nv = scale ? 3 : 1; |
| 149 | for (cpu = 0; cpu < nr_cpus; cpu ++) { |
| 150 | res = read(fd[cpu][counter], single_count, nv * sizeof(__u64)); |
| 151 | assert(res == nv * sizeof(__u64)); |
| 152 | |
| 153 | count[0] += single_count[0]; |
| 154 | if (scale) { |
| 155 | count[1] += single_count[1]; |
| 156 | count[2] += single_count[2]; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | scaled = 0; |
| 161 | if (scale) { |
| 162 | if (count[2] == 0) { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 163 | event_scaled[counter] = -1; |
| 164 | count[0] = 0; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 165 | return; |
| 166 | } |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 167 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 168 | if (count[2] < count[1]) { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 169 | event_scaled[counter] = 1; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 170 | count[0] = (unsigned long long) |
| 171 | ((double)count[0] * count[1] / count[2] + 0.5); |
| 172 | } |
| 173 | } |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 174 | /* |
| 175 | * Save the full runtime - to allow normalization during printout: |
| 176 | */ |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 177 | if (attrs[counter].type == PERF_TYPE_SOFTWARE && |
| 178 | attrs[counter].config == PERF_COUNT_TASK_CLOCK) |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 179 | runtime_nsecs = count[0]; |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* |
| 183 | * Print out the results of a single counter: |
| 184 | */ |
| 185 | static void print_counter(int counter) |
| 186 | { |
| 187 | __u64 *count; |
| 188 | int scaled; |
| 189 | |
| 190 | count = event_res[counter]; |
| 191 | scaled = event_scaled[counter]; |
| 192 | |
| 193 | if (scaled == -1) { |
| 194 | fprintf(stderr, " %14s %-20s\n", |
| 195 | "<not counted>", event_name(counter)); |
| 196 | return; |
| 197 | } |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 198 | |
| 199 | if (nsec_counter(counter)) { |
| 200 | double msecs = (double)count[0] / 1000000; |
| 201 | |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 202 | fprintf(stderr, " %14.6f %-20s", |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 203 | msecs, event_name(counter)); |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 204 | if (attrs[counter].type == PERF_TYPE_SOFTWARE && |
| 205 | attrs[counter].config == PERF_COUNT_TASK_CLOCK) { |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 206 | |
| 207 | fprintf(stderr, " # %11.3f CPU utilization factor", |
| 208 | (double)count[0] / (double)walltime_nsecs); |
| 209 | } |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 210 | } else { |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 211 | fprintf(stderr, " %14Ld %-20s", |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 212 | count[0], event_name(counter)); |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 213 | if (runtime_nsecs) |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 214 | fprintf(stderr, " # %11.3f M/sec", |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 215 | (double)count[0]/runtime_nsecs*1000.0); |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 216 | } |
| 217 | if (scaled) |
| 218 | fprintf(stderr, " (scaled from %.2f%%)", |
| 219 | (double) count[2] / count[1] * 100); |
| 220 | fprintf(stderr, "\n"); |
| 221 | } |
| 222 | |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 223 | static int do_perfstat(int argc, const char **argv) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 224 | { |
| 225 | unsigned long long t0, t1; |
| 226 | int counter; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 227 | int status; |
| 228 | int pid; |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 229 | int i; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 230 | |
| 231 | if (!system_wide) |
| 232 | nr_cpus = 1; |
| 233 | |
| 234 | for (counter = 0; counter < nr_counters; counter++) |
| 235 | create_perfstat_counter(counter); |
| 236 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 237 | /* |
| 238 | * Enable counters and exec the command: |
| 239 | */ |
| 240 | t0 = rdclock(); |
| 241 | prctl(PR_TASK_PERF_COUNTERS_ENABLE); |
| 242 | |
| 243 | if ((pid = fork()) < 0) |
| 244 | perror("failed to fork"); |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 245 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 246 | if (!pid) { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 247 | if (execvp(argv[0], (char **)argv)) { |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 248 | perror(argv[0]); |
| 249 | exit(-1); |
| 250 | } |
| 251 | } |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 252 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 253 | while (wait(&status) >= 0) |
| 254 | ; |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 255 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 256 | prctl(PR_TASK_PERF_COUNTERS_DISABLE); |
| 257 | t1 = rdclock(); |
| 258 | |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 259 | walltime_nsecs = t1 - t0; |
| 260 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 261 | fflush(stdout); |
| 262 | |
| 263 | fprintf(stderr, "\n"); |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame] | 264 | fprintf(stderr, " Performance counter stats for \'%s", argv[0]); |
| 265 | |
| 266 | for (i = 1; i < argc; i++) |
| 267 | fprintf(stderr, " %s", argv[i]); |
| 268 | |
| 269 | fprintf(stderr, "\':\n"); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 270 | fprintf(stderr, "\n"); |
| 271 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 272 | for (counter = 0; counter < nr_counters; counter++) |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 273 | read_counter(counter); |
| 274 | |
| 275 | for (counter = 0; counter < nr_counters; counter++) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 276 | print_counter(counter); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 277 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 278 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 279 | fprintf(stderr, "\n"); |
| 280 | fprintf(stderr, " Wall-clock time elapsed: %12.6f msecs\n", |
| 281 | (double)(t1-t0)/1e6); |
| 282 | fprintf(stderr, "\n"); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 287 | static void skip_signal(int signo) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 288 | { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 289 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 290 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 291 | static const char * const stat_usage[] = { |
| 292 | "perf stat [<options>] <command>", |
| 293 | NULL |
| 294 | }; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 295 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 296 | static char events_help_msg[EVENTS_HELP_MAX]; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 297 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 298 | static const struct option options[] = { |
| 299 | OPT_CALLBACK('e', "event", NULL, "event", |
| 300 | events_help_msg, parse_events), |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 301 | OPT_BOOLEAN('i', "inherit", &inherit, |
| 302 | "child tasks inherit counters"), |
| 303 | OPT_INTEGER('p', "pid", &target_pid, |
| 304 | "stat events on existing pid"), |
| 305 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
| 306 | "system-wide collection from all CPUs"), |
| 307 | OPT_BOOLEAN('l', "scale", &scale, |
| 308 | "scale/normalize counters"), |
| 309 | OPT_END() |
| 310 | }; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 311 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 312 | int cmd_stat(int argc, const char **argv, const char *prefix) |
| 313 | { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 314 | page_size = sysconf(_SC_PAGE_SIZE); |
| 315 | |
| 316 | create_events_help(events_help_msg); |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 317 | |
| 318 | memcpy(attrs, default_attrs, sizeof(attrs)); |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 319 | |
| 320 | argc = parse_options(argc, argv, options, stat_usage, 0); |
| 321 | if (!argc) |
| 322 | usage_with_options(stat_usage, options); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 323 | |
Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame^] | 324 | if (!nr_counters) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 325 | nr_counters = 8; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 326 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 327 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 328 | assert(nr_cpus <= MAX_NR_CPUS); |
| 329 | assert(nr_cpus >= 0); |
| 330 | |
Ingo Molnar | 58d7e99 | 2009-05-15 11:03:23 +0200 | [diff] [blame] | 331 | /* |
| 332 | * We dont want to block the signals - that would cause |
| 333 | * child tasks to inherit that and Ctrl-C would not work. |
| 334 | * What we want is for Ctrl-C to work in the exec()-ed |
| 335 | * task, but being ignored by perf stat itself: |
| 336 | */ |
| 337 | signal(SIGINT, skip_signal); |
| 338 | signal(SIGALRM, skip_signal); |
| 339 | signal(SIGABRT, skip_signal); |
| 340 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 341 | return do_perfstat(argc, argv); |
| 342 | } |