From nobody Thu Dec 18 11:44:32 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7D237493; Wed, 17 Jan 2024 05:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705468365; cv=none; b=M1uuHvXIcq3FUQbo/5dvu0axG0aaVvDNUpLUMAVVpZT32gJkymsvthqJU8ECN7c7fvlqcnvNex5ly0Z+0XHNYm6SIniIL2903b8weYxYDs3Mo47D5w+ncH0vfat0B3AoTgqxHpigU7b4ikpGvF1NaCuHfDS9cmDpHEHUb5sg9IU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705468365; c=relaxed/simple; bh=eyG3Q8jP0jD/ZXUqfb96W86KdrzkpPnLcXYTzTNaYt8=; h=Received:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; b=VSfqJBNeMA15OPp6jB2XGNmZgOqrRdn6fYq8wpRfGVLPDbTUnnFViMACd+Y5VZVXoMWl6R694rR5qzEcdf9c2uJ1UbYq9Z1yXAieu1G08Q1OCUoFFIXLVdRC4E9Wp+kf4U+vsVL3sPX2bwA4PdmyDySKNE5A0SSiNB7Qe6vn7yM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TFDWH0F3MzSpWw; Wed, 17 Jan 2024 13:11:39 +0800 (CST) Received: from kwepemd100002.china.huawei.com (unknown [7.221.188.184]) by mail.maildlp.com (Postfix) with ESMTPS id 74D321400D4; Wed, 17 Jan 2024 13:12:25 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100002.china.huawei.com (7.221.188.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Wed, 17 Jan 2024 13:11:28 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Andi Kleen , Thomas Richter , , Changbin Du Subject: [PATCH v2 4/5] perf: script: add raw|disam arguments to --insn-trace option Date: Wed, 17 Jan 2024 13:11:03 +0800 Message-ID: <20240117051104.2147643-5-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117051104.2147643-1-changbin.du@huawei.com> References: <20240117051104.2147643-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd100002.china.huawei.com (7.221.188.184) Content-Type: text/plain; charset="utf-8" Now '--insn-trace' accept a argument to specify the output format: - raw: display raw instructions. - disam: display mnemonic instructions (if capstone is installed). $ sudo perf script --insn-trace=3Draw ls 1443864 [006] 2275506.209908875: 7f216b426100 _start+= 0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: 48 89 e7 ls 1443864 [006] 2275506.209908875: 7f216b426103 _start+= 0x3 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: e8 e8 0c 00 00 ls 1443864 [006] 2275506.209908875: 7f216b426df0 _dl_sta= rt+0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: f3 0f 1e fa $ sudo perf script --insn-trace=3Ddisam ls 1443864 [006] 2275506.209908875: 7f216b426100 _start+= 0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: movq %rsp, %rdi ls 1443864 [006] 2275506.209908875: 7f216b426103 _start+= 0x3 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: callq _dl_start+0x0 ls 1443864 [006] 2275506.209908875: 7f216b426df0 _dl_sta= rt+0x0 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: illegal instruction ls 1443864 [006] 2275506.209908875: 7f216b426df4 _dl_sta= rt+0x4 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: pushq %rbp ls 1443864 [006] 2275506.209908875: 7f216b426df5 _dl_sta= rt+0x5 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: movq %rsp, %rbp ls 1443864 [006] 2275506.209908875: 7f216b426df8 _dl_sta= rt+0x8 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) insn: pushq %r15 Signed-off-by: Changbin Du --- tools/perf/Documentation/perf-script.txt | 6 +++--- tools/perf/builtin-script.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Document= ation/perf-script.txt index 1b0b62dd3145..7061f607709c 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -442,9 +442,9 @@ include::itrace.txt[] will be printed. Each entry has function name and file/line. Enabled by default, disable with --no-inline. =20 ---insn-trace:: - Show instruction stream for intel_pt traces. Combine with --xed to - show disassembly. +--insn-trace[=3D]:: + Show raw or mnemonic instruction stream for intel_pt traces. You can + also combine raw instructions with --xed to show disassembly. =20 --xed:: Run xed disassembler on output. Requires installing the xed disassembler. diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 33f7dff6d066..01c83e45def1 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3769,10 +3769,19 @@ static int perf_script__process_auxtrace_info(struc= t perf_session *session, #endif =20 static int parse_insn_trace(const struct option *opt __maybe_unused, - const char *str __maybe_unused, - int unset __maybe_unused) + const char *str, int unset __maybe_unused) { - parse_output_fields(NULL, "+insn,-event,-period", 0); + const char *fields =3D "+insn,-event,-period"; + + if (str) { + if (strcmp(str, "disam") =3D=3D 0) + fields =3D "+insn_disam,-event,-period"; + else if (strlen(str) !=3D 0 && strcmp(str, "raw") !=3D 0) { + fprintf(stderr, "Only accept raw|disam\n"); + return -EINVAL; + } + } + parse_output_fields(NULL, fields, 0); itrace_parse_synth_opts(opt, "i0ns", 0); symbol_conf.nanosecs =3D true; return 0; @@ -3918,7 +3927,7 @@ int cmd_script(int argc, const char **argv) "only consider these symbols"), OPT_INTEGER(0, "addr-range", &symbol_conf.addr_range, "Use with -S to list traced records within address range"), - OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, NULL, + OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, "raw|disam= ", "Decode instructions from itrace", parse_insn_trace), OPT_CALLBACK_OPTARG(0, "xed", NULL, NULL, NULL, "Run xed disassembler on output", parse_xed), --=20 2.25.1