All of lore.kernel.org
 help / color / mirror / Atom feed
* Minor improvements for brstackisn
@ 2024-08-02 21:14 Andi Kleen
  2024-08-02 21:14 ` [PATCH 1/2] perf script: Add summary to brstackinsn / brstackdisasm Andi Kleen
  2024-08-02 21:14 ` [PATCH 2/2] perf report: Handle non capstone case for calling perf script Andi Kleen
  0 siblings, 2 replies; 3+ messages in thread
From: Andi Kleen @ 2024-08-02 21:14 UTC (permalink / raw)
  To: linux-perf-users

One bug fix and one minor enhancement.

Note one of the patches will likely conflict with Kan's LBR events
patchkit, but the conflict should be easy to resolve (or I will rebase
if that one goes in first)

-Andi


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

* [PATCH 1/2] perf script: Add summary to brstackinsn / brstackdisasm
  2024-08-02 21:14 Minor improvements for brstackisn Andi Kleen
@ 2024-08-02 21:14 ` Andi Kleen
  2024-08-02 21:14 ` [PATCH 2/2] perf report: Handle non capstone case for calling perf script Andi Kleen
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2024-08-02 21:14 UTC (permalink / raw)
  To: linux-perf-users; +Cc: Andi Kleen

Print the total average IPC and total instructions for the last LBR entry.
This can be useful to quickly estimate if a sample shows problematic
code or not.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-script.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c16224b1fef3..d8646366ac74 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1195,7 +1195,8 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
 			    struct perf_insn *x, u8 *inbuf, int len,
 			    int insn, FILE *fp, int *total_cycles,
 			    struct perf_event_attr *attr,
-			    struct thread *thread)
+			    struct thread *thread,
+			    int total_insn, bool end)
 {
 	int ilen = 0;
 	int printed = fprintf(fp, "\t%016" PRIx64 "\t", ip);
@@ -1227,6 +1228,11 @@ static int ip__fprintf_jump(uint64_t ip, struct branch_entry *en,
 		if (insn)
 			printed += fprintf(fp, " %.2f IPC", (float)insn / en->flags.cycles);
 	}
+	if (end) { 
+		printed += fprintf(fp, " %.2f total-IPC %d total-insns",
+				(float)total_insn / *total_cycles,
+				total_insn);
+	}
 
 	return printed + fprintf(fp, "\n");
 }
@@ -1285,6 +1291,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
 	unsigned off;
 	struct symbol *lastsym = NULL;
 	int total_cycles = 0;
+	int total_insn = 0;
 
 	if (!(br && br->nr))
 		return 0;
@@ -1307,7 +1314,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
 					   x.cpumode, x.cpu, &lastsym, attr, fp);
 		printed += ip__fprintf_jump(entries[nr - 1].from, &entries[nr - 1],
 					    &x, buffer, len, 0, fp, &total_cycles,
-					    attr, thread);
+					    attr, thread, 0, false);
 		if (PRINT_FIELD(SRCCODE))
 			printed += print_srccode(thread, x.cpumode, entries[nr - 1].from);
 	}
@@ -1338,7 +1345,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
 			printed += ip__fprintf_sym(ip, thread, x.cpumode, x.cpu, &lastsym, attr, fp);
 			if (ip == end) {
 				printed += ip__fprintf_jump(ip, &entries[i], &x, buffer + off, len - off, ++insn, fp,
-							    &total_cycles, attr, thread);
+							    &total_cycles, attr, thread, total_insn, i == 0);
 				if (PRINT_FIELD(SRCCODE))
 					printed += print_srccode(thread, x.cpumode, ip);
 				break;
@@ -1346,6 +1353,7 @@ static int perf_sample__fprintf_brstackinsn(struct perf_sample *sample,
 				ilen = 0;
 				printed += fprintf(fp, "\t%016" PRIx64 "\t", ip);
 				printed += any_dump_insn(attr, &x, ip, buffer + off, len - off, &ilen, fp);
+				total_insn++;
 				if (PRINT_FIELD(BRSTACKINSNLEN))
 					printed += fprintf(fp, "\tilen: %d", ilen);
 				printed += fprintf(fp, "\n");
-- 
2.45.2


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

* [PATCH 2/2] perf report: Handle non capstone case for calling perf script
  2024-08-02 21:14 Minor improvements for brstackisn Andi Kleen
  2024-08-02 21:14 ` [PATCH 1/2] perf script: Add summary to brstackinsn / brstackdisasm Andi Kleen
@ 2024-08-02 21:14 ` Andi Kleen
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2024-08-02 21:14 UTC (permalink / raw)
  To: linux-perf-users; +Cc: Andi Kleen

When perf is built without capstone trying to displaying assembler
sample context would error out. Use the older --xed variant in this
case.

Fixes: 659663f0bccc ("perf: script: prefer capstone to XED")
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/ui/browsers/scripts.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
index e437d7889de6..b130a92053db 100644
--- a/tools/perf/ui/browsers/scripts.c
+++ b/tools/perf/ui/browsers/scripts.c
@@ -107,8 +107,13 @@ static int list_scripts(char *script_name, bool *custom,
 	if (evsel)
 		attr_to_script(scriptc.extra_format, &evsel->core.attr);
 	add_script_option("Show individual samples", "", &scriptc);
+#ifdef NO_CAPSTONE
+	add_script_option("Show individual samples with assembler", "-F +insn --xed",
+			  &scriptc);
+#else
 	add_script_option("Show individual samples with assembler", "-F +disasm",
 			  &scriptc);
+#endif
 	add_script_option("Show individual samples with source", "-F +srcline,+srccode",
 			  &scriptc);
 	perf_config(scripts_config, &scriptc);
-- 
2.45.2


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

end of thread, other threads:[~2024-08-02 21:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 21:14 Minor improvements for brstackisn Andi Kleen
2024-08-02 21:14 ` [PATCH 1/2] perf script: Add summary to brstackinsn / brstackdisasm Andi Kleen
2024-08-02 21:14 ` [PATCH 2/2] perf report: Handle non capstone case for calling perf script Andi Kleen

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.