Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp836774lqh; Thu, 28 Mar 2024 19:53:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXZzozq8bRv9TJ/VCbiMu9bQQ+9wugIMCEERaOqwxWAlsYoJ9pRHXrVkpuEF3oBzkQ6lhQxMF6Q558KXHPZllb4lOZR+echIzRTdH952g== X-Google-Smtp-Source: AGHT+IF/XnJs8CqtWeiDdjCJRi9I4uf+mJ5+jzk8gRc7WjdtqYYcpZvv41LNh5647S17ntacLTWy X-Received: by 2002:a05:6358:5488:b0:183:40f2:4bd6 with SMTP id v8-20020a056358548800b0018340f24bd6mr1360271rwe.0.1711680828615; Thu, 28 Mar 2024 19:53:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711680828; cv=pass; d=google.com; s=arc-20160816; b=uIDEAQ/JbNpZIyi5QF1s/Sg3gUkO4A1IhBvLVFnJIuehhu+xUbE+K6v7E3n/gI9xnZ W/OdzUC5qgF2a4Wpo6vOoRJinLwAu0SEsSOdXKww5YnezPKaElC33wQLDQ+daJIoFYoB glHldc6SU0UFKtcWjQnFOKfshM/R2CnB8wzm28ps72l5O0wRwoSGv5bQUz4dYa9CuMjj n8oswd8mFc0RSFBWrP0lsTdgWkbAuB8XHEyO4BWYGyLxWjoDlhd/fP5hDIdgXU7uf2A4 ZUylAyMzEBS8IAEXw1MnvYhotTnOZxspB+H6Ai67ZLmYW948ngFDFVl2b3ZPBYCChHCQ BbqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-language:accept-language :message-id:date:thread-index:thread-topic:subject:cc:to:from; bh=PSk2popo2tiP/ceGmw4660BjLQBkBgupZXDu4AphhfU=; fh=DOsSQPpeD8Lp+Wz5PMGym96QJn8Fls047qIJ5KuXDCA=; b=07wkyv/kUTBLuEhlSmxvCTr9o7/kTP2QGcFxwOp3gR/b0brAYXo7zZiH0BP7RSGQKA xH8WhSDY4siqNsroZiz5G4aqieMY4MYc3UpJCINLgm57V6P+KqXq0Iov9pUt+9EKZPnn qNwXQlBrtKtXJ3U3wlDfzB5EKDEyUXB57LDXHPvSkyK4554GWhzL+HJbyqKc//BADbOS T3qU+PwAzyxqyirvNyxTzsAum/2pvcb1MwhfuDrjwSn/oIH+KI6IwEkxVAjnu5LUp8CT 5w799lCjPPAIPam4uGNnRkIvHKrpTcD0cf4b2DL8igwsZE+Bumke5IFc2jvOobPIyAcQ tzHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-124068-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124068-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t15-20020a63954f000000b005d6c2958481si2785127pgn.639.2024.03.28.19.53.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 19:53:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124068-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-124068-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124068-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3D453289657 for ; Fri, 29 Mar 2024 02:53:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9894B37160; Fri, 29 Mar 2024 02:53:41 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 D7DD8629; Fri, 29 Mar 2024 02:53:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711680821; cv=none; b=ix89yKOaSGhPEBppx73VW7rABjCWKdgaZZrX/PssqGKfD89PmlepDWcwcKluKUS3JZ0AzRVlKYVcIm605JkgdmrMnsfDZgmT84D4w2OdNUFY8xG+U+6FPdZuOPa9XmOSjAml8tz7nbQJVptRaCmMn4EsdmqgqseStTnaHi0sNGY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711680821; c=relaxed/simple; bh=cLVUA/Dq+r+L9fmpbcFS4ppyU7J6eSvTew0CqZL202k=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=h+FDxC4rkBQtEAJ8Hr8UxeNQfKHYdl/rQPrSrUPH9rKbcRQ2L0YziZyI6wGoahntR0ulQ9/d54FrTmDPyeP/K6h7wi5ZlKKYreCGhv2jXbGbmrApyDua9BdtahycQk9cQsvnjaLXEYcZQrBkzbUk90M+5nTkpsgyhW8vXmYxlvU= 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.190 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.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4V5Q0P05PQz1xtM9; Fri, 29 Mar 2024 10:51:33 +0800 (CST) Received: from kwepemd200010.china.huawei.com (unknown [7.221.188.124]) by mail.maildlp.com (Postfix) with ESMTPS id 45B1F18001A; Fri, 29 Mar 2024 10:53:35 +0800 (CST) Received: from kwepemd100011.china.huawei.com (7.221.188.204) by kwepemd200010.china.huawei.com (7.221.188.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Fri, 29 Mar 2024 10:53:34 +0800 Received: from kwepemd100011.china.huawei.com ([7.221.188.204]) by kwepemd100011.china.huawei.com ([7.221.188.204]) with mapi id 15.02.1258.028; Fri, 29 Mar 2024 10:53:34 +0800 From: duchangbin To: Namhyung Kim , Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang CC: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , "linux-perf-users@vger.kernel.org" Subject: Re: [PATCH 4/4] perf annotate: Use libcapstone to disassemble Thread-Topic: [PATCH 4/4] perf annotate: Use libcapstone to disassemble Thread-Index: AdqBhEXN5g0vMGErl0mxS52m6D0zyA== Date: Fri, 29 Mar 2024 02:53:34 +0000 Message-ID: <9492dc44260c40598d1b282975eb9a4a@huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi, Namhyung, On Thu, Mar 28, 2024 at 04:20:09PM -0700, Namhyung Kim wrote: > Now it can use the capstone library to disassemble the instructions. > Let's use that (if available) for perf annotate to speed up. Currently > it only supports x86 architecture. With this change I can see ~3x speed > up in data type profiling. > > But note that capstone cannot give the source file and line number info. > For now, users should use the external objdump for that by specifying > the --objdump option explicitly. > > Cc: Changbin Du > Signed-off-by: Namhyung Kim > --- > tools/perf/util/disasm.c | 153 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 153 insertions(+) > > diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c > index 59ac37723990..c58ea6d822ed 100644 > --- a/tools/perf/util/disasm.c > +++ b/tools/perf/util/disasm.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0-only > #include > #include > +#include > #include > #include > #include > @@ -18,6 +19,7 @@ > #include "evsel.h" > #include "map.h" > #include "maps.h" > +#include "namespaces.h" > #include "srcline.h" > #include "symbol.h" > > @@ -1341,6 +1343,151 @@ symbol__disassemble_bpf_image(struct symbol *sym, > return 0; > } > > +#ifdef HAVE_LIBCAPSTONE_SUPPORT > +#include > + > +static int open_capstone_handle(struct annotate_args *args, bool is_64bi= t, > + csh *handle) > +{ > + struct annotation_options *opt =3D args->options; > + cs_mode mode =3D is_64bit ? CS_MODE_64 : CS_MODE_32; > + > + /* TODO: support more architectures */ > + if (!arch__is(args->arch, "x86")) > + return -1; > + > + if (cs_open(CS_ARCH_X86, mode, handle) !=3D CS_ERR_OK) > + return -1; > + > + if (!opt->disassembler_style || > + !strcmp(opt->disassembler_style, "att")) > + cs_option(*handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); > + > + /* > + * Resolving address operands to symbols is implemented > + * on x86 by investigating instruction details. > + */ > + cs_option(*handle, CS_OPT_DETAIL, CS_OPT_ON); Enabling CS_OPT_DETAIL is to symbolize branch target address. You can refer= to print_insn_x86() in print_insn.c. > + > + return 0; > +} > + -- Cheers, Changbin Du