static int system_wide = 0;
static int inherit = 1;
+static int verbose = 0;
static int fd[MAX_NR_CPUS][MAX_COUNTERS];
static __u64 runtime_nsecs;
static __u64 walltime_nsecs;
-static void create_perfstat_counter(int counter)
+static void create_perf_stat_counter(int counter)
{
struct perf_counter_attr *attr = attrs + counter;
int cpu;
for (cpu = 0; cpu < nr_cpus; cpu ++) {
fd[cpu][counter] = sys_perf_counter_open(attr, -1, cpu, -1, 0);
- if (fd[cpu][counter] < 0) {
- printf("perfstat error: syscall returned with %d (%s)\n",
- fd[cpu][counter], strerror(errno));
- exit(-1);
+ if (fd[cpu][counter] < 0 && verbose) {
+ printf("Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n", counter, fd[cpu][counter], strerror(errno));
}
}
} else {
attr->disabled = 1;
fd[0][counter] = sys_perf_counter_open(attr, 0, -1, -1, 0);
- if (fd[0][counter] < 0) {
- printf("perfstat error: syscall returned with %d (%s)\n",
- fd[0][counter], strerror(errno));
- exit(-1);
+ if (fd[0][counter] < 0 && verbose) {
+ printf("Error: counter %d, sys_perf_counter_open() syscall returned with %d (%s)\n", counter, fd[0][counter], strerror(errno));
}
}
}
nv = scale ? 3 : 1;
for (cpu = 0; cpu < nr_cpus; cpu ++) {
+ if (fd[cpu][counter] < 0)
+ continue;
+
res = read(fd[cpu][counter], single_count, nv * sizeof(__u64));
assert(res == nv * sizeof(__u64));
if (attrs[counter].type == PERF_TYPE_SOFTWARE &&
attrs[counter].config == PERF_COUNT_TASK_CLOCK) {
- fprintf(stderr, " # %11.3f CPU utilization factor",
- (double)count[0] / (double)walltime_nsecs);
+ if (walltime_nsecs)
+ fprintf(stderr, " # %11.3f CPU utilization factor",
+ (double)count[0] / (double)walltime_nsecs);
}
} else {
fprintf(stderr, " %14Ld %-20s",
fprintf(stderr, "\n");
}
-static int do_perfstat(int argc, const char **argv)
+static int do_perf_stat(int argc, const char **argv)
{
unsigned long long t0, t1;
int counter;
nr_cpus = 1;
for (counter = 0; counter < nr_counters; counter++)
- create_perfstat_counter(counter);
+ create_perf_stat_counter(counter);
/*
* Enable counters and exec the command:
"system-wide collection from all CPUs"),
OPT_BOOLEAN('S', "scale", &scale,
"scale/normalize counters"),
+ OPT_BOOLEAN('v', "verbose", &verbose,
+ "be more verbose (show counter open errors, etc)"),
OPT_END()
};
signal(SIGALRM, skip_signal);
signal(SIGABRT, skip_signal);
- return do_perfstat(argc, argv);
+ return do_perf_stat(argc, argv);
}