perf record: Create events initially disabled and enable after init
[pandora-kernel.git] / tools / perf / builtin-record.c
index 80dc5b7..f4c3fbe 100644 (file)
@@ -30,8 +30,6 @@
 #include <sched.h>
 #include <sys/mman.h>
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
-
 enum write_mode_t {
        WRITE_FORCE,
        WRITE_APPEND
@@ -47,7 +45,7 @@ static int                    freq                            =   1000;
 static int                     output;
 static int                     pipe_output                     =      0;
 static const char              *output_name                    = NULL;
-static int                     group                           =      0;
+static bool                    group                           =  false;
 static int                     realtime_prio                   =      0;
 static bool                    nodelay                         =  false;
 static bool                    raw_samples                     =  false;
@@ -163,6 +161,7 @@ static void config_attr(struct perf_evsel *evsel, struct perf_evlist *evlist)
        struct perf_event_attr *attr = &evsel->attr;
        int track = !evsel->idx; /* only the first counter needs these */
 
+       attr->disabled          = 1;
        attr->inherit           = !no_inherit;
        attr->read_format       = PERF_FORMAT_TOTAL_TIME_ENABLED |
                                  PERF_FORMAT_TOTAL_TIME_RUNNING |
@@ -438,7 +437,6 @@ static void mmap_read_all(void)
 
 static int __cmd_record(int argc, const char **argv)
 {
-       int i;
        struct stat st;
        int flags;
        int err;
@@ -674,6 +672,8 @@ static int __cmd_record(int argc, const char **argv)
                }
        }
 
+       perf_evlist__enable(evsel_list);
+
        /*
         * Let the child rip
         */
@@ -682,7 +682,6 @@ static int __cmd_record(int argc, const char **argv)
 
        for (;;) {
                int hits = samples;
-               int thread;
 
                mmap_read_all();
 
@@ -693,19 +692,8 @@ static int __cmd_record(int argc, const char **argv)
                        waking++;
                }
 
-               if (done) {
-                       for (i = 0; i < evsel_list->cpus->nr; i++) {
-                               struct perf_evsel *pos;
-
-                               list_for_each_entry(pos, &evsel_list->entries, node) {
-                                       for (thread = 0;
-                                               thread < evsel_list->threads->nr;
-                                               thread++)
-                                               ioctl(FD(pos, i, thread),
-                                                       PERF_EVENT_IOC_DISABLE);
-                               }
-                       }
-               }
+               if (done)
+                       perf_evlist__disable(evsel_list);
        }
 
        if (quiet || signr == SIGUSR1)
@@ -768,6 +756,8 @@ const struct option record_options[] = {
                    "child tasks do not inherit counters"),
        OPT_UINTEGER('F', "freq", &user_freq, "profile at this frequency"),
        OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"),
+       OPT_BOOLEAN(0, "group", &group,
+                   "put the counters into a counter group"),
        OPT_BOOLEAN('g', "call-graph", &call_graph,
                    "do call-graph (stack chain/backtrace) recording"),
        OPT_INCR('v', "verbose", &verbose,