Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147696
b: refs/heads/master
c: 743ee1f
h: refs/heads/master
v: v3
  • Loading branch information
Ingo Molnar committed Jun 7, 2009
1 parent a2b1964 commit 17b8239
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2f01190aa62fe9dd0a98205927b9f09fd191c017
refs/heads/master: 743ee1f80434138495bbb95ffb897acf46b51d54
31 changes: 17 additions & 14 deletions trunk/tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {

static int system_wide = 0;
static int inherit = 1;
static int verbose = 0;

static int fd[MAX_NR_CPUS][MAX_COUNTERS];

Expand All @@ -83,7 +84,7 @@ static __u64 event_scaled[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;

Expand All @@ -95,21 +96,17 @@ static void create_perfstat_counter(int 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->inherit = inherit;
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));
}
}
}
Expand Down Expand Up @@ -147,6 +144,9 @@ static void read_counter(int counter)

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));

Expand Down Expand Up @@ -204,8 +204,9 @@ static void print_counter(int counter)
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",
Expand All @@ -220,7 +221,7 @@ static void print_counter(int counter)
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;
Expand All @@ -232,7 +233,7 @@ static int do_perfstat(int argc, const char **argv)
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:
Expand Down Expand Up @@ -305,6 +306,8 @@ static const struct option options[] = {
"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()
};

Expand Down Expand Up @@ -335,5 +338,5 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
signal(SIGALRM, skip_signal);
signal(SIGABRT, skip_signal);

return do_perfstat(argc, argv);
return do_perf_stat(argc, argv);
}

0 comments on commit 17b8239

Please sign in to comment.