]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - tools/perf/builtin-stat.c
perf evlist: Fix grouping of multiple events
[karo-tx-linux.git] / tools / perf / builtin-stat.c
index 076eda53cfba9d890affbe37f0a0dfd7ff889ac1..7d98676808d8722a39623de8983642f987cea7cc 100644 (file)
@@ -278,9 +278,14 @@ struct stats                       runtime_itlb_cache_stats[MAX_NR_CPUS];
 struct stats                   runtime_dtlb_cache_stats[MAX_NR_CPUS];
 struct stats                   walltime_nsecs_stats;
 
-static int create_perf_stat_counter(struct perf_evsel *evsel)
+static int create_perf_stat_counter(struct perf_evsel *evsel,
+                                   struct perf_evsel *first)
 {
        struct perf_event_attr *attr = &evsel->attr;
+       struct xyarray *group_fd = NULL;
+
+       if (group && evsel != first)
+               group_fd = first->fd;
 
        if (scale)
                attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -289,14 +294,15 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
        attr->inherit = !no_inherit;
 
        if (system_wide)
-               return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, group);
-
+               return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
+                                               group, group_fd);
        if (target_pid == -1 && target_tid == -1) {
                attr->disabled = 1;
                attr->enable_on_exec = 1;
        }
 
-       return perf_evsel__open_per_thread(evsel, evsel_list->threads, group);
+       return perf_evsel__open_per_thread(evsel, evsel_list->threads,
+                                          group, group_fd);
 }
 
 /*
@@ -396,7 +402,7 @@ static int read_counter(struct perf_evsel *counter)
 static int run_perf_stat(int argc __used, const char **argv)
 {
        unsigned long long t0, t1;
-       struct perf_evsel *counter;
+       struct perf_evsel *counter, *first;
        int status = 0;
        int child_ready_pipe[2], go_pipe[2];
        const bool forks = (argc > 0);
@@ -453,8 +459,10 @@ static int run_perf_stat(int argc __used, const char **argv)
                close(child_ready_pipe[0]);
        }
 
+       first = list_entry(evsel_list->entries.next, struct perf_evsel, node);
+
        list_for_each_entry(counter, &evsel_list->entries, node) {
-               if (create_perf_stat_counter(counter) < 0) {
+               if (create_perf_stat_counter(counter, first) < 0) {
                        if (errno == EINVAL || errno == ENOSYS || errno == ENOENT) {
                                if (verbose)
                                        ui__warning("%s event is not supported by the kernel.\n",
@@ -495,6 +503,8 @@ static int run_perf_stat(int argc __used, const char **argv)
        if (forks) {
                close(go_pipe[1]);
                wait(&status);
+               if (WIFSIGNALED(status))
+                       psignal(WTERMSIG(status), argv[0]);
        } else {
                while(!done) sleep(1);
        }
@@ -1198,16 +1208,18 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
                }
        }
 
-       if (csv_sep)
+       if (csv_sep) {
                csv_output = true;
-       else
+               if (!strcmp(csv_sep, "\\t"))
+                       csv_sep = "\t";
+       } else
                csv_sep = DEFAULT_SEPARATOR;
 
        /*
         * let the spreadsheet do the pretty-printing
         */
        if (csv_output) {
-               /* User explicitely passed -B? */
+               /* User explicitly passed -B? */
                if (big_num_opt == 1) {
                        fprintf(stderr, "-B option not supported with -x\n");
                        usage_with_options(stat_usage, options);