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 | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 47 | static int system_wide = 0; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 48 | static int inherit = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 49 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 50 | static __u64 default_event_id[MAX_COUNTERS] = { |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 51 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK), |
| 52 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CONTEXT_SWITCHES), |
| 53 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), |
| 54 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_PAGE_FAULTS), |
| 55 | |
| 56 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CPU_CYCLES), |
| 57 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_INSTRUCTIONS), |
| 58 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_REFERENCES), |
| 59 | EID(PERF_TYPE_HARDWARE, PERF_COUNT_CACHE_MISSES), |
| 60 | }; |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 61 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 62 | static int default_interval = 100000; |
| 63 | static int event_count[MAX_COUNTERS]; |
| 64 | static int fd[MAX_NR_CPUS][MAX_COUNTERS]; |
| 65 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 66 | static int target_pid = -1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 67 | static int nr_cpus = 0; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 68 | static unsigned int page_size; |
| 69 | |
Ingo Molnar | 66cf782 | 2009-04-30 13:53:33 +0200 | [diff] [blame] | 70 | static int scale = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 71 | |
| 72 | static const unsigned int default_count[] = { |
| 73 | 1000000, |
| 74 | 1000000, |
| 75 | 10000, |
| 76 | 10000, |
| 77 | 1000000, |
| 78 | 10000, |
| 79 | }; |
| 80 | |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 81 | static __u64 event_res[MAX_COUNTERS][3]; |
| 82 | static __u64 event_scaled[MAX_COUNTERS]; |
| 83 | |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 84 | static __u64 runtime_nsecs; |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 85 | static __u64 walltime_nsecs; |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 86 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 87 | static void create_perfstat_counter(int counter) |
| 88 | { |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 89 | struct perf_counter_attr attr; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 90 | |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 91 | memset(&attr, 0, sizeof(attr)); |
| 92 | attr.config = event_id[counter]; |
| 93 | attr.sample_type = 0; |
| 94 | attr.exclude_kernel = event_mask[counter] & EVENT_MASK_KERNEL; |
| 95 | attr.exclude_user = event_mask[counter] & EVENT_MASK_USER; |
Peter Zijlstra | 16c8a10 | 2009-05-05 17:50:27 +0200 | [diff] [blame] | 96 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 97 | if (scale) |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 98 | attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 99 | PERF_FORMAT_TOTAL_TIME_RUNNING; |
| 100 | |
| 101 | if (system_wide) { |
| 102 | int cpu; |
| 103 | for (cpu = 0; cpu < nr_cpus; cpu ++) { |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 104 | fd[cpu][counter] = sys_perf_counter_open(&attr, -1, cpu, -1, 0); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 105 | if (fd[cpu][counter] < 0) { |
| 106 | printf("perfstat error: syscall returned with %d (%s)\n", |
| 107 | fd[cpu][counter], strerror(errno)); |
| 108 | exit(-1); |
| 109 | } |
| 110 | } |
| 111 | } else { |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 112 | attr.inherit = inherit; |
| 113 | attr.disabled = 1; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 114 | |
Peter Zijlstra | c70975b | 2009-06-02 17:38:21 +0200 | [diff] [blame] | 115 | fd[0][counter] = sys_perf_counter_open(&attr, 0, -1, -1, 0); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 116 | if (fd[0][counter] < 0) { |
| 117 | printf("perfstat error: syscall returned with %d (%s)\n", |
| 118 | fd[0][counter], strerror(errno)); |
| 119 | exit(-1); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 124 | /* |
| 125 | * Does the counter have nsecs as a unit? |
| 126 | */ |
| 127 | static inline int nsec_counter(int counter) |
| 128 | { |
| 129 | if (event_id[counter] == EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_CLOCK)) |
| 130 | return 1; |
| 131 | if (event_id[counter] == EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK)) |
| 132 | return 1; |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 138 | * Read out the results of a single counter: |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 139 | */ |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 140 | static void read_counter(int counter) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 141 | { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 142 | __u64 *count, single_count[3]; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 143 | ssize_t res; |
| 144 | int cpu, nv; |
| 145 | int scaled; |
| 146 | |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 147 | count = event_res[counter]; |
| 148 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 149 | count[0] = count[1] = count[2] = 0; |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 150 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 151 | nv = scale ? 3 : 1; |
| 152 | for (cpu = 0; cpu < nr_cpus; cpu ++) { |
| 153 | res = read(fd[cpu][counter], single_count, nv * sizeof(__u64)); |
| 154 | assert(res == nv * sizeof(__u64)); |
| 155 | |
| 156 | count[0] += single_count[0]; |
| 157 | if (scale) { |
| 158 | count[1] += single_count[1]; |
| 159 | count[2] += single_count[2]; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | scaled = 0; |
| 164 | if (scale) { |
| 165 | if (count[2] == 0) { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 166 | event_scaled[counter] = -1; |
| 167 | count[0] = 0; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 168 | return; |
| 169 | } |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 170 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 171 | if (count[2] < count[1]) { |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 172 | event_scaled[counter] = 1; |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 173 | count[0] = (unsigned long long) |
| 174 | ((double)count[0] * count[1] / count[2] + 0.5); |
| 175 | } |
| 176 | } |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 177 | /* |
| 178 | * Save the full runtime - to allow normalization during printout: |
| 179 | */ |
| 180 | if (event_id[counter] == EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK)) |
| 181 | runtime_nsecs = count[0]; |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Print out the results of a single counter: |
| 186 | */ |
| 187 | static void print_counter(int counter) |
| 188 | { |
| 189 | __u64 *count; |
| 190 | int scaled; |
| 191 | |
| 192 | count = event_res[counter]; |
| 193 | scaled = event_scaled[counter]; |
| 194 | |
| 195 | if (scaled == -1) { |
| 196 | fprintf(stderr, " %14s %-20s\n", |
| 197 | "<not counted>", event_name(counter)); |
| 198 | return; |
| 199 | } |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 200 | |
| 201 | if (nsec_counter(counter)) { |
| 202 | double msecs = (double)count[0] / 1000000; |
| 203 | |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 204 | fprintf(stderr, " %14.6f %-20s", |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 205 | msecs, event_name(counter)); |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 206 | if (event_id[counter] == |
| 207 | EID(PERF_TYPE_SOFTWARE, PERF_COUNT_TASK_CLOCK)) { |
| 208 | |
| 209 | fprintf(stderr, " # %11.3f CPU utilization factor", |
| 210 | (double)count[0] / (double)walltime_nsecs); |
| 211 | } |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 212 | } else { |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 213 | fprintf(stderr, " %14Ld %-20s", |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 214 | count[0], event_name(counter)); |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 215 | if (runtime_nsecs) |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 216 | fprintf(stderr, " # %11.3f M/sec", |
Ingo Molnar | be1ac0d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 217 | (double)count[0]/runtime_nsecs*1000.0); |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 218 | } |
| 219 | if (scaled) |
| 220 | fprintf(stderr, " (scaled from %.2f%%)", |
| 221 | (double) count[2] / count[1] * 100); |
| 222 | fprintf(stderr, "\n"); |
| 223 | } |
| 224 | |
Ingo Molnar | 16f762a | 2009-05-27 09:10:38 +0200 | [diff] [blame] | 225 | static int do_perfstat(int argc, const char **argv) |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 226 | { |
| 227 | unsigned long long t0, t1; |
| 228 | int counter; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 229 | int status; |
| 230 | int pid; |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame^] | 231 | int i; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 232 | |
| 233 | if (!system_wide) |
| 234 | nr_cpus = 1; |
| 235 | |
| 236 | for (counter = 0; counter < nr_counters; counter++) |
| 237 | create_perfstat_counter(counter); |
| 238 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 239 | /* |
| 240 | * Enable counters and exec the command: |
| 241 | */ |
| 242 | t0 = rdclock(); |
| 243 | prctl(PR_TASK_PERF_COUNTERS_ENABLE); |
| 244 | |
| 245 | if ((pid = fork()) < 0) |
| 246 | perror("failed to fork"); |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame^] | 247 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 248 | if (!pid) { |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 249 | if (execvp(argv[0], (char **)argv)) { |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 250 | perror(argv[0]); |
| 251 | exit(-1); |
| 252 | } |
| 253 | } |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame^] | 254 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 255 | while (wait(&status) >= 0) |
| 256 | ; |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame^] | 257 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 258 | prctl(PR_TASK_PERF_COUNTERS_DISABLE); |
| 259 | t1 = rdclock(); |
| 260 | |
Ingo Molnar | d7c2931 | 2009-05-30 12:38:51 +0200 | [diff] [blame] | 261 | walltime_nsecs = t1 - t0; |
| 262 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 263 | fflush(stdout); |
| 264 | |
| 265 | fprintf(stderr, "\n"); |
Ingo Molnar | 44db76c | 2009-06-03 19:36:07 +0200 | [diff] [blame^] | 266 | fprintf(stderr, " Performance counter stats for \'%s", argv[0]); |
| 267 | |
| 268 | for (i = 1; i < argc; i++) |
| 269 | fprintf(stderr, " %s", argv[i]); |
| 270 | |
| 271 | fprintf(stderr, "\':\n"); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 272 | fprintf(stderr, "\n"); |
| 273 | |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 274 | for (counter = 0; counter < nr_counters; counter++) |
Ingo Molnar | 2996f5d | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 275 | read_counter(counter); |
| 276 | |
| 277 | for (counter = 0; counter < nr_counters; counter++) |
Ingo Molnar | c04f5e5 | 2009-05-29 09:10:54 +0200 | [diff] [blame] | 278 | print_counter(counter); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 279 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 280 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 281 | fprintf(stderr, "\n"); |
| 282 | fprintf(stderr, " Wall-clock time elapsed: %12.6f msecs\n", |
| 283 | (double)(t1-t0)/1e6); |
| 284 | fprintf(stderr, "\n"); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 289 | static void skip_signal(int signo) |
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 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 292 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 293 | static const char * const stat_usage[] = { |
| 294 | "perf stat [<options>] <command>", |
| 295 | NULL |
| 296 | }; |
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 char events_help_msg[EVENTS_HELP_MAX]; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 299 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 300 | static const struct option options[] = { |
| 301 | OPT_CALLBACK('e', "event", NULL, "event", |
| 302 | events_help_msg, parse_events), |
| 303 | OPT_INTEGER('c', "count", &default_interval, |
| 304 | "event period to sample"), |
| 305 | OPT_BOOLEAN('i', "inherit", &inherit, |
| 306 | "child tasks inherit counters"), |
| 307 | OPT_INTEGER('p', "pid", &target_pid, |
| 308 | "stat events on existing pid"), |
| 309 | OPT_BOOLEAN('a', "all-cpus", &system_wide, |
| 310 | "system-wide collection from all CPUs"), |
| 311 | OPT_BOOLEAN('l', "scale", &scale, |
| 312 | "scale/normalize counters"), |
| 313 | OPT_END() |
| 314 | }; |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 315 | |
Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 316 | int cmd_stat(int argc, const char **argv, const char *prefix) |
| 317 | { |
| 318 | int counter; |
| 319 | |
| 320 | page_size = sysconf(_SC_PAGE_SIZE); |
| 321 | |
| 322 | create_events_help(events_help_msg); |
| 323 | memcpy(event_id, default_event_id, sizeof(default_event_id)); |
| 324 | |
| 325 | argc = parse_options(argc, argv, options, stat_usage, 0); |
| 326 | if (!argc) |
| 327 | usage_with_options(stat_usage, options); |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 328 | |
| 329 | if (!nr_counters) { |
| 330 | nr_counters = 8; |
| 331 | } |
| 332 | |
| 333 | for (counter = 0; counter < nr_counters; counter++) { |
| 334 | if (event_count[counter]) |
| 335 | continue; |
| 336 | |
| 337 | event_count[counter] = default_interval; |
| 338 | } |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 339 | nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); |
| 340 | assert(nr_cpus <= MAX_NR_CPUS); |
| 341 | assert(nr_cpus >= 0); |
| 342 | |
Ingo Molnar | 58d7e99 | 2009-05-15 11:03:23 +0200 | [diff] [blame] | 343 | /* |
| 344 | * We dont want to block the signals - that would cause |
| 345 | * child tasks to inherit that and Ctrl-C would not work. |
| 346 | * What we want is for Ctrl-C to work in the exec()-ed |
| 347 | * task, but being ignored by perf stat itself: |
| 348 | */ |
| 349 | signal(SIGINT, skip_signal); |
| 350 | signal(SIGALRM, skip_signal); |
| 351 | signal(SIGABRT, skip_signal); |
| 352 | |
Ingo Molnar | ddcacfa | 2009-04-20 15:37:32 +0200 | [diff] [blame] | 353 | return do_perfstat(argc, argv); |
| 354 | } |