All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 21/25] perf scripts python: intel-pt-events.py: Add Event Trace
Date: Mon, 24 Jan 2022 10:41:57 +0200	[thread overview]
Message-ID: <20220124084201.2699795-22-adrian.hunter@intel.com> (raw)
In-Reply-To: <20220124084201.2699795-1-adrian.hunter@intel.com>

Add Event Trace to the intel-pt-events.py script. This shows how to unpack
the raw data from the new sample events in a Python script.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/scripts/python/intel-pt-events.py | 55 ++++++++++++++++++--
 1 file changed, 50 insertions(+), 5 deletions(-)

diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
index 66452a8ec358..973bd12b7b40 100644
--- a/tools/perf/scripts/python/intel-pt-events.py
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -76,16 +76,16 @@ def trace_begin():
 	glb_args = ap.parse_args()
 	if glb_args.insn_trace:
 		print("Intel PT Instruction Trace")
-		itrace = "i0nsepwx"
+		itrace = "i0nsepwxI"
 		glb_insn = True
 	elif glb_args.src_trace:
 		print("Intel PT Source Trace")
-		itrace = "i0nsepwx"
+		itrace = "i0nsepwxI"
 		glb_insn = True
 		glb_src = True
 	else:
-		print("Intel PT Branch Trace, Power Events and PTWRITE")
-		itrace = "bepwx"
+		print("Intel PT Branch Trace, Power Events, Event Trace and PTWRITE")
+		itrace = "bepwxI"
 	global glb_disassembler
 	try:
 		glb_disassembler = LibXED()
@@ -149,6 +149,43 @@ def print_psb(raw_buf):
 	offset = data[1]
 	print("offset: %#x" % (offset), end=' ')
 
+glb_cfe = ["", "INTR", "IRET", "SMI", "RSM", "SIPI", "INIT", "VMENTRY", "VMEXIT",
+		"VMEXIT_INTR", "SHUTDOWN", "", "UINT", "UIRET"] + [""] * 18
+glb_evd = ["", "PFA", "VMXQ", "VMXR"] + [""] * 60
+
+def print_evt(raw_buf):
+	data = struct.unpack_from("<BBH", raw_buf)
+	typ = data[0] & 0x1f
+	ip_flag = (data[0] & 0x80) >> 7
+	vector = data[1]
+	evd_cnt = data[2]
+	s = glb_cfe[typ]
+	if s:
+		print(" cfe: %s IP: %u vector: %u" % (s, ip_flag, vector), end=' ')
+	else:
+		print(" cfe: %u IP: %u vector: %u" % (typ, ip_flag, vector), end=' ')
+	pos = 4
+	for i in range(evd_cnt):
+		data = struct.unpack_from("<QQ", raw_buf)
+		et = data[0] & 0x3f
+		s = glb_evd[et]
+		if s:
+			print("%s: %#x" % (s, data[1]), end=' ')
+		else:
+			print("EVD_%u: %#x" % (et, data[1]), end=' ')
+
+def print_iflag(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	iflag = data[0] & 1
+	old_iflag = iflag ^ 1
+	via_branch = data[0] & 2
+	branch_ip = data[1]
+	if via_branch:
+		s = "via"
+	else:
+		s = "non"
+	print("IFLAG: %u->%u %s branch" % (old_iflag, iflag, s), end=' ')
+
 def common_start_str(comm, sample):
 	ts = sample["time"]
 	cpu = sample["cpu"]
@@ -164,7 +201,7 @@ def print_common_start(comm, sample, name):
 	# weight      = sample["weight"]
 	# transaction = sample["transaction"]
 	# cpumode     = get_optional_zero(sample, "cpumode")
-	print(common_start_str(comm, sample) + "%7s  %19s" % (name, flags_disp), end=' ')
+	print(common_start_str(comm, sample) + "%8s  %21s" % (name, flags_disp), end=' ')
 
 def print_instructions_start(comm, sample):
 	if "x" in get_optional_null(sample, "flags"):
@@ -315,6 +352,14 @@ def do_process_event(param_dict):
 		print_common_start(comm, sample, name)
 		print_psb(raw_buf)
 		print_common_ip(param_dict, sample, symbol, dso)
+	elif name == "evt":
+		print_common_start(comm, sample, name)
+		print_evt(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
+	elif name == "iflag":
+		print_common_start(comm, sample, name)
+		print_iflag(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	else:
 		print_common_start(comm, sample, name)
 		print_common_ip(param_dict, sample, symbol, dso)
-- 
2.25.1


  parent reply	other threads:[~2022-01-24  8:43 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24  8:41 [PATCH 00/25] perf intel-pt: Add support for Event Trace and TNT disable Adrian Hunter
2022-01-24  8:41 ` [PATCH 01/25] perf intel-pt: pkt-decoder-test: Fix scope of test_data Adrian Hunter
2022-01-24  8:41 ` [PATCH 02/25] perf intel-pt: pkt-decoder: Remove misplaced linebreak Adrian Hunter
2022-01-24  8:41 ` [PATCH 03/25] perf intel-pt: pkt-decoder: Add CFE and EVD packets Adrian Hunter
2022-01-24  8:41 ` [PATCH 04/25] perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit Adrian Hunter
2022-01-24  8:41 ` [PATCH 05/25] perf intel-pt: decoder: Add config bit definitions Adrian Hunter
2022-01-24  8:41 ` [PATCH 06/25] perf intel-pt: decoder: Factor out clearing of FUP event variables Adrian Hunter
2022-01-24  8:41 ` [PATCH 07/25] perf intel-pt: decoder: Add CFE and EVD processing Adrian Hunter
2022-01-24  8:41 ` [PATCH 08/25] perf intel-pt: decoder: Add MODE.Exec IFLAG processing Adrian Hunter
2022-01-24  8:41 ` [PATCH 09/25] perf tools: Define Intel PT CFE / EVD event Adrian Hunter
2022-01-24  8:41 ` [PATCH 10/25] perf tools: Define Intel PT iflag synthesized event Adrian Hunter
2022-01-24  8:41 ` [PATCH 11/25] perf tools: Define new D and t flags Adrian Hunter
2022-01-24  8:41 ` [PATCH 12/25] perf auxtrace: Add itrace option "I" Adrian Hunter
2022-01-24  8:41 ` [PATCH 13/25] perf intel-pt: Record Event Trace capability flag Adrian Hunter
2022-01-24  8:41 ` [PATCH 14/25] perf intel-pt: Synthesize CFE / EVD event Adrian Hunter
2022-01-24  8:41 ` [PATCH 15/25] perf intel-pt: Synthesize iflag event Adrian Hunter
2022-01-24  8:41 ` [PATCH 16/25] perf intel-pt: Synthesize new D and t flags Adrian Hunter
2022-01-24  8:41 ` [PATCH 17/25] perf intel-pt: Force 'quick' mode when TNT is disabled Adrian Hunter
2022-01-24  8:41 ` [PATCH 18/25] perf script: Display Intel PT CFE / EVD synthesized event Adrian Hunter
2022-01-24  8:41 ` [PATCH 19/25] perf script: Display Intel PT iflag " Adrian Hunter
2022-01-24  8:41 ` [PATCH 20/25] perf script: Display new D and t flags Adrian Hunter
2022-01-24  8:41 ` Adrian Hunter [this message]
2022-01-24  8:41 ` [PATCH 22/25] perf scripting python: Add all sample flags to DB export Adrian Hunter
2022-01-24  8:41 ` [PATCH 23/25] perf scripts python: export-to-sqlite.py: Export all sample flags Adrian Hunter
2022-01-24  8:42 ` [PATCH 24/25] perf scripts python: export-to-postgresql.py: " Adrian Hunter
2022-01-24  8:42 ` [PATCH 25/25] perf intel-pt: Add documentation for Event Trace and TNT disable Adrian Hunter
2022-02-15 14:27 ` [PATCH 00/25] perf intel-pt: Add support " Arnaldo Carvalho de Melo
2022-02-15 19:39   ` Arnaldo Carvalho de Melo
2022-02-16  6:12     ` Adrian Hunter
2022-02-16  9:46       ` Arnaldo Carvalho de Melo

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=20220124084201.2699795-22-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.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 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.