Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1248634

[PATCH 20/57] perf tools: Add attr_update event unit type

From Jiri Olsa <jolsa@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 20/57] perf tools: Add attr_update event unit type
Date 2015-10-16 13:00 +0200
Message-ID <qkaTU-3YR-37@gated-at.bofh.it> (permalink)
References <qkaKe-3Nh-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Adding unit type attr update event, that stores/transfer
events unit name. The unit name is part of the perf stat
output data.

Link: http://lkml.kernel.org/n/tip-5s6ape0vz2sfxgzu16eu8y7r@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/Build          |  1 +
 tools/perf/tests/attr_update.c  | 42 +++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c |  4 ++++
 tools/perf/tests/tests.h        |  1 +
 tools/perf/util/event.h         |  5 +++++
 tools/perf/util/header.c        | 44 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h        |  3 +++
 7 files changed, 100 insertions(+)
 create mode 100644 tools/perf/tests/attr_update.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index ea4ef8fdd463..039bba2918b0 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -35,6 +35,7 @@ perf-y += llvm.o
 perf-y += topology.o
 perf-y += cpumap.o
 perf-y += stat.o
+perf-y += attr_update.o
 
 ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
 perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
diff --git a/tools/perf/tests/attr_update.c b/tools/perf/tests/attr_update.c
new file mode 100644
index 000000000000..a564c3827da4
--- /dev/null
+++ b/tools/perf/tests/attr_update.c
@@ -0,0 +1,42 @@
+#include <linux/compiler.h>
+#include "evlist.h"
+#include "evsel.h"
+#include "machine.h"
+#include "tests.h"
+#include "debug.h"
+
+static int process_event_unit(struct perf_tool *tool __maybe_unused,
+			      union perf_event *event,
+			      struct perf_sample *sample __maybe_unused,
+			      struct machine *machine __maybe_unused)
+{
+	struct attr_update_event *ev = (struct attr_update_event*) event;
+
+	TEST_ASSERT_VAL("wrong id", ev->id == 123);
+	TEST_ASSERT_VAL("wrong id", ev->type == PERF_ATTR_UPDATE__UNIT);
+	TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
+	return 0;
+}
+
+int test__attr_update(void)
+{
+	struct perf_evlist *evlist;
+	struct perf_evsel *evsel;
+
+	evlist = perf_evlist__new_default();
+	TEST_ASSERT_VAL("failed to get evlist", evlist);
+
+	evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("failed to allos ids",
+			!perf_evsel__alloc_id(evsel, 1, 1));
+
+	perf_evlist__id_add(evlist, evsel, 0, 0, 123);
+
+	evsel->unit = strdup("KRAVA");
+
+	TEST_ASSERT_VAL("failed to synthesize attr update unit",
+			!perf_event__synthesize_attr_update_unit(NULL, evsel, process_event_unit));
+
+	return 0;
+}
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index e18f5b818a02..11713dcf1294 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -186,6 +186,10 @@ static struct test generic_tests[] = {
 		.func = test__synthesize_stat_round,
 	},
 	{
+		.desc = "Test attr update synthesize",
+		.func = test__attr_update,
+	},
+	{
 		.func = NULL,
 	},
 };
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 261716924ad9..e4e3cebcb7f3 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -72,6 +72,7 @@ int test__cpu_map_synthesize(void);
 int test__synthesize_stat_config(void);
 int test__synthesize_stat(void);
 int test__synthesize_stat_round(void);
+int test__attr_update(void);
 
 
 #if defined(__arm__) || defined(__aarch64__)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1d46e12acd75..1bccac1b22ec 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -308,6 +308,11 @@ struct attr_event {
 	u64 id[];
 };
 
+
+enum {
+	PERF_ATTR_UPDATE__UNIT  = 0,
+};
+
 struct attr_update_event {
 	struct perf_event_header header;
 	u64 type;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 437856eec7c4..50c6b28486e0 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2686,6 +2686,43 @@ int perf_event__synthesize_attr(struct perf_tool *tool,
 	return err;
 }
 
+static struct attr_update_event*
+attr_update_event__alloc(size_t size, u64 type, u64 id)
+{
+	struct attr_update_event *ev;
+
+	size += sizeof(*ev);
+	size  = PERF_ALIGN(size, sizeof(u64));
+
+	ev = zalloc(size);
+	if (ev) {
+		ev->header.type = PERF_RECORD_HEADER_ATTR_UPDATE;
+		ev->header.size = (u16)size;
+		ev->type = type;
+		ev->id = id;
+	}
+	return ev;
+}
+
+int
+perf_event__synthesize_attr_update_unit(struct perf_tool *tool,
+					struct perf_evsel *evsel,
+					perf_event__handler_t process)
+{
+	struct attr_update_event *ev;
+	size_t size = strlen(evsel->unit);
+	int err;
+
+	ev = attr_update_event__alloc(size + 1, PERF_ATTR_UPDATE__UNIT, evsel->id[0]);
+	if (ev == NULL)
+		return -ENOMEM;
+
+	strncpy(ev->data, evsel->unit, size);
+	err = process(tool, (union perf_event*) ev, NULL, NULL);
+	free(ev);
+	return err;
+}
+
 int perf_event__synthesize_attrs(struct perf_tool *tool,
 				   struct perf_session *session,
 				   perf_event__handler_t process)
@@ -2762,6 +2799,13 @@ int perf_event__process_attr_update(struct perf_tool *tool __maybe_unused,
 	if (evsel == NULL)
 		return -EINVAL;
 
+	switch (ev->type) {
+	case PERF_ATTR_UPDATE__UNIT:
+		evsel->unit = strdup(ev->data);
+	default:
+		break;
+	}
+
 	return 0;
 }
 
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 069298367348..0f00ff55f451 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -105,6 +105,9 @@ int perf_event__synthesize_attr(struct perf_tool *tool,
 int perf_event__synthesize_attrs(struct perf_tool *tool,
 				 struct perf_session *session,
 				 perf_event__handler_t process);
+int perf_event__synthesize_attr_update_unit(struct perf_tool *tool,
+					    struct perf_evsel *evsel,
+					    perf_event__handler_t process);
 int perf_event__process_attr(struct perf_tool *tool, union perf_event *event,
 			     struct perf_evlist **pevlist);
 int perf_event__process_attr_update(struct perf_tool *tool __maybe_unused,
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHv4 00/57] perf stat: Add scripting support Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 50/57] perf script: Check output fields only for samples Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 27/57] perf tools: Move id_offset out of struct perf_evsel union Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 41/57] perf stat report: Cache aggregated map entries in extra cpumap Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 35/57] perf stat record: Write stat events on record Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 06/57] perf tools: Add cpu_map event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 38/57] perf stat record: Synthesize attr update events Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 25/57] perf report: Display newly added events in raw dump Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 43/57] perf stat report: Process cpu/threads maps Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 08/57] perf tools: Add cpu_map__new_event function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 30/57] perf stat record: Add record command Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 39/57] perf tools: Make cpu_map__build_map global Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 49/57] perf stat report: Allow to override aggr_mode Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 03/57] perf tools: Add thread_map__new_event function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 40/57] perf tools: Add data arg to cpu_map__build_map callback Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 42/57] perf stat report: Add report command Jiri Olsa <jolsa@kernel.org> - 2015-10-16 12:50 +0200
  [PATCH 15/57] perf tools: Add stat event read function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 11/57] perf tools: Add stat config event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 33/57] perf stat record: Store events IDs in perf data file Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 21/57] perf tools: Add attr_update event scale type Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 18/57] perf tools: Add stat events fprintf functions Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 09/57] perf tools: Add perf_event__fprintf_cpu_map function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 17/57] perf tools: Add stat round event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 07/57] perf tools: Add cpu_map__empty_new function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 26/57] perf tools: Introduce stat feature Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 36/57] perf stat record: Write stat round events on record Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 10/57] perf tools: Add stat config event Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 04/57] perf tools: Add perf_event__fprintf_thread_map function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 20/57] perf tools: Add attr_update event unit type Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 05/57] perf tools: Add cpu_map event Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 13/57] perf tools: Add stat event Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 24/57] perf tools: Add perf_event__fprintf_attr_update function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 29/57] perf stat: Add AGGR_UNSET mode Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 34/57] perf stat record: Add pipe support for record command Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 31/57] perf stat record: Initialize record features Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:00 +0200
  [PATCH 02/57] perf tools: Add thread_map event sythesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-16 13:10 +0200

csiph-web