perf timechart: Get number of CPUs from perf header
authorStanislav Fomichev <stfomichev@yandex-team.ru>
Mon, 2 Dec 2013 14:37:35 +0000 (18:37 +0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 16 Dec 2013 19:34:27 +0000 (16:34 -0300)
Print all CPUs, even if there were no events (use perf header to get
number of CPUs).

This is required to support topology in the next patch.

Signed-off-by: Stanislav Fomichev <stfomichev@yandex-team.ru>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ramkumar Ramachandra <artagnon@gmail.com>
Link: http://lkml.kernel.org/r/1385995056-20158-4-git-send-email-stfomichev@yandex-team.ru
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-timechart.c

index 99fe363f1de81e7805ccee6f2c0ca99586d8063b..db9c4c1725877f5828cb5809bc890e8662351a68 100644 (file)
@@ -531,12 +531,10 @@ static int process_sample_event(struct perf_tool *tool,
                        tchart->last_time = sample->time;
        }
 
-       if (sample->cpu > tchart->numcpus)
-               tchart->numcpus = sample->cpu;
-
        if (evsel->handler != NULL) {
                tracepoint_handler f = evsel->handler;
-               return f(tchart, evsel, sample, cat_backtrace(event, sample, machine));
+               return f(tchart, evsel, sample,
+                        cat_backtrace(event, sample, machine));
        }
 
        return 0;
@@ -1038,8 +1036,6 @@ static void write_svg_file(struct timechart *tchart, const char *filename)
        int count;
        int thresh = TIME_THRESH;
 
-       tchart->numcpus++;
-
        if (tchart->power_only)
                tchart->proc_num = 0;
 
@@ -1069,6 +1065,25 @@ static void write_svg_file(struct timechart *tchart, const char *filename)
        svg_close();
 }
 
+static int process_header(struct perf_file_section *section __maybe_unused,
+                         struct perf_header *ph,
+                         int feat,
+                         int fd __maybe_unused,
+                         void *data)
+{
+       struct timechart *tchart = data;
+
+       switch (feat) {
+       case HEADER_NRCPUS:
+               tchart->numcpus = ph->env.nr_cpus_avail;
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
 static int __cmd_timechart(struct timechart *tchart, const char *output_name)
 {
        const struct perf_evsel_str_handler power_tracepoints[] = {
@@ -1094,6 +1109,11 @@ static int __cmd_timechart(struct timechart *tchart, const char *output_name)
        if (session == NULL)
                return -ENOMEM;
 
+       (void)perf_header__process_sections(&session->header,
+                                           perf_data_file__fd(session->file),
+                                           tchart,
+                                           process_header);
+
        if (!perf_session__has_traces(session, "timechart record"))
                goto out_delete;