From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0AB2ECAAA1 for ; Fri, 9 Sep 2022 08:57:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230435AbiIII5U (ORCPT ); Fri, 9 Sep 2022 04:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbiIII4u (ORCPT ); Fri, 9 Sep 2022 04:56:50 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45F521377B4; Fri, 9 Sep 2022 01:55:31 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MP8qY38KyzmVBb; Fri, 9 Sep 2022 16:51:37 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 16:55:14 +0800 From: Changbin Du To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , , , Hui Wang , , Changbin Du Subject: [PATCH 0/3] perf: script: use capstone to show disassembly instructions for samples Date: Fri, 9 Sep 2022 16:48:18 +0800 Message-ID: <20220909084821.7894-1-changbin.du@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Currently, the instructions of samples are shown as raw hex strings which are hard to read. x86 has a special option '--xed' to disassemble the hex string via intel XED. Here we use capstone as our disassembly engine to do that. We select libcapstone because capstone can provide more insn details. The improvements compared to xed: * support arm, arm64, x86-32, x86_64 (more could be supported), xed only for x86_64. * immediate address operands are shown as symbol+offs. Before: $ sudo perf script --insn-trace perf 17423 [000] 423271.557970005: 7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 48 3d 01 f0 ff ff perf 17423 [000] 423271.557970005: 7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so) insn: 73 01 perf 17423 [000] 423271.557970338: 7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so) insn: c3 perf 17423 [000] 423271.557970338: 5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf) insn: 85 c0 perf 17423 [000] 423271.557970338: 5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf) insn: 75 12 perf 17423 [000] 423271.557970338: 5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf) insn: 49 8b 84 24 a8 00 00 00 perf 17423 [000] 423271.557970338: 5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf) insn: 48 8b 50 20 After: $ sudo perf script --insn-trace perf 17423 [000] 423271.557970005: 7f2d95f16217 __GI___ioctl+0x7 (/lib/x86_64-linux-gnu/libc-2.27.so) insn: cmpq $-0xfff, %rax perf 17423 [000] 423271.557970005: 7f2d95f1621d __GI___ioctl+0xd (/lib/x86_64-linux-gnu/libc-2.27.so) insn: jae __GI___ioctl+0x10 perf 17423 [000] 423271.557970338: 7f2d95f1621f __GI___ioctl+0xf (/lib/x86_64-linux-gnu/libc-2.27.so) insn: retq perf 17423 [000] 423271.557970338: 5593ad3346d7 perf_evsel__enable_cpu+0x97 (/work/linux/tools/perf/perf) insn: testl %eax, %eax perf 17423 [000] 423271.557970338: 5593ad3346d9 perf_evsel__enable_cpu+0x99 (/work/linux/tools/perf/perf) insn: jne perf_evsel__enable_cpu+0xad perf 17423 [000] 423271.557970338: 5593ad3346db perf_evsel__enable_cpu+0x9b (/work/linux/tools/perf/perf) insn: movq 0xa8(%r12), %rax perf 17423 [000] 423271.557970338: 5593ad3346e3 perf_evsel__enable_cpu+0xa3 (/work/linux/tools/perf/perf) insn: movq 0x20(%rax), %rdx perf 17423 [000] 423271.557970338: 5593ad3346e7 perf_evsel__enable_cpu+0xa7 (/work/linux/tools/perf/perf) insn: cmpl %edx, %ebx Changbin Du (3): perf: build: introduce the libcapstone perf: script: use capstone disasm engine to show disassembly instructions perf: script: Deprecate the '--xed' option tools/build/Makefile.feature | 2 + tools/build/feature/Makefile | 4 + tools/build/feature/test-all.c | 4 + tools/build/feature/test-libcapstone.c | 11 ++ tools/perf/Documentation/build-xed.txt | 19 ---- tools/perf/Documentation/perf-intel-pt.txt | 17 +-- tools/perf/Documentation/perf-script.txt | 5 +- tools/perf/Documentation/tips.txt | 2 +- tools/perf/Makefile.config | 21 ++++ tools/perf/Makefile.perf | 3 + tools/perf/builtin-script.c | 15 +-- tools/perf/ui/browsers/res_sample.c | 2 +- tools/perf/ui/browsers/scripts.c | 4 +- tools/perf/util/Build | 1 + tools/perf/util/print_insn.c | 126 +++++++++++++++++++++ tools/perf/util/print_insn.h | 13 +++ 16 files changed, 201 insertions(+), 48 deletions(-) create mode 100644 tools/build/feature/test-libcapstone.c delete mode 100644 tools/perf/Documentation/build-xed.txt create mode 100644 tools/perf/util/print_insn.c create mode 100644 tools/perf/util/print_insn.h -- 2.17.1