mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	"Liang, Kan" <kan.liang@intel.com>
Subject: [PATCH 08/45] perf tools: Add stat config event synthesize function
Date: Wed, 30 Sep 2015 16:10:21 +0200	[thread overview]
Message-ID: <1443622258-17158-9-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1443622258-17158-1-git-send-email-jolsa@kernel.org>

Introduce perf_event__synthesize_stat_config function to
sythesize 'struct perf_stat_config'.

Storing stat config in form of tag-value pairs in a believe
it'll sort out future version issues.

Link: http://lkml.kernel.org/n/tip-zof1adf5flwp38xdzxzn4p2z@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/Build          |  1 +
 tools/perf/tests/builtin-test.c |  4 ++++
 tools/perf/tests/stat.c         | 53 +++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |  1 +
 tools/perf/util/event.c         | 40 +++++++++++++++++++++++++++++++
 tools/perf/util/event.h         |  5 ++++
 6 files changed, 104 insertions(+)
 create mode 100644 tools/perf/tests/stat.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 1a8d23367b8a..b7bdad4a00cd 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -35,6 +35,7 @@ perf-y += thread-map.o
 perf-y += llvm.o
 perf-y += topology.o
 perf-y += cpumap.o
+perf-y += stat.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 3068ec0c7ecf..23fccd474302 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -200,6 +200,10 @@ static struct test {
 		.func = test__cpu_map_synthesize,
 	},
 	{
+		.desc = "Test stat config synthesize",
+		.func = test__synthesize_stat_config,
+	},
+	{
 		.func = NULL,
 	},
 };
diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c
new file mode 100644
index 000000000000..5e6a2441998c
--- /dev/null
+++ b/tools/perf/tests/stat.c
@@ -0,0 +1,53 @@
+#include <linux/compiler.h>
+#include "event.h"
+#include "tests.h"
+#include "stat.h"
+#include "debug.h"
+
+static bool has_term(struct stat_config_event *config,
+		     u64 tag, u64 val)
+{
+	unsigned i;
+
+	for (i = 0; i < config->nr; i++) {
+		if ((config->data[i].tag == tag) &&
+		    (config->data[i].val == val))
+			return true;
+	}
+
+	return false;
+}
+
+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 stat_config_event *config = &event->stat_config;
+
+#define HAS(term, val) \
+	has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
+
+	TEST_ASSERT_VAL("wrong nr",        config->nr == PERF_STAT_CONFIG_TERM__MAX);
+	TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE));
+	TEST_ASSERT_VAL("wrong scale",     HAS(SCALE, 1));
+	TEST_ASSERT_VAL("wrong interval",  HAS(INTERVAL, 1));
+
+#undef HAS
+
+	return 0;
+}
+
+int test__synthesize_stat_config(void)
+{
+	struct perf_stat_config stat_config = {
+		.aggr_mode	= AGGR_CORE,
+		.scale		= 1,
+		.interval	= 1,
+	};
+
+	TEST_ASSERT_VAL("failed to synthesize stat_config",
+		!perf_event__synthesize_stat_config(NULL, &stat_config, process_event, NULL));
+
+	return 0;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index c8e4e74830c4..3dc65f5158ed 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -67,6 +67,7 @@ int test__insn_x86(void);
 int test_session_topology(void);
 int test__thread_map_synthesize(void);
 int test__cpu_map_synthesize(void);
+int test__synthesize_stat_config(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 8840d82ca24f..6708cc207c38 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -10,6 +10,8 @@
 #include "thread.h"
 #include "thread_map.h"
 #include "symbol/kallsyms.h"
+#include "asm/bug.h"
+#include "stat.h"
 
 static const char *perf_event__names[] = {
 	[0]					= "TOTAL",
@@ -766,6 +768,44 @@ int perf_event__synthesize_cpu_map(struct perf_tool *tool,
 	return err;
 }
 
+int perf_event__synthesize_stat_config(struct perf_tool *tool,
+				       struct perf_stat_config *config,
+				       perf_event__handler_t process,
+				       struct machine *machine)
+{
+	struct stat_config_event *event;
+	int size, i = 0, err;
+
+	size  = sizeof(*event);
+	size += (PERF_STAT_CONFIG_TERM__MAX * sizeof(event->data[0]));
+
+	event = zalloc(size);
+	if (!event)
+		return -ENOMEM;
+
+	event->header.type = PERF_RECORD_STAT_CONFIG;
+	event->header.size = size;
+	event->nr          = PERF_STAT_CONFIG_TERM__MAX;
+
+#define ADD(__term, __val)					\
+	event->data[i].tag = PERF_STAT_CONFIG_TERM__##__term;	\
+	event->data[i].val = __val;				\
+	i++;
+
+	ADD(AGGR_MODE,	config->aggr_mode)
+	ADD(INTERVAL,	config->interval)
+	ADD(SCALE,	config->scale)
+
+	WARN_ONCE(i != PERF_STAT_CONFIG_TERM__MAX,
+		  "stat config terms unbalanced\n");
+#undef ADD
+
+	err = process(tool, (union perf_event *) 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 179eba07889e..da6155dac7d1 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -426,6 +426,7 @@ void perf_event__print_totals(void);
 struct perf_tool;
 struct thread_map;
 struct cpu_map;
+struct perf_stat_config;
 
 typedef int (*perf_event__handler_t)(struct perf_tool *tool,
 				     union perf_event *event,
@@ -452,6 +453,10 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
 				       perf_event__handler_t process,
 				       struct machine *machine);
+int perf_event__synthesize_stat_config(struct perf_tool *tool,
+				       struct perf_stat_config *config,
+				       perf_event__handler_t process,
+				       struct machine *machine);
 
 int perf_event__synthesize_modules(struct perf_tool *tool,
 				   perf_event__handler_t process,
-- 
2.4.3


  parent reply	other threads:[~2015-09-30 14:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 14:10 [PATCHv2 00/45] perf stat: Add scripting support Jiri Olsa
2015-09-30 14:10 ` [PATCH 01/45] perf tools: Add thread_map event Jiri Olsa
2015-09-30 14:10 ` [PATCH 02/45] perf tools: Add thread_map event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 03/45] perf tools: Add thread_map__new_event function Jiri Olsa
2015-09-30 14:10 ` [PATCH 04/45] perf tools: Add cpu_map event Jiri Olsa
2015-09-30 14:10 ` [PATCH 05/45] perf tools: Add cpu_map event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 06/45] perf tools: Add cpu_map__new_event function Jiri Olsa
2015-09-30 14:10 ` [PATCH 07/45] perf tools: Add stat config event Jiri Olsa
2015-09-30 14:10 ` Jiri Olsa [this message]
2015-09-30 14:10 ` [PATCH 09/45] perf tools: Add stat config event read function Jiri Olsa
2015-09-30 14:10 ` [PATCH 10/45] perf tools: Add stat event Jiri Olsa
2015-09-30 14:10 ` [PATCH 11/45] perf tools: Add stat event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 12/45] perf tools: Add stat event read function Jiri Olsa
2015-09-30 14:10 ` [PATCH 13/45] perf tools: Add stat round event Jiri Olsa
2015-09-30 14:10 ` [PATCH 14/45] perf tools: Add stat round event synthesize function Jiri Olsa
2015-09-30 14:10 ` [PATCH 15/45] perf tools: Introduce stat feature Jiri Olsa
2015-09-30 14:10 ` [PATCH 16/45] perf tools: Move id_offset out of struct perf_evsel union Jiri Olsa
2015-09-30 14:10 ` [PATCH 17/45] perf stat: Rename perf_stat struct into perf_stat_evsel Jiri Olsa
2015-09-30 14:10 ` [PATCH 18/45] perf stat: Add AGGR_UNSET mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 19/45] perf stat record: Add record command Jiri Olsa
2015-09-30 14:10 ` [PATCH 20/45] perf stat record: Initialize record features Jiri Olsa
2015-09-30 14:10 ` [PATCH 21/45] perf stat record: Synthesize stat record data Jiri Olsa
2015-09-30 14:10 ` [PATCH 22/45] perf stat record: Store events IDs in perf data file Jiri Olsa
2015-09-30 14:10 ` [PATCH 23/45] perf stat record: Add pipe support for record command Jiri Olsa
2015-09-30 14:10 ` [PATCH 24/45] perf stat record: Write stat events on record Jiri Olsa
2015-09-30 14:10 ` [PATCH 25/45] perf stat record: Write stat round " Jiri Olsa
2015-09-30 14:10 ` [PATCH 26/45] perf stat record: Do not allow record with multiple runs mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 27/45] perf tools: Add cpu_map__empty_new interface Jiri Olsa
2015-09-30 14:10 ` [PATCH 28/45] perf tools: Make cpu_map__build_map global Jiri Olsa
2015-09-30 14:10 ` [PATCH 29/45] perf tools: Add data arg to cpu_map__build_map callback Jiri Olsa
2015-09-30 14:10 ` [PATCH 30/45] perf stat report: Cache aggregated map entries in extra cpumap Jiri Olsa
2015-09-30 14:10 ` [PATCH 31/45] perf stat report: Add report command Jiri Olsa
2015-09-30 14:10 ` [PATCH 32/45] perf stat report: Process cpu/threads maps Jiri Olsa
2015-09-30 14:10 ` [PATCH 33/45] perf stat report: Process stat config event Jiri Olsa
2015-09-30 14:10 ` [PATCH 34/45] perf stat report: Add support to initialize aggr_map from file Jiri Olsa
2015-09-30 14:10 ` [PATCH 35/45] perf stat report: Process stat and stat round events Jiri Olsa
2015-09-30 14:10 ` [PATCH 36/45] perf stat report: Move csv_sep initialization before report command Jiri Olsa
2015-09-30 14:10 ` [PATCH 37/45] perf stat report: Allow to override aggr_mode Jiri Olsa
2015-09-30 14:10 ` [PATCH 38/45] perf script: Check output fields only for samples Jiri Olsa
2015-09-30 14:10 ` [PATCH 39/45] perf script: Process cpu/threads maps Jiri Olsa
2015-09-30 14:10 ` [PATCH 40/45] perf script: Process stat config event Jiri Olsa
2015-09-30 14:10 ` [PATCH 41/45] perf script: Add process_stat/process_stat_interval scripting interface Jiri Olsa
2015-09-30 14:10 ` [PATCH 42/45] perf script: Add stat default handlers Jiri Olsa
2015-09-30 14:10 ` [PATCH 43/45] perf script: Display stat events by default Jiri Olsa
2015-09-30 14:10 ` [PATCH 44/45] perf script: Add python support for stat events Jiri Olsa
2015-09-30 14:10 ` [PATCH 45/45] perf script: Add stat-cpi.py script Jiri Olsa
2015-09-30 21:09 ` [PATCHv2 00/45] perf stat: Add scripting support Liang, Kan
2015-09-30 21:34   ` Jiri Olsa
2015-09-30 21:36   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443622258-17158-9-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome