[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1443622258-17158-6-git-send-email-jolsa@kernel.org>
Date: Wed, 30 Sep 2015 16:10:18 +0200
From: Jiri Olsa <jolsa@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: lkml <linux-kernel@...r.kernel.org>,
David Ahern <dsahern@...il.com>,
Ingo Molnar <mingo@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
"Liang, Kan" <kan.liang@...el.com>
Subject: [PATCH 05/45] perf tools: Add cpu_map event synthesize function
Introduce perf_event__synthesize_cpu_map function to
sythesize struct cpu_map.
Link: http://lkml.kernel.org/n/tip-miidn8vqsx3udu4ct8103v5f@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
tools/perf/tests/Build | 1 +
tools/perf/tests/builtin-test.c | 4 ++++
tools/perf/tests/cpumap.c | 29 +++++++++++++++++++++++++++++
tools/perf/tests/tests.h | 1 +
tools/perf/util/event.c | 28 ++++++++++++++++++++++++++++
tools/perf/util/event.h | 5 +++++
6 files changed, 68 insertions(+)
create mode 100644 tools/perf/tests/cpumap.c
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index c6f198ae65fb..1a8d23367b8a 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -34,6 +34,7 @@ perf-y += kmod-path.o
perf-y += thread-map.o
perf-y += llvm.o
perf-y += topology.o
+perf-y += cpumap.o
perf-$(CONFIG_X86) += perf-time-to-tsc.o
ifdef CONFIG_AUXTRACE
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 7cf131a3f75e..3068ec0c7ecf 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -196,6 +196,10 @@ static struct test {
.func = test__thread_map_synthesize,
},
{
+ .desc = "Test cpu map synthesize",
+ .func = test__cpu_map_synthesize,
+ },
+ {
.func = NULL,
},
};
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
new file mode 100644
index 000000000000..475c040f8a8d
--- /dev/null
+++ b/tools/perf/tests/cpumap.c
@@ -0,0 +1,29 @@
+#include "tests.h"
+#include "cpumap.h"
+
+static int process_event(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_sample *sample __maybe_unused,
+ struct machine *machine __maybe_unused)
+{
+ struct cpu_map_event *map = &event->cpu_map;
+
+ TEST_ASSERT_VAL("wrong nr", map->nr == 3);
+ TEST_ASSERT_VAL("wrong cpu", map->cpu[0] == 1);
+ TEST_ASSERT_VAL("wrong cpu", map->cpu[1] == 2);
+ TEST_ASSERT_VAL("wrong cpu", map->cpu[2] == 4);
+ return 0;
+}
+
+int test__cpu_map_synthesize(void)
+{
+ struct cpu_map *cpus;
+
+ cpus = cpu_map__new("1,2,4");
+
+
+ TEST_ASSERT_VAL("failed to synthesize map",
+ !perf_event__synthesize_cpu_map(NULL, cpus, process_event, NULL));
+
+ return 0;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 1c9cb793ae72..c8e4e74830c4 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -66,6 +66,7 @@ int test__llvm(void);
int test__insn_x86(void);
int test_session_topology(void);
int test__thread_map_synthesize(void);
+int test__cpu_map_synthesize(void);
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 091c5de2a523..d327f0922ae4 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -737,6 +737,34 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
return err;
}
+int perf_event__synthesize_cpu_map(struct perf_tool *tool,
+ struct cpu_map *cpus,
+ perf_event__handler_t process,
+ struct machine *machine)
+{
+ union perf_event *event;
+ int i, err, size;
+
+ size = sizeof(event->cpu_map);
+ size += cpus->nr * sizeof(event->cpu_map.cpu[0]);
+
+ event = zalloc(size);
+ if (!event)
+ return -ENOMEM;
+
+ event->header.type = PERF_RECORD_CPU_MAP;
+ event->header.size = size;
+ event->cpu_map.nr = cpus->nr;
+
+ for (i = 0; i < cpus->nr; i++)
+ event->cpu_map.cpu[i] = cpus->map[i];
+
+ err = process(tool, event, NULL, machine);
+
+ free(event);
+ return err;
+}
+
size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp)
{
const char *s;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 46162b9c6720..61f8228a90b5 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -405,6 +405,7 @@ void perf_event__print_totals(void);
struct perf_tool;
struct thread_map;
+struct cpu_map;
typedef int (*perf_event__handler_t)(struct perf_tool *tool,
union perf_event *event,
@@ -420,6 +421,10 @@ int perf_event__synthesize_thread_map2(struct perf_tool *tool,
struct thread_map *threads,
perf_event__handler_t process,
struct machine *machine);
+int perf_event__synthesize_cpu_map(struct perf_tool *tool,
+ struct cpu_map *cpus,
+ perf_event__handler_t process,
+ struct machine *machine);
int perf_event__synthesize_threads(struct perf_tool *tool,
perf_event__handler_t process,
struct machine *machine, bool mmap_data,
--
2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists