Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147570
b: refs/heads/master
c: 2996f5d
h: refs/heads/master
v: v3
  • Loading branch information
Ingo Molnar committed May 29, 2009
1 parent d9b63b0 commit 44b7494
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 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: c04f5e5d7b523f90ee3cdd70a68c4002aaecd3fa
refs/heads/master: 2996f5ddb7ba8889caeeac65edafe48845106eaa
40 changes: 34 additions & 6 deletions trunk/Documentation/perf_counter/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ static const unsigned int default_count[] = {
10000,
};

static __u64 event_res[MAX_COUNTERS][3];
static __u64 event_scaled[MAX_COUNTERS];

static void create_perfstat_counter(int counter)
{
struct perf_counter_hw_event hw_event;
Expand Down Expand Up @@ -123,16 +126,19 @@ static inline int nsec_counter(int counter)
}

/*
* Print out the results of a single counter:
* Read out the results of a single counter:
*/
static void print_counter(int counter)
static void read_counter(int counter)
{
__u64 count[3], single_count[3];
__u64 *count, single_count[3];
ssize_t res;
int cpu, nv;
int scaled;

count = event_res[counter];

count[0] = count[1] = count[2] = 0;

nv = scale ? 3 : 1;
for (cpu = 0; cpu < nr_cpus; cpu ++) {
res = read(fd[cpu][counter], single_count, nv * sizeof(__u64));
Expand All @@ -148,16 +154,35 @@ static void print_counter(int counter)
scaled = 0;
if (scale) {
if (count[2] == 0) {
fprintf(stderr, " %14s %-20s\n",
"<not counted>", event_name(counter));
event_scaled[counter] = -1;
count[0] = 0;
return;
}

if (count[2] < count[1]) {
scaled = 1;
event_scaled[counter] = 1;
count[0] = (unsigned long long)
((double)count[0] * count[1] / count[2] + 0.5);
}
}
}

/*
* Print out the results of a single counter:
*/
static void print_counter(int counter)
{
__u64 *count;
int scaled;

count = event_res[counter];
scaled = event_scaled[counter];

if (scaled == -1) {
fprintf(stderr, " %14s %-20s\n",
"<not counted>", event_name(counter));
return;
}

if (nsec_counter(counter)) {
double msecs = (double)count[0] / 1000000;
Expand Down Expand Up @@ -213,6 +238,9 @@ static int do_perfstat(int argc, const char **argv)
argv[0]);
fprintf(stderr, "\n");

for (counter = 0; counter < nr_counters; counter++)
read_counter(counter);

for (counter = 0; counter < nr_counters; counter++)
print_counter(counter);

Expand Down

0 comments on commit 44b7494

Please sign in to comment.