Skip to contentSkip to conversation

perf annotate: Support '--group' option

PATCH In review Jin Yao 3 participants 9 messages May 21, 2018 – May 24, 2018 perf events

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

v4 cover perf annotate: Support '--group' option

For non-explicit group, perf report has already supported a option '--group' which can enable group output.

This patch-set will support perf annotate with the same '--group'.

For example,

    perf record -e cycles,branches ./div
    perf annotate main --stdio --group

                     :            Disassembly of section .text:
                     :
                     :            00000000004004b0 <main>:
                     :            main():
                     :
                     :                    return i;
                     :            }
                     :
                     :            int main(void)
                     :            {
        0.00    0.00 :   4004b0:       push   %rbx
                     :                    int i;
                     :                    int flag;
                     :                    volatile double x = 1212121212, y = 121212;
                     :
                     :                    s_randseed = time(0);
        0.00    0.00 :   4004b1:       xor    %edi,%edi
                     :                    srand(s_randseed);
        0.00    0.00 :   4004b3:       mov    $0x77359400,%ebx
                     :
                     :                    return i;
                     :            }
                     :

v4:
---
Change function name from perf_evlist_forced_leader to perf_evlist__force_leader

Impact:
-------
perf evlist: Create new function perf_evlist__force_leader perf report: Use perf_evlist__force_leader to support '--group' perf annotate: Support '--group' option

v3:
---------
Move the comment which was on setup_forced_leader() to the new function perf_evlist_forced_leader().

Impact
------
perf evlist: Create a new function perf_evlist_forced_leader perf report: Use perf_evlist_forced_leader to support '--group'

v2:
---------
Arnaldo points out that it should be done the way it is for perf report --group. v2 refers to this way and the patch is totally rewritten.

Init post:
----------
Post the patch 'perf annotate: Support multiple events without group'

Jin Yao (3):
perf evlist: Create new function perf_evlist__force_leader perf report: Use perf_evlist__force_leader to support '--group' perf annotate: Support '--group' option

 tools/perf/builtin-annotate.c |  7 +++++++
 tools/perf/builtin-report.c   | 13 ++-----------
 tools/perf/util/evlist.c      | 15 +++++++++++++++
 tools/perf/util/evlist.h      |  3 +++
 4 files changed, 27 insertions(+), 11 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v4 1/3 perf evlist: Create new function perf_evlist__force_leader

For non-explicit group, perf report supports a option '--group' which can enable group output. We also need to support perf annotate with the same '--group'.

Create a new function perf_evlist__force_leader which contains common code to force setting the group leader.

---
 tools/perf/util/evlist.c | 15 +++++++++++++++
 tools/perf/util/evlist.h |  3 +++
 2 files changed, 18 insertions(+)
tools/perf/util/evlist.c +15 -0
index a59281d..e7a4b31 100644
@@ -1795,3 +1795,18 @@ bool perf_evlist__exclude_kernel(struct perf_evlist *evlist)
 
 	return true;
 }
+
+/*
+ * 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.
+ */
+void perf_evlist__force_leader(struct perf_evlist *evlist)
+{
+	if (!evlist->nr_groups) {
+		struct perf_evsel *leader = perf_evlist__first(evlist);
+
+		perf_evlist__set_leader(evlist);
+		leader->forced_leader = true;
+	}
+}
tools/perf/util/evlist.h +3 -0
index 6c41b2f..dc66436 100644
@@ -309,4 +309,7 @@ struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
 					    union perf_event *event);
 
 bool perf_evlist__exclude_kernel(struct perf_evlist *evlist);
+
+void perf_evlist__force_leader(struct perf_evlist *evlist);
+
 #endif /* __PERF_EVLIST_H */
Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/core] perf evlist: Introduce force_leader() method

perf evlist: Introduce force_leader() method
Commit-ID:  e2bdbe80a0b7dea9ba73582701b8a67c01e1da4f
Gitweb:     https://git.kernel.org/tip/e2bdbe80a0b7dea9ba73582701b8a67c01e1da4f
Author:     Jin Yao <[email protected]>
AuthorDate: Mon, 21 May 2018 22:57:44 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 May 2018 14:40:54 -0300

perf evlist: Introduce force_leader() method

For non-explicit group (e.g. those created with -e '{eventA,eventB}'), 'perf report' supports a option '--group' which can enable group output.

We also need to support 'perf annotate' with the same '--group'.

Create a new function perf_evlist__force_leader() which contains common code to force setting the group leader.

---
 tools/perf/util/evlist.c | 15 +++++++++++++++
 tools/perf/util/evlist.h |  3 +++
 2 files changed, 18 insertions(+)
tools/perf/util/evlist.c +15 -0
index a59281d64368..e7a4b31a84fb 100644
@@ -1795,3 +1795,18 @@ bool perf_evlist__exclude_kernel(struct perf_evlist *evlist)
 
 	return true;
 }
+
+/*
+ * 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.
+ */
+void perf_evlist__force_leader(struct perf_evlist *evlist)
+{
+	if (!evlist->nr_groups) {
+		struct perf_evsel *leader = perf_evlist__first(evlist);
+
+		perf_evlist__set_leader(evlist);
+		leader->forced_leader = true;
+	}
+}
tools/perf/util/evlist.h +3 -0
index 6c41b2f78713..dc66436add98 100644
@@ -309,4 +309,7 @@ struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
 					    union perf_event *event);
 
 bool perf_evlist__exclude_kernel(struct perf_evlist *evlist);
+
+void perf_evlist__force_leader(struct perf_evlist *evlist);
+
 #endif /* __PERF_EVLIST_H */
author
#3 lore raw

PATCH v4 2/3 perf report: Use perf_evlist__force_leader to support '--group'

In reply to Jin Yao

Since we have created a new function perf_evlist__force_leader, so now remove the old code and use perf_evlist__force_leader instead.

---
 tools/perf/builtin-report.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
tools/perf/builtin-report.c +2 -11
index 4c931af..ad978e3 100644
@@ -194,20 +194,11 @@ 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;
-	}
+	if (report->group_set)
+		perf_evlist__force_leader(evlist);
 }
 
 static int process_feature_event(struct perf_tool *tool,
Signature · 1 line
2.7.4
#4 lore raw

[tip:perf/core] perf report: Use perf_evlist__force_leader to support '--group'

perf report: Use perf_evlist__force_leader to support '--group'
Commit-ID:  a26bb0ba706aef4f42cc9377c0d4e849378574a4
Gitweb:     https://git.kernel.org/tip/a26bb0ba706aef4f42cc9377c0d4e849378574a4
Author:     Jin Yao <[email protected]>
AuthorDate: Mon, 21 May 2018 22:57:45 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 May 2018 14:41:01 -0300

perf report: Use perf_evlist__force_leader to support '--group'

Since we created a new function perf_evlist__force_leader(), remove the old code and use that new evlist method.

---
 tools/perf/builtin-report.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
tools/perf/builtin-report.c +2 -11
index 4c931afb2e80..ad978e3ee2b8 100644
@@ -194,20 +194,11 @@ 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;
-	}
+	if (report->group_set)
+		perf_evlist__force_leader(evlist);
 }
 
 static int process_feature_event(struct perf_tool *tool,
author
#5 lore raw

PATCH v4 3/3 perf annotate: Support '--group' option

In reply to Jin Yao

With the '--group' option, even for non-explicit group, perf annotate will enable the group output.

For example,

perf record -e cycles,branches ./div
perf annotate main --stdio --group

                 :            Disassembly of section .text:
                 :
                 :            00000000004004b0 <main>:
                 :            main():
                 :
                 :                    return i;
                 :            }
                 :
                 :            int main(void)
                 :            {
    0.00    0.00 :   4004b0:       push   %rbx
                 :                    int i;
                 :                    int flag;
                 :                    volatile double x = 1212121212, y = 121212;
                 :
                 :                    s_randseed = time(0);
    0.00    0.00 :   4004b1:       xor    %edi,%edi
                 :                    srand(s_randseed);
    0.00    0.00 :   4004b3:       mov    $0x77359400,%ebx
                 :
                 :                    return i;
                 :            }
                 :

But if without --group, there is only one event reported.

perf annotate main --stdio

         :            Disassembly of section .text:
         :
         :            00000000004004b0 <main>:
         :            main():
         :
         :                    return i;
         :            }
         :
         :            int main(void)
         :            {
    0.00 :   4004b0:       push   %rbx
         :                    int i;
         :                    int flag;
         :                    volatile double x = 1212121212, y = 121212;
         :
         :                    s_randseed = time(0);
    0.00 :   4004b1:       xor    %edi,%edi
         :                    srand(s_randseed);
    0.00 :   4004b3:       mov    $0x77359400,%ebx
         :
         :                    return i;
         :            }
---
 tools/perf/builtin-annotate.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/builtin-annotate.c +7 -0
index 6e5d9f7..da57042 100644
@@ -45,6 +45,7 @@ struct perf_annotate {
 	bool	   print_line;
 	bool	   skip_missing;
 	bool	   has_br_stack;
+	bool	   group_set;
 	const char *sym_hist_filter;
 	const char *cpu_list;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -508,6 +509,9 @@ int cmd_annotate(int argc, const char **argv)
 		    "Don't shorten the displayed pathnames"),
 	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
 		    "Skip symbols that cannot be annotated"),
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group,
+			&annotate.group_set,
+			"Show event group information together"),
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
 	OPT_CALLBACK(0, "symfs", NULL, "directory",
 		     "Look for files with symbols relative to this directory",
@@ -570,6 +574,9 @@ int cmd_annotate(int argc, const char **argv)
 	annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
 						      HEADER_BRANCH_STACK);
 
+	if (annotate.group_set)
+		perf_evlist__force_leader(annotate.session->evlist);
+
 	ret = symbol__annotation_init();
 	if (ret < 0)
 		goto out_delete;
Signature · 1 line
2.7.4
#6 lore raw

Em Mon, May 21, 2018 at 10:57:46PM +0800, Jin Yao escreveu:

Quoted 7 lines

With the '--group' option, even for non-explicit group, perf annotate will enable the group output.

For example,

perf record -e cycles,branches ./div
perf annotate main --stdio --group

You forgot to make the first line to include the group event string, i.e. for cycles,instructions it will show only this:

Percent | Source code & Disassembly of ld-2.26.so for cycles:u (1 samples)
----------------------------------------------------------------------------------------

                 :
                 :
                 :
                 :           Disassembly of section .text:
                 :
                 :           00000000000167e0 <__GI___tunables_init>:
                 :           __GI___tunables_init():
                 :           /* Initialize the tunables list from the environment.  For now we only use the
                 :              ENV_ALIAS to find values.  Later we will also use the tunable names to find
                 :              values.  */
                 :           void
                 :           __tunables_init (char **envp)
                 :           {
    0.00    0.00 :   167e0:       push   %r15
    0.00    0.00 :   167e2:       push   %r14

I'm applying the patch, this can be done on top,

- Arnaldo

Quoted 91 lines
                 :            Disassembly of section .text:
                 :
                 :            00000000004004b0 <main>:
                 :            main():
                 :
                 :                    return i;
                 :            }
                 :
                 :            int main(void)
                 :            {
    0.00    0.00 :   4004b0:       push   %rbx
                 :                    int i;
                 :                    int flag;
                 :                    volatile double x = 1212121212, y = 121212;
                 :
                 :                    s_randseed = time(0);
    0.00    0.00 :   4004b1:       xor    %edi,%edi
                 :                    srand(s_randseed);
    0.00    0.00 :   4004b3:       mov    $0x77359400,%ebx
                 :
                 :                    return i;
                 :            }
                 :

But if without --group, there is only one event reported.

perf annotate main --stdio

         :            Disassembly of section .text:
         :
         :            00000000004004b0 <main>:
         :            main():
         :
         :                    return i;
         :            }
         :
         :            int main(void)
         :            {
    0.00 :   4004b0:       push   %rbx
         :                    int i;
         :                    int flag;
         :                    volatile double x = 1212121212, y = 121212;
         :
         :                    s_randseed = time(0);
    0.00 :   4004b1:       xor    %edi,%edi
         :                    srand(s_randseed);
    0.00 :   4004b3:       mov    $0x77359400,%ebx
         :
         :                    return i;
         :            }
---
 tools/perf/builtin-annotate.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/builtin-annotate.c +7 -0
index 6e5d9f7..da57042 100644
@@ -45,6 +45,7 @@ struct perf_annotate {
 	bool	   print_line;
 	bool	   skip_missing;
 	bool	   has_br_stack;
+	bool	   group_set;
 	const char *sym_hist_filter;
 	const char *cpu_list;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -508,6 +509,9 @@ int cmd_annotate(int argc, const char **argv)
 		    "Don't shorten the displayed pathnames"),
 	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
 		    "Skip symbols that cannot be annotated"),
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group,
+			&annotate.group_set,
+			"Show event group information together"),
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
 	OPT_CALLBACK(0, "symfs", NULL, "directory",
 		     "Look for files with symbols relative to this directory",
@@ -570,6 +574,9 @@ int cmd_annotate(int argc, const char **argv)
 	annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
 						      HEADER_BRANCH_STACK);
 
+	if (annotate.group_set)
+		perf_evlist__force_leader(annotate.session->evlist);
+
 	ret = symbol__annotation_init();
 	if (ret < 0)
 		goto out_delete;
Signature · 1 line
2.7.4
author
#7 lore raw
Quoted 30 lines · Arnaldo Carvalho de Melo

Em Mon, May 21, 2018 at 10:57:46PM +0800, Jin Yao escreveu:

Quoted 7 lines

With the '--group' option, even for non-explicit group, perf annotate will enable the group output.

For example,

perf record -e cycles,branches ./div
perf annotate main --stdio --group

You forgot to make the first line to include the group event string, i.e. for cycles,instructions it will show only this:

Percent | Source code & Disassembly of ld-2.26.so for cycles:u (1 samples)
----------------------------------------------------------------------------------------

                  :
                  :
                  :
                  :           Disassembly of section .text:
                  :
                  :           00000000000167e0 <__GI___tunables_init>:
                  :           __GI___tunables_init():
                  :           /* Initialize the tunables list from the environment.  For now we only use the
                  :              ENV_ALIAS to find values.  Later we will also use the tunable names to find
                  :              values.  */
                  :           void
                  :           __tunables_init (char **envp)
                  :           {
     0.00    0.00 :   167e0:       push   %r15
     0.00    0.00 :   167e2:       push   %r14
Quoted 4 lines

I'm applying the patch, this can be done on top,

- Arnaldo

Oh, 'perf annotate --group' can show the group string but 'perf annotate --group --stdio' shows only one event.

I will check the '--stdio' and post a followup patch to fix that.

Thanks
Jin Yao

Quoted 91 lines
Quoted 91 lines
                  :            Disassembly of section .text:
                  :
                  :            00000000004004b0 <main>:
                  :            main():
                  :
                  :                    return i;
                  :            }
                  :
                  :            int main(void)
                  :            {
     0.00    0.00 :   4004b0:       push   %rbx
                  :                    int i;
                  :                    int flag;
                  :                    volatile double x = 1212121212, y = 121212;
                  :
                  :                    s_randseed = time(0);
     0.00    0.00 :   4004b1:       xor    %edi,%edi
                  :                    srand(s_randseed);
     0.00    0.00 :   4004b3:       mov    $0x77359400,%ebx
                  :
                  :                    return i;
                  :            }
                  :

But if without --group, there is only one event reported.

perf annotate main --stdio

          :            Disassembly of section .text:
          :
          :            00000000004004b0 <main>:
          :            main():
          :
          :                    return i;
          :            }
          :
          :            int main(void)
          :            {
     0.00 :   4004b0:       push   %rbx
          :                    int i;
          :                    int flag;
          :                    volatile double x = 1212121212, y = 121212;
          :
          :                    s_randseed = time(0);
     0.00 :   4004b1:       xor    %edi,%edi
          :                    srand(s_randseed);
     0.00 :   4004b3:       mov    $0x77359400,%ebx
          :
          :                    return i;
          :            }
---
  tools/perf/builtin-annotate.c | 7 +++++++
  1 file changed, 7 insertions(+)
tools/perf/builtin-annotate.c +7 -0
index 6e5d9f7..da57042 100644
@@ -45,6 +45,7 @@ struct perf_annotate {
  	bool	   print_line;
  	bool	   skip_missing;
  	bool	   has_br_stack;
+	bool	   group_set;
  	const char *sym_hist_filter;
  	const char *cpu_list;
  	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -508,6 +509,9 @@ int cmd_annotate(int argc, const char **argv)
  		    "Don't shorten the displayed pathnames"),
  	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
  		    "Skip symbols that cannot be annotated"),
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group,
+			&annotate.group_set,
+			"Show event group information together"),
  	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
  	OPT_CALLBACK(0, "symfs", NULL, "directory",
  		     "Look for files with symbols relative to this directory",
@@ -570,6 +574,9 @@ int cmd_annotate(int argc, const char **argv)
  	annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
  						      HEADER_BRANCH_STACK);
 
+	if (annotate.group_set)
+		perf_evlist__force_leader(annotate.session->evlist);
+
  	ret = symbol__annotation_init();
  	if (ret < 0)
  		goto out_delete;
Signature · 1 line
2.7.4
#8 lore raw
In reply to Jin Yao
perf annotate: Support '--group' option
Commit-ID:  7ebaf4890f63eb90856b76864a0847413cdf6c86
Gitweb:     https://git.kernel.org/tip/7ebaf4890f63eb90856b76864a0847413cdf6c86
Author:     Jin Yao <[email protected]>
AuthorDate: Mon, 21 May 2018 22:57:46 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 May 2018 14:41:25 -0300

perf annotate: Support '--group' option

With the '--group' option, even for non-explicit group, 'perf annotate' will enable the group output.

For example,

  $ perf record -e cycles,branches ./div
  $ perf annotate main --stdio --group
                 :            Disassembly of section .text:
                 :
                 :            00000000004004b0 <main>:
                 :            main():
                 :
                 :                    return i;
                 :            }
                 :
                 :            int main(void)
                 :            {
    0.00    0.00 :   4004b0:       push   %rbx
                 :                    int i;
                 :                    int flag;
                 :                    volatile double x = 1212121212, y = 121212;
                 :
                 :                    s_randseed = time(0);
    0.00    0.00 :   4004b1:       xor    %edi,%edi
                 :                    srand(s_randseed);
    0.00    0.00 :   4004b3:       mov    $0x77359400,%ebx
                 :
                 :                    return i;
                 :            }
                 :

But if without --group, there is only one event reported.

  $ perf annotate main --stdio
         :            Disassembly of section .text:
         :
         :            00000000004004b0 <main>:
         :            main():
         :
         :                    return i;
         :            }
         :
         :            int main(void)
         :            {
    0.00 :   4004b0:       push   %rbx
         :                    int i;
         :                    int flag;
         :                    volatile double x = 1212121212, y = 121212;
         :
         :                    s_randseed = time(0);
    0.00 :   4004b1:       xor    %edi,%edi
         :                    srand(s_randseed);
    0.00 :   4004b3:       mov    $0x77359400,%ebx
         :
         :                    return i;
         :            }
---
 tools/perf/builtin-annotate.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/builtin-annotate.c +7 -0
index 6e5d9f718154..da5704240239 100644
@@ -45,6 +45,7 @@ struct perf_annotate {
 	bool	   print_line;
 	bool	   skip_missing;
 	bool	   has_br_stack;
+	bool	   group_set;
 	const char *sym_hist_filter;
 	const char *cpu_list;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -508,6 +509,9 @@ int cmd_annotate(int argc, const char **argv)
 		    "Don't shorten the displayed pathnames"),
 	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
 		    "Skip symbols that cannot be annotated"),
+	OPT_BOOLEAN_SET(0, "group", &symbol_conf.event_group,
+			&annotate.group_set,
+			"Show event group information together"),
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
 	OPT_CALLBACK(0, "symfs", NULL, "directory",
 		     "Look for files with symbols relative to this directory",
@@ -570,6 +574,9 @@ int cmd_annotate(int argc, const char **argv)
 	annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
 						      HEADER_BRANCH_STACK);
 
+	if (annotate.group_set)
+		perf_evlist__force_leader(annotate.session->evlist);
+
 	ret = symbol__annotation_init();
 	if (ret < 0)
 		goto out_delete;