mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@kernel.org, mhiramat@kernel.org, adrian.hunter@intel.com,
	linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 02/12] perf, tools, script: Print insn/insnlen for non PT sample
Date: Mon, 27 Nov 2017 16:23:11 -0800	[thread overview]
Message-ID: <20171128002321.2878-3-andi@firstfloor.org> (raw)
In-Reply-To: <20171128002321.2878-1-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

Dumping insn/insnlen only works for PT samples where the PT decoder
fills in these fields. Add a fallback for other samples where we
grab the instructions manually and then call an architecture
specific function to determine the instruction length.

The architecture specific function is currently only implemented
for x86, and uses the standard Linux instruction decoder.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/arch/x86/util/Build     |  1 +
 tools/perf/arch/x86/util/insnlen.c | 12 ++++++++++++
 tools/perf/builtin-script.c        | 13 +++++++++++++
 tools/perf/util/Build              |  1 +
 tools/perf/util/insnlen.c          | 10 ++++++++++
 tools/perf/util/insnlen.h          |  6 ++++++
 6 files changed, 43 insertions(+)
 create mode 100644 tools/perf/arch/x86/util/insnlen.c
 create mode 100644 tools/perf/util/insnlen.c
 create mode 100644 tools/perf/util/insnlen.h

diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
index f95e6f46ef0d..139f9f1a56f9 100644
--- a/tools/perf/arch/x86/util/Build
+++ b/tools/perf/arch/x86/util/Build
@@ -1,6 +1,7 @@
 libperf-y += header.o
 libperf-y += tsc.o
 libperf-y += pmu.o
+libperf-y += insnlen.o
 libperf-y += kvm-stat.o
 libperf-y += perf_regs.o
 libperf-y += group.o
diff --git a/tools/perf/arch/x86/util/insnlen.c b/tools/perf/arch/x86/util/insnlen.c
new file mode 100644
index 000000000000..8e2e50bd5201
--- /dev/null
+++ b/tools/perf/arch/x86/util/insnlen.c
@@ -0,0 +1,12 @@
+#include "intel-pt-decoder/insn.h"
+#include "intel-pt-decoder/inat.h"
+#include "insnlen.h"
+
+int arch_insn_len(char *insnbytes, int insnlen, int is64bit)
+{
+	struct insn insn;
+
+	insn_init(&insn, insnbytes, insnlen, is64bit);
+	insn_get_length(&insn);
+	return insn.length;
+}
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index ee7c7aaaae72..cae4b13fc715 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -20,6 +20,7 @@
 #include "util/data.h"
 #include "util/auxtrace.h"
 #include "util/cpumap.h"
+#include "util/insnlen.h"
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include "util/string2.h"
@@ -1108,6 +1109,18 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample,
 {
 	int printed = 0;
 
+	if ((PRINT_FIELD(INSNLEN) || PRINT_FIELD(INSN)) && !sample->insn_len) {
+		u8 ibuf[64];
+		bool is64bit;
+		u8 cpumode;
+
+		if (grab_bb(ibuf, sample->ip, sample->ip + 16,
+			    machine, thread, &is64bit, &cpumode, false) > 0) {
+			sample->insn_len = arch_insn_len((char *)ibuf, 16, is64bit);
+			memcpy(sample->insn, ibuf, sample->insn_len);
+		}
+	}
+
 	if (PRINT_FIELD(INSNLEN))
 		printed += fprintf(fp, " ilen: %d", sample->insn_len);
 	if (PRINT_FIELD(INSN)) {
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index a3de7916fe63..80c05329835a 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -14,6 +14,7 @@ libperf-y += kallsyms.o
 libperf-y += levenshtein.o
 libperf-y += llvm-utils.o
 libperf-y += mmap.o
+libperf-y += insnlen.o
 libperf-y += memswap.o
 libperf-y += parse-events.o
 libperf-y += perf_regs.o
diff --git a/tools/perf/util/insnlen.c b/tools/perf/util/insnlen.c
new file mode 100644
index 000000000000..6c126960a7e6
--- /dev/null
+++ b/tools/perf/util/insnlen.c
@@ -0,0 +1,10 @@
+#include "perf.h"
+#include "insnlen.h"
+
+/* Fallback for architectures not supporting this */
+__weak int arch_insn_len(char *buf __maybe_unused,
+			 int len __maybe_unused,
+			 int is64bit __maybe_unused)
+{
+	return 0;
+}
diff --git a/tools/perf/util/insnlen.h b/tools/perf/util/insnlen.h
new file mode 100644
index 000000000000..289877dff89d
--- /dev/null
+++ b/tools/perf/util/insnlen.h
@@ -0,0 +1,6 @@
+#ifndef INSNLEN_H
+#define INSNLEN_H 1
+
+int arch_insn_len(char *buf, int len, int is64bit);
+
+#endif
-- 
2.13.6

  parent reply	other threads:[~2017-11-28  0:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28  0:23 Implement dwarf variable/type resolving for perf script Andi Kleen
2017-11-28  0:23 ` [PATCH 01/12] perf, tools, pt: Clear instruction for ptwrite samples Andi Kleen
2017-11-28  0:23 ` Andi Kleen [this message]
2017-11-28  0:23 ` [PATCH 03/12] perf, tools: Support storing additional data in strlist Andi Kleen
2017-11-28 13:31   ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 04/12] perf, tools: Store variable name and register for dwarf variable lists Andi Kleen
2017-11-28  0:23 ` [PATCH 05/12] perf, tools, probe: Print location for resolved variables Andi Kleen
2017-11-29  1:19   ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 06/12] perf, tools, probe: Support a quiet argument for debug info open Andi Kleen
2017-11-29  3:14   ` Masami Hiramatsu
2017-11-29  3:39     ` Andi Kleen
2017-11-30  2:36       ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 07/12] perf, tools, script: Resolve variable names for registers Andi Kleen
2017-11-28  0:23 ` [PATCH 08/12] perf, tools: Always print probe finder warnings with -v Andi Kleen
2017-11-29  3:16   ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 09/12] perf, tools: Downgrade register mapping message to warning Andi Kleen
2017-11-29  5:56   ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 10/12] perf, tools: Add args and gprs shortcut for registers Andi Kleen
2017-11-28  0:23 ` [PATCH 11/12] perf, tools: Print probe warnings for binaries only once per binary Andi Kleen
2017-11-30  2:38   ` Masami Hiramatsu
2017-11-28  0:23 ` [PATCH 12/12] perf, tools, script: Implement dwarf resolving of instructions Andi Kleen
2017-12-01  2:36   ` Masami Hiramatsu
2017-11-28  5:31 ` Implement dwarf variable/type resolving for perf script Masami Hiramatsu

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=20171128002321.2878-3-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@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