From: duchangbin <changbin.du@huawei.com>
To: Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
Kan Liang <kan.liang@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"linux-perf-users@vger.kernel.org"
<linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH 4/4] perf annotate: Use libcapstone to disassemble
Date: Fri, 29 Mar 2024 02:53:34 +0000 [thread overview]
Message-ID: <9492dc44260c40598d1b282975eb9a4a@huawei.com> (raw)
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 <changbin.du@huawei.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> 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 <ctype.h>
> #include <errno.h>
> +#include <fcntl.h>
> #include <inttypes.h>
> #include <libgen.h>
> #include <regex.h>
> @@ -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 <capstone/capstone.h>
> +
> +static int open_capstone_handle(struct annotate_args *args, bool is_64bit,
> + csh *handle)
> +{
> + struct annotation_options *opt = args->options;
> + cs_mode mode = 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) != 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
next reply other threads:[~2024-03-29 2:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 2:53 duchangbin [this message]
2024-03-29 20:00 ` [PATCH 4/4] perf annotate: Use libcapstone to disassemble Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2024-03-28 23:20 [PATCH 0/4] perf annotate: Use libcapstone as a disasssembler Namhyung Kim
2024-03-28 23:20 ` [PATCH 4/4] perf annotate: Use libcapstone to disassemble Namhyung Kim
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=9492dc44260c40598d1b282975eb9a4a@huawei.com \
--to=changbin.du@huawei.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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