V4L/DVB (11654): gspca - m5602: Storage class should be before const qualifier
[safe/jmp/linux-2.6] / tools / perf / builtin-stat.c
index 184ff95..c43e4a9 100644 (file)
 
 static struct perf_counter_attr default_attrs[MAX_COUNTERS] = {
 
-  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_TASK_CLOCK                },
-  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_CONTEXT_SWITCHES  },
-  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_CPU_MIGRATIONS    },
-  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_PAGE_FAULTS       },
-
-  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CPU_CYCLES                },
-  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_INSTRUCTIONS      },
-  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CACHE_REFERENCES  },
-  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_CACHE_MISSES      },
+  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_TASK_CLOCK     },
+  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CONTEXT_SWITCHES},
+  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_CPU_MIGRATIONS },
+  { .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_PAGE_FAULTS    },
+
+  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CPU_CYCLES     },
+  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_INSTRUCTIONS   },
+  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CACHE_REFERENCES},
+  { .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_CACHE_MISSES   },
+
 };
 
 static int                     system_wide                     =  0;
@@ -83,6 +84,7 @@ static __u64                  event_scaled[MAX_COUNTERS];
 
 static __u64                   runtime_nsecs;
 static __u64                   walltime_nsecs;
+static __u64                   runtime_cycles;
 
 static void create_perf_stat_counter(int counter)
 {
@@ -119,10 +121,10 @@ static inline int nsec_counter(int counter)
        if (attrs[counter].type != PERF_TYPE_SOFTWARE)
                return 0;
 
-       if (attrs[counter].config == PERF_COUNT_CPU_CLOCK)
+       if (attrs[counter].config == PERF_COUNT_SW_CPU_CLOCK)
                return 1;
 
-       if (attrs[counter].config == PERF_COUNT_TASK_CLOCK)
+       if (attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK)
                return 1;
 
        return 0;
@@ -175,8 +177,11 @@ static void read_counter(int counter)
         * Save the full runtime - to allow normalization during printout:
         */
        if (attrs[counter].type == PERF_TYPE_SOFTWARE &&
-               attrs[counter].config == PERF_COUNT_TASK_CLOCK)
+               attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK)
                runtime_nsecs = count[0];
+       if (attrs[counter].type == PERF_TYPE_HARDWARE &&
+               attrs[counter].config == PERF_COUNT_HW_CPU_CYCLES)
+               runtime_cycles = count[0];
 }
 
 /*
@@ -202,7 +207,7 @@ static void print_counter(int counter)
                fprintf(stderr, " %14.6f  %-20s",
                        msecs, event_name(counter));
                if (attrs[counter].type == PERF_TYPE_SOFTWARE &&
-                       attrs[counter].config == PERF_COUNT_TASK_CLOCK) {
+                       attrs[counter].config == PERF_COUNT_SW_TASK_CLOCK) {
 
                        if (walltime_nsecs)
                                fprintf(stderr, " # %11.3f CPU utilization factor",
@@ -214,6 +219,13 @@ static void print_counter(int counter)
                if (runtime_nsecs)
                        fprintf(stderr, " # %11.3f M/sec",
                                (double)count[0]/runtime_nsecs*1000.0);
+               if (runtime_cycles &&
+                       attrs[counter].type == PERF_TYPE_HARDWARE &&
+                               attrs[counter].config == PERF_COUNT_HW_INSTRUCTIONS) {
+
+                       fprintf(stderr, " # %1.3f per cycle",
+                               (double)count[0] / (double)runtime_cycles);
+               }
        }
        if (scaled)
                fprintf(stderr, "  (scaled from %.2f%%)",
@@ -285,8 +297,20 @@ static int do_perf_stat(int argc, const char **argv)
        return 0;
 }
 
+static volatile int signr = -1;
+
 static void skip_signal(int signo)
 {
+       signr = signo;
+}
+
+static void sig_atexit(void)
+{
+       if (signr == -1)
+               return;
+
+       signal(signr, SIG_DFL);
+       kill(getpid(), signr);
 }
 
 static const char * const stat_usage[] = {
@@ -334,6 +358,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
         * What we want is for Ctrl-C to work in the exec()-ed
         * task, but being ignored by perf stat itself:
         */
+       atexit(sig_atexit);
        signal(SIGINT,  skip_signal);
        signal(SIGALRM, skip_signal);
        signal(SIGABRT, skip_signal);