[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1444161335-26734-7-git-send-email-jolsa@kernel.org>
Date: Tue, 6 Oct 2015 21:54:45 +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 06/56] perf tools: Add cpu_map event synthesize function
Introduce perf_event__synthesize_cpu_map function to
synthesize 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 50de2253cff6..1c0296fc95ea 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -33,6 +33,7 @@ perf-y += kmod-path.o
perf-y += thread-map.o
perf-y += llvm.o
perf-y += topology.o
+perf-y += cpumap.o
ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 9bbe1c39740e..3b8b518d96f9 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -171,6 +171,10 @@ static struct test generic_tests[] = {
.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 2e280a5cd579..c7f3c3211bcf 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -68,6 +68,7 @@ int test__thread_map(void);
int test__llvm(void);
int test_session_topology(void);
int test__thread_map_synthesize(void);
+int test__cpu_map_synthesize(void);
#if defined(__arm__) || defined(__aarch64__)
#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index c05f4b036069..eac52f12c5c4 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 84104cfaab87..e58a36b8ecbc 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