All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] perf record: Synthesize features before events in pipe mode
@ 2018-03-14  9:22 Jiri Olsa
  2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jiri Olsa @ 2018-03-14  9:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

We need to synthesize events first, because some
features works on top of them (on report side).

Link: http://lkml.kernel.org/n/tip-vz436m6fobfz8ykmuxo8phyy@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-record.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d33103291b02..22ebeb92ac51 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -754,13 +754,10 @@ static int record__synthesize(struct record *rec, bool tail)
 		return 0;
 
 	if (data->is_pipe) {
-		err = perf_event__synthesize_features(
-			tool, session, rec->evlist, process_synthesized_event);
-		if (err < 0) {
-			pr_err("Couldn't synthesize features.\n");
-			return err;
-		}
-
+		/*
+		 * We need to synthesize events first, because some
+		 * features works on top of them (on report side).
+		 */
 		err = perf_event__synthesize_attrs(tool, session,
 						   process_synthesized_event);
 		if (err < 0) {
@@ -768,6 +765,13 @@ static int record__synthesize(struct record *rec, bool tail)
 			goto out;
 		}
 
+		err = perf_event__synthesize_features(tool, session, rec->evlist,
+						      process_synthesized_event);
+		if (err < 0) {
+			pr_err("Couldn't synthesize features.\n");
+			return err;
+		}
+
 		if (have_tracepoints(&rec->evlist->entries)) {
 			/*
 			 * FIXME err <= 0 here actually means that
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] perf report: Support forced leader feature in pipe mode
  2018-03-14  9:22 [PATCH 1/2] perf record: Synthesize features before events in pipe mode Jiri Olsa
@ 2018-03-14  9:22 ` Jiri Olsa
  2018-03-14 18:46   ` Stephane Eranian
  2018-03-20  6:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
  2018-03-14 18:45 ` [PATCH 1/2] perf record: Synthesize features before events " Stephane Eranian
  2018-03-20  6:32 ` [tip:perf/core] " tip-bot for Jiri Olsa
  2 siblings, 2 replies; 7+ messages in thread
From: Jiri Olsa @ 2018-03-14  9:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Stephan reported a problem with forced leader in pipe mode,
where report does not force the group output. The reason is
that we don't force the leader in pipe mode.

This patch adds HEADER_LAST_FEATURE mark to have a point
where we have all events and features received, and
force the group if requested.

  $ perf record --group -e '{cycles, instructions}' -o - kill | perf report -i - --group

  SNIP

  #         Overhead  Command  Shared Object     Symbol
  # ................  .......  ................  .......................
  #
      28.36%   0.00%  kill     libc-2.25.so      [.] __unregister_atfork
      26.32%   0.00%  kill     libc-2.25.so      [.] _dl_addr
      26.10%   0.00%  kill     ld-2.25.so        [.] _dl_relocate_object
      17.32%   0.00%  kill     ld-2.25.so        [.] __tunables_init
       1.70%   0.01%  kill     [unknown]         [k] 0xffffffffafa01a40
       0.20%   0.00%  kill     ld-2.25.so        [.] _start
       0.00%  48.77%  kill     ld-2.25.so        [.] do_lookup_x
       0.00%  42.97%  kill     libc-2.25.so      [.] _IO_getline
       0.00%   6.35%  kill     ld-2.25.so        [.] strcmp
       0.00%   1.71%  kill     ld-2.25.so        [.] _dl_sysdep_start
       0.00%   0.19%  kill     ld-2.25.so        [.] _dl_start

Link: http://lkml.kernel.org/n/tip-afxv5ufoxsbtxfhzupcv9ktg@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-report.c | 57 ++++++++++++++++++++++++++++++++++-----------
 tools/perf/util/header.c    | 11 ++++++++-
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 971ccba85464..91da12975642 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -68,6 +68,7 @@ struct report {
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
+	bool			group_set;
 	int			max_stack;
 	struct perf_read_values	show_threads_values;
 	const char		*pretty_printing_style;
@@ -193,6 +194,45 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
 	return err;
 }
 
+/*
+ * Events in data file are not collect in groups, but we still want
+ * the group display. Set the artificial group and set the leader's
+ * forced_leader flag to notify the display code.
+ */
+static void setup_forced_leader(struct report *report,
+				struct perf_evlist *evlist)
+{
+	if (report->group_set && !evlist->nr_groups) {
+		struct perf_evsel *leader = perf_evlist__first(evlist);
+
+		perf_evlist__set_leader(evlist);
+		leader->forced_leader = true;
+	}
+}
+
+static int process_feature_event(struct perf_tool *tool,
+				 union perf_event *event,
+				 struct perf_session *session __maybe_unused)
+{
+	struct report *rep = container_of(tool, struct report, tool);
+
+	if (event->feat.feat_id < HEADER_LAST_FEATURE)
+		return perf_event__process_feature(tool, event, session);
+
+	if (event->feat.feat_id != HEADER_LAST_FEATURE) {
+		pr_err("failed: wrong feature ID: %" PRIu64 "\n",
+		       event->feat.feat_id);
+		return -1;
+	}
+
+	/*
+	 * All features are received, we can force the
+	 * group if needed.
+	 */
+	setup_forced_leader(rep, session->evlist);
+	return 0;
+}
+
 static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -940,7 +980,6 @@ int cmd_report(int argc, const char **argv)
 		"perf report [<options>]",
 		NULL
 	};
-	bool group_set = false;
 	struct report report = {
 		.tool = {
 			.sample		 = process_sample_event,
@@ -958,7 +997,7 @@ int cmd_report(int argc, const char **argv)
 			.id_index	 = perf_event__process_id_index,
 			.auxtrace_info	 = perf_event__process_auxtrace_info,
 			.auxtrace	 = perf_event__process_auxtrace,
-			.feature	 = perf_event__process_feature,
+			.feature	 = process_feature_event,
 			.ordered_events	 = true,
 			.ordering_requires_timestamps = true,
 		},
@@ -1060,7 +1099,7 @@ int cmd_report(int argc, const char **argv)
 		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
 		    "Show a column with the sum of periods"),
-	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &group_set,
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
 		    "Show event group information together"),
 	OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
 		    "use branch records for per branch histogram filling",
@@ -1177,17 +1216,7 @@ int cmd_report(int argc, const char **argv)
 	has_br_stack = perf_header__has_feat(&session->header,
 					     HEADER_BRANCH_STACK);
 
-	/*
-	 * Events in data file are not collect in groups, but we still want
-	 * the group display. Set the artificial group and set the leader's
-	 * forced_leader flag to notify the display code.
-	 */
-	if (group_set && !session->evlist->nr_groups) {
-		struct perf_evsel *leader = perf_evlist__first(session->evlist);
-
-		perf_evlist__set_leader(session->evlist);
-		leader->forced_leader = true;
-	}
+	setup_forced_leader(&report, session->evlist);
 
 	if (itrace_synth_opts.last_branch)
 		has_br_stack = true;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e14b3f7c7212..121df1683c36 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3415,8 +3415,17 @@ int perf_event__synthesize_features(struct perf_tool *tool,
 			return ret;
 		}
 	}
+
+	/* Send HEADER_LAST_FEATURE mark. */
+	fe = ff.buf;
+	fe->feat_id     = HEADER_LAST_FEATURE;
+	fe->header.type = PERF_RECORD_HEADER_FEATURE;
+	fe->header.size = sizeof(*fe);
+
+	ret = process(tool, ff.buf, NULL, NULL);
+
 	free(ff.buf);
-	return 0;
+	return ret;
 }
 
 int perf_event__process_feature(struct perf_tool *tool,
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf record: Synthesize features before events in pipe mode
  2018-03-14  9:22 [PATCH 1/2] perf record: Synthesize features before events in pipe mode Jiri Olsa
  2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
@ 2018-03-14 18:45 ` Stephane Eranian
  2018-03-14 18:57   ` Arnaldo Carvalho de Melo
  2018-03-20  6:32 ` [tip:perf/core] " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 7+ messages in thread
From: Stephane Eranian @ 2018-03-14 18:45 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Alexander Shishkin, Peter Zijlstra

On Wed, Mar 14, 2018 at 2:22 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> We need to synthesize events first, because some
> features works on top of them (on report side).
>
> Link: http://lkml.kernel.org/n/tip-vz436m6fobfz8ykmuxo8phyy@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Works for me.
Tested-by: Stephane Eranian <eranian@google.com>

> ---
>  tools/perf/builtin-record.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index d33103291b02..22ebeb92ac51 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -754,13 +754,10 @@ static int record__synthesize(struct record *rec, bool tail)
>                 return 0;
>
>         if (data->is_pipe) {
> -               err = perf_event__synthesize_features(
> -                       tool, session, rec->evlist, process_synthesized_event);
> -               if (err < 0) {
> -                       pr_err("Couldn't synthesize features.\n");
> -                       return err;
> -               }
> -
> +               /*
> +                * We need to synthesize events first, because some
> +                * features works on top of them (on report side).
> +                */
>                 err = perf_event__synthesize_attrs(tool, session,
>                                                    process_synthesized_event);
>                 if (err < 0) {
> @@ -768,6 +765,13 @@ static int record__synthesize(struct record *rec, bool tail)
>                         goto out;
>                 }
>
> +               err = perf_event__synthesize_features(tool, session, rec->evlist,
> +                                                     process_synthesized_event);
> +               if (err < 0) {
> +                       pr_err("Couldn't synthesize features.\n");
> +                       return err;
> +               }
> +
>                 if (have_tracepoints(&rec->evlist->entries)) {
>                         /*
>                          * FIXME err <= 0 here actually means that
> --
> 2.13.6
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] perf report: Support forced leader feature in pipe mode
  2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
@ 2018-03-14 18:46   ` Stephane Eranian
  2018-03-20  6:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 7+ messages in thread
From: Stephane Eranian @ 2018-03-14 18:46 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	David Ahern, Alexander Shishkin, Peter Zijlstra

On Wed, Mar 14, 2018 at 2:22 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> Stephan reported a problem with forced leader in pipe mode,
> where report does not force the group output. The reason is
> that we don't force the leader in pipe mode.
>
> This patch adds HEADER_LAST_FEATURE mark to have a point
> where we have all events and features received, and
> force the group if requested.
>
>   $ perf record --group -e '{cycles, instructions}' -o - kill | perf report -i - --group
>
>   SNIP
>
>   #         Overhead  Command  Shared Object     Symbol
>   # ................  .......  ................  .......................
>   #
>       28.36%   0.00%  kill     libc-2.25.so      [.] __unregister_atfork
>       26.32%   0.00%  kill     libc-2.25.so      [.] _dl_addr
>       26.10%   0.00%  kill     ld-2.25.so        [.] _dl_relocate_object
>       17.32%   0.00%  kill     ld-2.25.so        [.] __tunables_init
>        1.70%   0.01%  kill     [unknown]         [k] 0xffffffffafa01a40
>        0.20%   0.00%  kill     ld-2.25.so        [.] _start
>        0.00%  48.77%  kill     ld-2.25.so        [.] do_lookup_x
>        0.00%  42.97%  kill     libc-2.25.so      [.] _IO_getline
>        0.00%   6.35%  kill     ld-2.25.so        [.] strcmp
>        0.00%   1.71%  kill     ld-2.25.so        [.] _dl_sysdep_start
>        0.00%   0.19%  kill     ld-2.25.so        [.] _dl_start
>
> Link: http://lkml.kernel.org/n/tip-afxv5ufoxsbtxfhzupcv9ktg@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Works for me.
Thanks.
Tested-by: Stephane Eranian <eranian@google.com>

> ---
>  tools/perf/builtin-report.c | 57 ++++++++++++++++++++++++++++++++++-----------
>  tools/perf/util/header.c    | 11 ++++++++-
>  2 files changed, 53 insertions(+), 15 deletions(-)
>
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index 971ccba85464..91da12975642 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -68,6 +68,7 @@ struct report {
>         bool                    header;
>         bool                    header_only;
>         bool                    nonany_branch_mode;
> +       bool                    group_set;
>         int                     max_stack;
>         struct perf_read_values show_threads_values;
>         const char              *pretty_printing_style;
> @@ -193,6 +194,45 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
>         return err;
>  }
>
> +/*
> + * Events in data file are not collect in groups, but we still want
> + * the group display. Set the artificial group and set the leader's
> + * forced_leader flag to notify the display code.
> + */
> +static void setup_forced_leader(struct report *report,
> +                               struct perf_evlist *evlist)
> +{
> +       if (report->group_set && !evlist->nr_groups) {
> +               struct perf_evsel *leader = perf_evlist__first(evlist);
> +
> +               perf_evlist__set_leader(evlist);
> +               leader->forced_leader = true;
> +       }
> +}
> +
> +static int process_feature_event(struct perf_tool *tool,
> +                                union perf_event *event,
> +                                struct perf_session *session __maybe_unused)
> +{
> +       struct report *rep = container_of(tool, struct report, tool);
> +
> +       if (event->feat.feat_id < HEADER_LAST_FEATURE)
> +               return perf_event__process_feature(tool, event, session);
> +
> +       if (event->feat.feat_id != HEADER_LAST_FEATURE) {
> +               pr_err("failed: wrong feature ID: %" PRIu64 "\n",
> +                      event->feat.feat_id);
> +               return -1;
> +       }
> +
> +       /*
> +        * All features are received, we can force the
> +        * group if needed.
> +        */
> +       setup_forced_leader(rep, session->evlist);
> +       return 0;
> +}
> +
>  static int process_sample_event(struct perf_tool *tool,
>                                 union perf_event *event,
>                                 struct perf_sample *sample,
> @@ -940,7 +980,6 @@ int cmd_report(int argc, const char **argv)
>                 "perf report [<options>]",
>                 NULL
>         };
> -       bool group_set = false;
>         struct report report = {
>                 .tool = {
>                         .sample          = process_sample_event,
> @@ -958,7 +997,7 @@ int cmd_report(int argc, const char **argv)
>                         .id_index        = perf_event__process_id_index,
>                         .auxtrace_info   = perf_event__process_auxtrace_info,
>                         .auxtrace        = perf_event__process_auxtrace,
> -                       .feature         = perf_event__process_feature,
> +                       .feature         = process_feature_event,
>                         .ordered_events  = true,
>                         .ordering_requires_timestamps = true,
>                 },
> @@ -1060,7 +1099,7 @@ int cmd_report(int argc, const char **argv)
>                    "Specify disassembler style (e.g. -M intel for intel syntax)"),
>         OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
>                     "Show a column with the sum of periods"),
> -       OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &group_set,
> +       OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
>                     "Show event group information together"),
>         OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
>                     "use branch records for per branch histogram filling",
> @@ -1177,17 +1216,7 @@ int cmd_report(int argc, const char **argv)
>         has_br_stack = perf_header__has_feat(&session->header,
>                                              HEADER_BRANCH_STACK);
>
> -       /*
> -        * Events in data file are not collect in groups, but we still want
> -        * the group display. Set the artificial group and set the leader's
> -        * forced_leader flag to notify the display code.
> -        */
> -       if (group_set && !session->evlist->nr_groups) {
> -               struct perf_evsel *leader = perf_evlist__first(session->evlist);
> -
> -               perf_evlist__set_leader(session->evlist);
> -               leader->forced_leader = true;
> -       }
> +       setup_forced_leader(&report, session->evlist);
>
>         if (itrace_synth_opts.last_branch)
>                 has_br_stack = true;
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index e14b3f7c7212..121df1683c36 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -3415,8 +3415,17 @@ int perf_event__synthesize_features(struct perf_tool *tool,
>                         return ret;
>                 }
>         }
> +
> +       /* Send HEADER_LAST_FEATURE mark. */
> +       fe = ff.buf;
> +       fe->feat_id     = HEADER_LAST_FEATURE;
> +       fe->header.type = PERF_RECORD_HEADER_FEATURE;
> +       fe->header.size = sizeof(*fe);
> +
> +       ret = process(tool, ff.buf, NULL, NULL);
> +
>         free(ff.buf);
> -       return 0;
> +       return ret;
>  }
>
>  int perf_event__process_feature(struct perf_tool *tool,
> --
> 2.13.6
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf record: Synthesize features before events in pipe mode
  2018-03-14 18:45 ` [PATCH 1/2] perf record: Synthesize features before events " Stephane Eranian
@ 2018-03-14 18:57   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-03-14 18:57 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, David Ahern,
	Alexander Shishkin, Peter Zijlstra

Em Wed, Mar 14, 2018 at 11:45:14AM -0700, Stephane Eranian escreveu:
> On Wed, Mar 14, 2018 at 2:22 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> > We need to synthesize events first, because some
> > features works on top of them (on report side).
> >
> > Link: http://lkml.kernel.org/n/tip-vz436m6fobfz8ykmuxo8phyy@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> 
> Works for me.
> Tested-by: Stephane Eranian <eranian@google.com>

Thanks for testing, will apply.

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip:perf/core] perf record: Synthesize features before events in pipe mode
  2018-03-14  9:22 [PATCH 1/2] perf record: Synthesize features before events in pipe mode Jiri Olsa
  2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
  2018-03-14 18:45 ` [PATCH 1/2] perf record: Synthesize features before events " Stephane Eranian
@ 2018-03-20  6:32 ` tip-bot for Jiri Olsa
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-03-20  6:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: eranian, alexander.shishkin, dsahern, acme, mingo, tglx, hpa,
	linux-kernel, jolsa, peterz, namhyung

Commit-ID:  a2015516c5c0be932a69e1d3405c2fb03b4eacf1
Gitweb:     https://git.kernel.org/tip/a2015516c5c0be932a69e1d3405c2fb03b4eacf1
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 14 Mar 2018 10:22:04 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 16 Mar 2018 13:56:50 -0300

perf record: Synthesize features before events in pipe mode

We need to synthesize events first, because some features works on top
of them (on report side).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180314092205.23291-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-record.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d33103291b02..22ebeb92ac51 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -754,13 +754,10 @@ static int record__synthesize(struct record *rec, bool tail)
 		return 0;
 
 	if (data->is_pipe) {
-		err = perf_event__synthesize_features(
-			tool, session, rec->evlist, process_synthesized_event);
-		if (err < 0) {
-			pr_err("Couldn't synthesize features.\n");
-			return err;
-		}
-
+		/*
+		 * We need to synthesize events first, because some
+		 * features works on top of them (on report side).
+		 */
 		err = perf_event__synthesize_attrs(tool, session,
 						   process_synthesized_event);
 		if (err < 0) {
@@ -768,6 +765,13 @@ static int record__synthesize(struct record *rec, bool tail)
 			goto out;
 		}
 
+		err = perf_event__synthesize_features(tool, session, rec->evlist,
+						      process_synthesized_event);
+		if (err < 0) {
+			pr_err("Couldn't synthesize features.\n");
+			return err;
+		}
+
 		if (have_tracepoints(&rec->evlist->entries)) {
 			/*
 			 * FIXME err <= 0 here actually means that

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [tip:perf/core] perf report: Support forced leader feature in pipe mode
  2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
  2018-03-14 18:46   ` Stephane Eranian
@ 2018-03-20  6:32   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-03-20  6:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, alexander.shishkin, dsahern, eranian, mingo, tglx, jolsa,
	acme, linux-kernel, namhyung, hpa

Commit-ID:  57b5de463925b9fbd1eff56a38a510495ac9c2c0
Gitweb:     https://git.kernel.org/tip/57b5de463925b9fbd1eff56a38a510495ac9c2c0
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Wed, 14 Mar 2018 10:22:05 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 16 Mar 2018 13:56:59 -0300

perf report: Support forced leader feature in pipe mode

Stephane reported a problem with forced leader in pipe mode, where
report does not force the group output. The reason is that we don't
force the leader in pipe mode.

This patch adds HEADER_LAST_FEATURE mark to have a point where we have
all events and features received, and force the group if requested.

  $ perf record --group -e '{cycles, instructions}' -o - kill | perf report -i - --group

  SNIP

  #         Overhead  Command  Shared Object     Symbol
  # ................  .......  ................  .......................
  #
      28.36%   0.00%  kill     libc-2.25.so      [.] __unregister_atfork
      26.32%   0.00%  kill     libc-2.25.so      [.] _dl_addr
      26.10%   0.00%  kill     ld-2.25.so        [.] _dl_relocate_object
      17.32%   0.00%  kill     ld-2.25.so        [.] __tunables_init
       1.70%   0.01%  kill     [unknown]         [k] 0xffffffffafa01a40
       0.20%   0.00%  kill     ld-2.25.so        [.] _start
       0.00%  48.77%  kill     ld-2.25.so        [.] do_lookup_x
       0.00%  42.97%  kill     libc-2.25.so      [.] _IO_getline
       0.00%   6.35%  kill     ld-2.25.so        [.] strcmp
       0.00%   1.71%  kill     ld-2.25.so        [.] _dl_sysdep_start
       0.00%   0.19%  kill     ld-2.25.so        [.] _dl_start

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180314092205.23291-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c | 57 ++++++++++++++++++++++++++++++++++-----------
 tools/perf/util/header.c    | 11 ++++++++-
 2 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 971ccba85464..91da12975642 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -68,6 +68,7 @@ struct report {
 	bool			header;
 	bool			header_only;
 	bool			nonany_branch_mode;
+	bool			group_set;
 	int			max_stack;
 	struct perf_read_values	show_threads_values;
 	const char		*pretty_printing_style;
@@ -193,6 +194,45 @@ out:
 	return err;
 }
 
+/*
+ * Events in data file are not collect in groups, but we still want
+ * the group display. Set the artificial group and set the leader's
+ * forced_leader flag to notify the display code.
+ */
+static void setup_forced_leader(struct report *report,
+				struct perf_evlist *evlist)
+{
+	if (report->group_set && !evlist->nr_groups) {
+		struct perf_evsel *leader = perf_evlist__first(evlist);
+
+		perf_evlist__set_leader(evlist);
+		leader->forced_leader = true;
+	}
+}
+
+static int process_feature_event(struct perf_tool *tool,
+				 union perf_event *event,
+				 struct perf_session *session __maybe_unused)
+{
+	struct report *rep = container_of(tool, struct report, tool);
+
+	if (event->feat.feat_id < HEADER_LAST_FEATURE)
+		return perf_event__process_feature(tool, event, session);
+
+	if (event->feat.feat_id != HEADER_LAST_FEATURE) {
+		pr_err("failed: wrong feature ID: %" PRIu64 "\n",
+		       event->feat.feat_id);
+		return -1;
+	}
+
+	/*
+	 * All features are received, we can force the
+	 * group if needed.
+	 */
+	setup_forced_leader(rep, session->evlist);
+	return 0;
+}
+
 static int process_sample_event(struct perf_tool *tool,
 				union perf_event *event,
 				struct perf_sample *sample,
@@ -940,7 +980,6 @@ int cmd_report(int argc, const char **argv)
 		"perf report [<options>]",
 		NULL
 	};
-	bool group_set = false;
 	struct report report = {
 		.tool = {
 			.sample		 = process_sample_event,
@@ -958,7 +997,7 @@ int cmd_report(int argc, const char **argv)
 			.id_index	 = perf_event__process_id_index,
 			.auxtrace_info	 = perf_event__process_auxtrace_info,
 			.auxtrace	 = perf_event__process_auxtrace,
-			.feature	 = perf_event__process_feature,
+			.feature	 = process_feature_event,
 			.ordered_events	 = true,
 			.ordering_requires_timestamps = true,
 		},
@@ -1060,7 +1099,7 @@ int cmd_report(int argc, const char **argv)
 		   "Specify disassembler style (e.g. -M intel for intel syntax)"),
 	OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
 		    "Show a column with the sum of periods"),
-	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &group_set,
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group, &report.group_set,
 		    "Show event group information together"),
 	OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
 		    "use branch records for per branch histogram filling",
@@ -1177,17 +1216,7 @@ repeat:
 	has_br_stack = perf_header__has_feat(&session->header,
 					     HEADER_BRANCH_STACK);
 
-	/*
-	 * Events in data file are not collect in groups, but we still want
-	 * the group display. Set the artificial group and set the leader's
-	 * forced_leader flag to notify the display code.
-	 */
-	if (group_set && !session->evlist->nr_groups) {
-		struct perf_evsel *leader = perf_evlist__first(session->evlist);
-
-		perf_evlist__set_leader(session->evlist);
-		leader->forced_leader = true;
-	}
+	setup_forced_leader(&report, session->evlist);
 
 	if (itrace_synth_opts.last_branch)
 		has_br_stack = true;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index e14b3f7c7212..121df1683c36 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3415,8 +3415,17 @@ int perf_event__synthesize_features(struct perf_tool *tool,
 			return ret;
 		}
 	}
+
+	/* Send HEADER_LAST_FEATURE mark. */
+	fe = ff.buf;
+	fe->feat_id     = HEADER_LAST_FEATURE;
+	fe->header.type = PERF_RECORD_HEADER_FEATURE;
+	fe->header.size = sizeof(*fe);
+
+	ret = process(tool, ff.buf, NULL, NULL);
+
 	free(ff.buf);
-	return 0;
+	return ret;
 }
 
 int perf_event__process_feature(struct perf_tool *tool,

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-20  6:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14  9:22 [PATCH 1/2] perf record: Synthesize features before events in pipe mode Jiri Olsa
2018-03-14  9:22 ` [PATCH 2/2] perf report: Support forced leader feature " Jiri Olsa
2018-03-14 18:46   ` Stephane Eranian
2018-03-20  6:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
2018-03-14 18:45 ` [PATCH 1/2] perf record: Synthesize features before events " Stephane Eranian
2018-03-14 18:57   ` Arnaldo Carvalho de Melo
2018-03-20  6:32 ` [tip:perf/core] " tip-bot for Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.