perf stat record: Synthesize event update events
authorJiri Olsa <jolsa@kernel.org>
Thu, 5 Nov 2015 14:40:54 +0000 (15:40 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Dec 2015 19:00:33 +0000 (16:00 -0300)
Synthesize other events stuff not carried within attr event - unit,
scale, name.

Reported-by: Kan Liang <kan.liang@intel.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1446734469-11352-11-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c

index 10f86a6..575e253 100644 (file)
@@ -351,8 +351,19 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf
        workload_exec_errno = info->si_value.sival_int;
 }
 
+static bool has_unit(struct perf_evsel *counter)
+{
+       return counter->unit && *counter->unit;
+}
+
+static bool has_scale(struct perf_evsel *counter)
+{
+       return counter->scale != 1;
+}
+
 static int perf_stat_synthesize_config(bool is_pipe)
 {
+       struct perf_evsel *counter;
        int err;
 
        if (is_pipe) {
@@ -364,6 +375,54 @@ static int perf_stat_synthesize_config(bool is_pipe)
                }
        }
 
+       /*
+        * Synthesize other events stuff not carried within
+        * attr event - unit, scale, name
+        */
+       evlist__for_each(evsel_list, counter) {
+               if (!counter->supported)
+                       continue;
+
+               /*
+                * Synthesize unit and scale only if it's defined.
+                */
+               if (has_unit(counter)) {
+                       err = perf_event__synthesize_event_update_unit(NULL, counter, process_synthesized_event);
+                       if (err < 0) {
+                               pr_err("Couldn't synthesize evsel unit.\n");
+                               return err;
+                       }
+               }
+
+               if (has_scale(counter)) {
+                       err = perf_event__synthesize_event_update_scale(NULL, counter, process_synthesized_event);
+                       if (err < 0) {
+                               pr_err("Couldn't synthesize evsel scale.\n");
+                               return err;
+                       }
+               }
+
+               if (counter->own_cpus) {
+                       err = perf_event__synthesize_event_update_cpus(NULL, counter, process_synthesized_event);
+                       if (err < 0) {
+                               pr_err("Couldn't synthesize evsel scale.\n");
+                               return err;
+                       }
+               }
+
+               /*
+                * Name is needed only for pipe output,
+                * perf.data carries event names.
+                */
+               if (is_pipe) {
+                       err = perf_event__synthesize_event_update_name(NULL, counter, process_synthesized_event);
+                       if (err < 0) {
+                               pr_err("Couldn't synthesize evsel name.\n");
+                               return err;
+                       }
+               }
+       }
+
        err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads,
                                                process_synthesized_event,
                                                NULL);