perf timechart: Refactor svg_build_topology_map()
authorKyle Meyer <meyerk@hpe.com>
Tue, 27 Aug 2019 21:43:46 +0000 (16:43 -0500)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 29 Aug 2019 20:38:31 +0000 (17:38 -0300)
Exchange the parameters of svg_build_topology_map() with 'struct
perf_env *env' and adjust the function accordingly.

This patch should not change any behavior, it is merely refactoring for
the following patch.

Committer notes:

No need to include env.h from svghelper.h, all it needs is a forward
declaration for 'struct perf_env', so move the include directive to
svghelper.c, where it is really needed.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-2-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-timechart.c
tools/perf/util/svghelper.c
tools/perf/util/svghelper.h

index 7d6a6ec..1ff81a7 100644 (file)
@@ -1518,10 +1518,7 @@ static int process_header(struct perf_file_section *section __maybe_unused,
                if (!tchart->topology)
                        break;
 
-               if (svg_build_topology_map(ph->env.sibling_cores,
-                                          ph->env.nr_sibling_cores,
-                                          ph->env.sibling_threads,
-                                          ph->env.nr_sibling_threads))
+               if (svg_build_topology_map(&ph->env))
                        fprintf(stderr, "problem building topology\n");
                break;
 
index bbdd871..2e99715 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/zalloc.h>
 #include <perf/cpumap.h>
 
+#include "env.h"
 #include "perf.h"
 #include "svghelper.h"
 #include "cpumap.h"
@@ -752,23 +753,26 @@ static int str_to_bitmap(char *s, cpumask_t *b)
        return ret;
 }
 
-int svg_build_topology_map(char *sib_core, int sib_core_nr,
-                          char *sib_thr, int sib_thr_nr)
+int svg_build_topology_map(struct perf_env *env)
 {
        int i;
        struct topology t;
+       char *sib_core, *sib_thr;
 
-       t.sib_core_nr = sib_core_nr;
-       t.sib_thr_nr = sib_thr_nr;
-       t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
-       t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
+       t.sib_core_nr = env->nr_sibling_cores;
+       t.sib_thr_nr = env->nr_sibling_threads;
+       t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
+       t.sib_thr = calloc(env->nr_sibling_threads, sizeof(cpumask_t));
+
+       sib_core = env->sibling_cores;
+       sib_thr = env->sibling_threads;
 
        if (!t.sib_core || !t.sib_thr) {
                fprintf(stderr, "topology: no memory\n");
                goto exit;
        }
 
-       for (i = 0; i < sib_core_nr; i++) {
+       for (i = 0; i < env->nr_sibling_cores; i++) {
                if (str_to_bitmap(sib_core, &t.sib_core[i])) {
                        fprintf(stderr, "topology: can't parse siblings map\n");
                        goto exit;
@@ -777,7 +781,7 @@ int svg_build_topology_map(char *sib_core, int sib_core_nr,
                sib_core += strlen(sib_core) + 1;
        }
 
-       for (i = 0; i < sib_thr_nr; i++) {
+       for (i = 0; i < env->nr_sibling_threads; i++) {
                if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
                        fprintf(stderr, "topology: can't parse siblings map\n");
                        goto exit;
index e55338d..81823e8 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <linux/types.h>
 
+struct perf_env;
+
 void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
 void svg_ubox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
 void svg_lbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
@@ -28,7 +30,7 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc
 void svg_interrupt(u64 start, int row, const char *backtrace);
 void svg_text(int Yslot, u64 start, const char *text);
 void svg_close(void);
-int svg_build_topology_map(char *sib_core, int sib_core_nr, char *sib_thr, int sib_thr_nr);
+int svg_build_topology_map(struct perf_env *env);
 
 extern int svg_page_width;
 extern u64 svg_highlight;