mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 34/39] perf inject: Add --strip option to strip out non-synthesized events
Date: Mon, 28 Sep 2015 18:08:19 -0300	[thread overview]
Message-ID: <1443474504-16528-35-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1443474504-16528-1-git-send-email-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

Add a new option --strip which is used with --itrace to strip out
non-synthesized events.  This results in a perf.data file that is
simpler for external tools to parse.  In particular, this can be used to
prepare a perf.data file for consumption by autofdo.

A subsequent patch makes a change to Intel PT also to enable use with
autofdo and gives an example of that use.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1443186956-18718-25-git-send-email-adrian.hunter@intel.com
[ Made it use perf_evlist__remove() + perf_evsel__delete() ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-inject.txt |  3 ++
 tools/perf/builtin-inject.c              | 92 ++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt
index 0c721c3e37e1..0b1cedeef895 100644
--- a/tools/perf/Documentation/perf-inject.txt
+++ b/tools/perf/Documentation/perf-inject.txt
@@ -50,6 +50,9 @@ OPTIONS
 
 include::itrace.txt[]
 
+--strip::
+	Use with --itrace to strip out non-synthesized events.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 9b6119f134b4..0a945d2e8ca5 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -28,6 +28,7 @@ struct perf_inject {
 	bool			build_ids;
 	bool			sched_stat;
 	bool			have_auxtrace;
+	bool			strip;
 	const char		*input_name;
 	struct perf_data_file	output;
 	u64			bytes_written;
@@ -177,6 +178,14 @@ static int perf_event__repipe(struct perf_tool *tool,
 	return perf_event__repipe_synth(tool, event);
 }
 
+static int perf_event__drop(struct perf_tool *tool __maybe_unused,
+			    union perf_event *event __maybe_unused,
+			    struct perf_sample *sample __maybe_unused,
+			    struct machine *machine __maybe_unused)
+{
+	return 0;
+}
+
 static int perf_event__drop_aux(struct perf_tool *tool,
 				union perf_event *event __maybe_unused,
 				struct perf_sample *sample,
@@ -480,6 +489,78 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel,
 	return 0;
 }
 
+static int drop_sample(struct perf_tool *tool __maybe_unused,
+		       union perf_event *event __maybe_unused,
+		       struct perf_sample *sample __maybe_unused,
+		       struct perf_evsel *evsel __maybe_unused,
+		       struct machine *machine __maybe_unused)
+{
+	return 0;
+}
+
+static void strip_init(struct perf_inject *inject)
+{
+	struct perf_evlist *evlist = inject->session->evlist;
+	struct perf_evsel *evsel;
+
+	inject->tool.context_switch = perf_event__drop;
+
+	evlist__for_each(evlist, evsel)
+		evsel->handler = drop_sample;
+}
+
+static bool has_tracking(struct perf_evsel *evsel)
+{
+	return evsel->attr.mmap || evsel->attr.mmap2 || evsel->attr.comm ||
+	       evsel->attr.task;
+}
+
+#define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
+		     PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER)
+
+/*
+ * In order that the perf.data file is parsable, tracking events like MMAP need
+ * their selected event to exist, except if there is only 1 selected event left
+ * and it has a compatible sample type.
+ */
+static bool ok_to_remove(struct perf_evlist *evlist,
+			 struct perf_evsel *evsel_to_remove)
+{
+	struct perf_evsel *evsel;
+	int cnt = 0;
+	bool ok = false;
+
+	if (!has_tracking(evsel_to_remove))
+		return true;
+
+	evlist__for_each(evlist, evsel) {
+		if (evsel->handler != drop_sample) {
+			cnt += 1;
+			if ((evsel->attr.sample_type & COMPAT_MASK) ==
+			    (evsel_to_remove->attr.sample_type & COMPAT_MASK))
+				ok = true;
+		}
+	}
+
+	return ok && cnt == 1;
+}
+
+static void strip_fini(struct perf_inject *inject)
+{
+	struct perf_evlist *evlist = inject->session->evlist;
+	struct perf_evsel *evsel, *tmp;
+
+	/* Remove non-synthesized evsels if possible */
+	evlist__for_each_safe(evlist, tmp, evsel) {
+		if (evsel->handler == drop_sample &&
+		    ok_to_remove(evlist, evsel)) {
+			pr_debug("Deleting %s\n", perf_evsel__name(evsel));
+			perf_evlist__remove(evlist, evsel);
+			perf_evsel__delete(evsel);
+		}
+	}
+}
+
 static int __cmd_inject(struct perf_inject *inject)
 {
 	int ret = -EINVAL;
@@ -532,6 +613,8 @@ static int __cmd_inject(struct perf_inject *inject)
 		inject->tool.ordering_requires_timestamps = true;
 		/* Allow space in the header for new attributes */
 		output_data_offset = 4096;
+		if (inject->strip)
+			strip_init(inject);
 	}
 
 	if (!inject->itrace_synth_opts.set)
@@ -570,6 +653,8 @@ static int __cmd_inject(struct perf_inject *inject)
 				perf_evlist__remove(session->evlist, evsel);
 				perf_evsel__delete(evsel);
 			}
+			if (inject->strip)
+				strip_fini(inject);
 		}
 		session->header.data_offset = output_data_offset;
 		session->header.data_size = inject->bytes_written;
@@ -635,6 +720,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 		OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
 				    NULL, "opts", "Instruction Tracing options",
 				    itrace_parse_synth_opts),
+		OPT_BOOLEAN(0, "strip", &inject.strip,
+			    "strip non-synthesized events (use with --itrace)"),
 		OPT_END()
 	};
 	const char * const inject_usage[] = {
@@ -650,6 +737,11 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (argc)
 		usage_with_options(inject_usage, options);
 
+	if (inject.strip && !inject.itrace_synth_opts.set) {
+		pr_err("--strip option requires --itrace option\n");
+		return -1;
+	}
+
 	if (perf_data_file__open(&inject.output)) {
 		perror("failed to create output file");
 		return -1;
-- 
2.1.0


  parent reply	other threads:[~2015-09-28 21:13 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28 21:07 [GIT PULL 00/39] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 01/39] perf top: Filter symbols based on __map__is_kernel(map) Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 02/39] perf hists browser: Use the map to determine if a DSO is being used as a kernel Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 03/39] perf tools: Use __map__is_kernel() when synthesizing kernel module mmap records Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 04/39] tools lib api fs: Store tracing mountpoint for better error message Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 05/39] tools build: Add Makefile.include Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 06/39] tools build: Add test for missing include Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 07/39] tools build: Add fixdep dependency helper Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 08/39] tools build: Move dependency copy into function Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 09/39] tools build: Make the fixdep helper part of the build process Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 10/39] perf tools: Rename the 'single_dep' target to 'prepare' Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 11/39] tools build: Build fixdep helper from perf and basic libs Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 12/39] perf auxtrace: Fix 'instructions' period of zero Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 13/39] perf report: Fix sample type validation for synthesized callchains Arnaldo Carvalho de Melo
2015-09-28 21:07 ` [PATCH 14/39] perf intel-pt: Fix potential loop forever Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 15/39] perf intel-pt: Make logging slightly more efficient Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 16/39] perf script: Allow time to be displayed in nanoseconds Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 17/39] perf session: Warn when AUX data has been lost Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 18/39] perf tools: Add more documentation to export-to-postgresql.py script Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 19/39] perf auxtrace: Add option to synthesize branch stacks on samples Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 20/39] perf report: Adjust sample type validation for synthesized branch stacks Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 21/39] perf report: Also do default setup " Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 22/39] perf report: Skip events with null " Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 23/39] perf inject: Set branch stack feature flag when synthesizing " Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 24/39] perf intel-pt: Move branch filter logic Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 25/39] perf intel-pt: Support generating branch stack Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 26/39] perf report: Make max_stack value allow for synthesized callchains Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 27/39] perf hists: Allow for max_stack greater than PERF_MAX_STACK_DEPTH Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 28/39] perf script: Add a setting for maximum stack depth Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 29/39] perf scripting python: Allow for max_stack greater than PERF_MAX_STACK_DEPTH Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 30/39] perf script: Make scripting_max_stack value allow for synthesized callchains Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 31/39] perf evlist: Add perf_evlist__id2evsel_strict() Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 32/39] perf evlist: Add perf_evlist__remove() Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 33/39] perf inject: Remove more aux-related stuff when processing instruction traces Arnaldo Carvalho de Melo
2015-09-28 21:08 ` Arnaldo Carvalho de Melo [this message]
2015-09-28 21:08 ` [PATCH 35/39] perf intel-pt: Add mispred-all config option to aid use with autofdo Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 36/39] perf tools: Adds the config_term callback for different type events Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 37/39] perf tools: Show proper error message for wrong terms of hw/sw events Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 38/39] perf tools: Adds the tracepoint name parsing support Arnaldo Carvalho de Melo
2015-09-28 21:08 ` [PATCH 39/39] perf tools: Enable event_config terms to tracepoint events Arnaldo Carvalho de Melo
2015-09-29  7:47 ` [GIT PULL 00/39] perf/core improvements and fixes Ingo Molnar

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=1443474504-16528-35-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@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