All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] perf top: Add --branch-history option
@ 2023-03-30 13:18 Adrian Hunter
  2023-03-30 13:18 ` [PATCH 1/2] " Adrian Hunter
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Adrian Hunter @ 2023-03-30 13:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, Andi Kleen, linux-kernel,
	linux-perf-users

Hi

Here are small patches related to option --branch-history.

Note, currently --branch-history is broken due to patch
"perf report: append inlines to non-dwarf callchains" so
that needs to be reverted / fixed beforehand.


Adrian Hunter (2):
      perf top: Add --branch-history option
      perf symbol: Remove unused branch_callstack

 tools/perf/Documentation/perf-top.txt |  4 ++++
 tools/perf/builtin-top.c              | 17 +++++++++++++++++
 tools/perf/util/symbol_conf.h         |  1 -
 3 files changed, 21 insertions(+), 1 deletion(-)


Regards
Adrian

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

* [PATCH 1/2] perf top: Add --branch-history option
  2023-03-30 13:18 [PATCH 0/2] perf top: Add --branch-history option Adrian Hunter
@ 2023-03-30 13:18 ` Adrian Hunter
  2023-03-30 13:18 ` [PATCH 2/2] perf symbol: Remove unused branch_callstack Adrian Hunter
  2023-03-30 21:14 ` [PATCH 0/2] perf top: Add --branch-history option Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2023-03-30 13:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, Andi Kleen, linux-kernel,
	linux-perf-users

Add --branch-history option, to act the same as that option does for
perf report.

Example:

  $ cat tcallf.c
  volatile a = 10000, b = 100000, c;

  __attribute__((noinline)) f2()
  {
          c = a / b;
  }

  __attribute__((noinline)) f1()
  {
          f2();
          f2();
  }
  main()
  {
          while (1)
                  f1();
  }
  $ gcc -w -g -o tcallf tcallf.c
  $ ./tcallf &
  [1] 29409
  $ perf top -e cycles:u  -t $(pidof tcallf) --stdio --no-children --branch-history
     PerfTop:    3819 irqs/sec  kernel: 0.0%  exact:  0.0% lost: 0/0 drop: 0/0 [4000Hz cycles:u],  (target_tid: 29409)
  --------------------------------------------------------------------------------------------------------------------

      49.01%  tcallf.c:5   [.] f2    tcallf
              |
              |--24.91%--f2 tcallf.c:4
              |          |
              |          |--17.14%--f1 tcallf.c:11 (cycles:1)
              |          |          f1 tcallf.c:11
              |          |          f2 tcallf.c:6 (cycles:3)
              |          |          f2 tcallf.c:4
              |          |          f1 tcallf.c:10 (cycles:2)
              |          |          f1 tcallf.c:9
              |          |          main tcallf.c:16 (cycles:1)
              |          |          main tcallf.c:16
              |          |          main tcallf.c:16 (cycles:1)
              |          |          main tcallf.c:16
              |          |          f1 tcallf.c:12 (cycles:1)
              |          |          f1 tcallf.c:12
              |          |          f2 tcallf.c:6 (cycles:3)
              |          |          f2 tcallf.c:4
              |          |          f1 tcallf.c:11 (cycles:1 iter:1 avg_cycles:12)
              |          |          f1 tcallf.c:11
              |          |          f2 tcallf.c:6 (cycles:3 iter:1 avg_cycles:12)
              |          |          f2 tcallf.c:4
              |          |          f1 tcallf.c:10 (cycles:2 iter:1 avg_cycles:12)
              |          |
              |           --7.78%--f1 tcallf.c:10 (cycles:2)
              |                     f1 tcallf.c:9
              |                     main tcallf.c:16 (cycles:1)
              |                     main tcallf.c:16
              |                     main tcallf.c:16 (cycles:1)
              |                     main tcallf.c:16
              |                     f1 tcallf.c:12 (cycles:1)
              |                     f1 tcallf.c:12
              |                     f2 tcallf.c:6 (cycles:3)
              |                     f2 tcallf.c:4
              |                     f1 tcallf.c:11 (cycles:1)
              |                     f1 tcallf.c:11
              |                     f2 tcallf.c:6 (cycles:3)
              |                     f2 tcallf.c:4
              |                     f1 tcallf.c:10 (cycles:2 iter:1 avg_cycles:12)
              |                     f1 tcallf.c:9
              |                     main tcallf.c:16 (cycles:1 iter:1 avg_cycles:12)
              |                     main tcallf.c:16
              |                     main tcallf.c:16 (cycles:1 iter:1 avg_cycles:12)
  ...

  $ pkill tcallf
  [1]+  Terminated              ./tcallf

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-top.txt |  4 ++++
 tools/perf/builtin-top.c              | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index 619cc8143ad5..3c202ec080ba 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -254,6 +254,10 @@ Default is to monitor all CPUS.
 	The various filters must be specified as a comma separated list: --branch-filter any_ret,u,k
 	Note that this feature may not be available on all processors.
 
+--branch-history::
+	Add the addresses of sampled taken branches to the callstack.
+	This allows to examine the path the program took to each sample.
+
 --raw-trace::
 	When displaying traceevent output, do not use print fmt or plugins.
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 82c6c065830d..2c985cfea517 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1437,6 +1437,7 @@ int cmd_top(int argc, const char **argv)
 		.max_stack	     = sysctl__max_stack(),
 		.nr_threads_synthesize = UINT_MAX,
 	};
+	bool branch_call_mode = false;
 	struct record_opts *opts = &top.record_opts;
 	struct target *target = &opts->target;
 	const char *disassembler_style = NULL, *objdump_path = NULL, *addr2line_path = NULL;
@@ -1551,6 +1552,8 @@ int cmd_top(int argc, const char **argv)
 	OPT_CALLBACK('j', "branch-filter", &opts->branch_stack,
 		     "branch filter mask", "branch stack filter modes",
 		     parse_branch_stack),
+	OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
+		    "add last branch records to call history"),
 	OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
 		    "Show raw trace event output (do not use print fmt or plugins)"),
 	OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
@@ -1677,6 +1680,20 @@ int cmd_top(int argc, const char **argv)
 		goto out_delete_evlist;
 	}
 
+	if (branch_call_mode) {
+		if (!opts->branch_stack)
+			opts->branch_stack = PERF_SAMPLE_BRANCH_ANY;
+		symbol_conf.use_callchain = true;
+		callchain_param.key = CCKEY_ADDRESS;
+		callchain_param.branch_callstack = true;
+		callchain_param.enabled = true;
+		if (callchain_param.record_mode == CALLCHAIN_NONE)
+			callchain_param.record_mode = CALLCHAIN_FP;
+		callchain_register_param(&callchain_param);
+		if (!sort_order)
+			sort_order = "srcline,symbol,dso";
+	}
+
 	if (opts->branch_stack && callchain_param.enabled)
 		symbol_conf.show_branchflag_count = true;
 
-- 
2.34.1


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

* [PATCH 2/2] perf symbol: Remove unused branch_callstack
  2023-03-30 13:18 [PATCH 0/2] perf top: Add --branch-history option Adrian Hunter
  2023-03-30 13:18 ` [PATCH 1/2] " Adrian Hunter
@ 2023-03-30 13:18 ` Adrian Hunter
  2023-03-30 21:14 ` [PATCH 0/2] perf top: Add --branch-history option Arnaldo Carvalho de Melo
  2 siblings, 0 replies; 6+ messages in thread
From: Adrian Hunter @ 2023-03-30 13:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, Andi Kleen, linux-kernel,
	linux-perf-users

branch_callstack was added by commit 8b7bad58efb7 ("perf callchain: Support
handling complete branch stacks as histograms") but never used.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/symbol_conf.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
index 5accd8e69ad2..f26f81eb8252 100644
--- a/tools/perf/util/symbol_conf.h
+++ b/tools/perf/util/symbol_conf.h
@@ -33,7 +33,6 @@ struct symbol_conf {
 			demangle_kernel,
 			filter_relative,
 			show_hist_headers,
-			branch_callstack,
 			has_filter,
 			show_ref_callgraph,
 			hide_unresolved,
-- 
2.34.1


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

* Re: [PATCH 0/2] perf top: Add --branch-history option
  2023-03-30 13:18 [PATCH 0/2] perf top: Add --branch-history option Adrian Hunter
  2023-03-30 13:18 ` [PATCH 1/2] " Adrian Hunter
  2023-03-30 13:18 ` [PATCH 2/2] perf symbol: Remove unused branch_callstack Adrian Hunter
@ 2023-03-30 21:14 ` Arnaldo Carvalho de Melo
  2023-03-31 14:17   ` Andi Kleen
  2 siblings, 1 reply; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-03-30 21:14 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, Andi Kleen, linux-kernel,
	linux-perf-users

Em Thu, Mar 30, 2023 at 04:18:31PM +0300, Adrian Hunter escreveu:
> Hi
> 
> Here are small patches related to option --branch-history.
> 
> Note, currently --branch-history is broken due to patch
> "perf report: append inlines to non-dwarf callchains" so
> that needs to be reverted / fixed beforehand.

Thanks, applied.

- Arnaldo

 
> 
> Adrian Hunter (2):
>       perf top: Add --branch-history option
>       perf symbol: Remove unused branch_callstack
> 
>  tools/perf/Documentation/perf-top.txt |  4 ++++
>  tools/perf/builtin-top.c              | 17 +++++++++++++++++
>  tools/perf/util/symbol_conf.h         |  1 -
>  3 files changed, 21 insertions(+), 1 deletion(-)
> 
> 
> Regards
> Adrian

-- 

- Arnaldo

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

* Re: [PATCH 0/2] perf top: Add --branch-history option
  2023-03-30 21:14 ` [PATCH 0/2] perf top: Add --branch-history option Arnaldo Carvalho de Melo
@ 2023-03-31 14:17   ` Andi Kleen
  2023-04-03 20:32     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2023-03-31 14:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Adrian Hunter
  Cc: Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel, linux-perf-users


On 3/30/2023 2:14 PM, Arnaldo Carvalho de Melo wrote:
> Em Thu, Mar 30, 2023 at 04:18:31PM +0300, Adrian Hunter escreveu:
>> Hi
>>
>> Here are small patches related to option --branch-history.
>>
>> Note, currently --branch-history is broken due to patch
>> "perf report: append inlines to non-dwarf callchains" so
>> that needs to be reverted / fixed beforehand.
> Thanks, applied.


How about the revert to fix it too?


-Andi



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

* Re: [PATCH 0/2] perf top: Add --branch-history option
  2023-03-31 14:17   ` Andi Kleen
@ 2023-04-03 20:32     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-04-03 20:32 UTC (permalink / raw)
  To: Andi Kleen, Artem Savkov
  Cc: Adrian Hunter, Jiri Olsa, Namhyung Kim, Ian Rogers, linux-kernel,
	linux-perf-users

Em Fri, Mar 31, 2023 at 07:17:08AM -0700, Andi Kleen escreveu:
> 
> On 3/30/2023 2:14 PM, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Mar 30, 2023 at 04:18:31PM +0300, Adrian Hunter escreveu:
> > > Hi
> > > 
> > > Here are small patches related to option --branch-history.
> > > 
> > > Note, currently --branch-history is broken due to patch
> > > "perf report: append inlines to non-dwarf callchains" so
> > > that needs to be reverted / fixed beforehand.
> > Thanks, applied.
> 
> 
> How about the revert to fix it too?

Since there was no discussion on this or a proposal to a fix, I'm
reverting it now.

- Arnaldo

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

end of thread, other threads:[~2023-04-03 20:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 13:18 [PATCH 0/2] perf top: Add --branch-history option Adrian Hunter
2023-03-30 13:18 ` [PATCH 1/2] " Adrian Hunter
2023-03-30 13:18 ` [PATCH 2/2] perf symbol: Remove unused branch_callstack Adrian Hunter
2023-03-30 21:14 ` [PATCH 0/2] perf top: Add --branch-history option Arnaldo Carvalho de Melo
2023-03-31 14:17   ` Andi Kleen
2023-04-03 20:32     ` Arnaldo Carvalho de Melo

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.