From nobody Thu Dec 18 18:50:15 2025 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 B0417C77B73 for ; Fri, 14 Apr 2023 03:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbjDND0N (ORCPT ); Thu, 13 Apr 2023 23:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjDND0K (ORCPT ); Thu, 13 Apr 2023 23:26:10 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AD083AAD; Thu, 13 Apr 2023 20:26:08 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PyMFC2bD3zSsB3; Fri, 14 Apr 2023 11:22:07 +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.2507.23; Fri, 14 Apr 2023 11:26:05 +0800 From: Changbin Du To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v4 1/2] perf script: print raw ip instead of binary offset for callchain Date: Fri, 14 Apr 2023 11:25:46 +0800 Message-ID: <20230414032547.2767909-2-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414032547.2767909-1-changbin.du@huawei.com> References: <20230414032547.2767909-1-changbin.du@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Before this, the raw ip is printed for non-callchain and dso offset for callchain. This inconsistent output for address may confuse people. And mostly what we expect is the raw ip. 'dso offset' is printed in callchain: $ perf script ... ls 1341034 2739463.008343: 2162417 cycles: ffffffff99d657a7 [unknown] ([unknown]) ffffffff99e00b67 [unknown] ([unknown]) 235d3 memset+0x53 (/usr/lib/x86_64-linux-gnu/ld-2.31.so)= # dso offset a61b _dl_map_object+0x1bb (/usr/lib/x86_64-linux-gnu/ld= -2.31.so) raw ip is printed for non-callchain: $ perf script -G ... ls 1341034 2739463.008876: 2053304 cycles: ffffffffc1596923 [un= known] ([unknown]) ls 1341034 2739463.009381: 1917049 cycles: 14def8e149e6 __s= trcoll_l+0xd96 (/usr/lib/x86_64-linux-gnu/libc-2.31.so) # raw ip Let's have consistent output for it. Later I'll add a new field 'dsoff' to print dso offset. Signed-off-by: Changbin Du --- tools/perf/util/evsel_fprintf.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprint= f.c index bd22c4932d10..1fb8044d402e 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -153,13 +153,8 @@ int sample__fprintf_callchain(struct perf_sample *samp= le, int left_alignment, if (map) addr =3D map->map_ip(map, node->ip); =20 - if (print_ip) { - /* Show binary offset for userspace addr */ - if (map && !map->dso->kernel) - printed +=3D fprintf(fp, "%c%16" PRIx64, s, addr); - else - printed +=3D fprintf(fp, "%c%16" PRIx64, s, node->ip); - } + if (print_ip) + printed +=3D fprintf(fp, "%c%16" PRIx64, s, node->ip); =20 if (print_sym) { printed +=3D fprintf(fp, " "); --=20 2.25.1 From nobody Thu Dec 18 18:50:15 2025 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 D0882C77B70 for ; Fri, 14 Apr 2023 03:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbjDND0T (ORCPT ); Thu, 13 Apr 2023 23:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjDND0L (ORCPT ); Thu, 13 Apr 2023 23:26:11 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 321FC2D78; Thu, 13 Apr 2023 20:26:09 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PyMJB3CHYzrZqr; Fri, 14 Apr 2023 11:24:42 +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.2507.23; Fri, 14 Apr 2023 11:26:06 +0800 From: Changbin Du To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , , , Hui Wang , Changbin Du Subject: [PATCH v4 2/2] perf: script: add new output field 'dsoff' to print dso offset Date: Fri, 14 Apr 2023 11:25:47 +0800 Message-ID: <20230414032547.2767909-3-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414032547.2767909-1-changbin.du@huawei.com> References: <20230414032547.2767909-1-changbin.du@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500013.china.huawei.com (7.221.188.120) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This adds a new 'dsoff' field to print dso offset for resolved symbols, and the offset is appended to dso name. Default output: $ perf script ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_= common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unk= nown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unk= nown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __er= rno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1) Display 'dsoff' field: $ perf script -F +dsoff ls 2695501 3011030.487017: 500000 cycles: 152cc73ef4b5 get_= common_indices.constprop.0+0x155 (/usr/lib/x86_64-linux-gnu/ld-2.31.so+0x1c= 4b5) ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unk= nown] ([unknown]) ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unk= nown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unk= nown] ([unknown]) ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __er= rno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1+0x68d0) ls 2695501 3011030.487019: 500000 cycles: ffffffff992a6db0 [unk= nown] ([unknown]) Signed-off-by: Changbin Du --- tools/perf/Documentation/perf-script.txt | 2 +- tools/perf/builtin-script.c | 25 +++++++++++++++++++++++- tools/perf/util/evsel_fprintf.c | 6 ++++++ tools/perf/util/evsel_fprintf.h | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Document= ation/perf-script.txt index 68e37de5fae4..20a1558c555f 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -130,7 +130,7 @@ OPTIONS -F:: --fields:: Comma separated list of fields to print. Options are: - comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symof= f, + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr= , symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-out= put, brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen= , synth, phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_s= ize, ins_lat, diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 69394ac0a20d..95dd6d650c21 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -130,6 +130,7 @@ enum perf_output_field { PERF_OUTPUT_BRSTACKINSNLEN =3D 1ULL << 36, PERF_OUTPUT_MACHINE_PID =3D 1ULL << 37, PERF_OUTPUT_VCPU =3D 1ULL << 38, + PERF_OUTPUT_DSOFF =3D 1ULL << 39, }; =20 struct perf_script { @@ -171,6 +172,7 @@ struct output_option { {.str =3D "ip", .field =3D PERF_OUTPUT_IP}, {.str =3D "sym", .field =3D PERF_OUTPUT_SYM}, {.str =3D "dso", .field =3D PERF_OUTPUT_DSO}, + {.str =3D "dsoff", .field =3D PERF_OUTPUT_DSOFF}, {.str =3D "addr", .field =3D PERF_OUTPUT_ADDR}, {.str =3D "symoff", .field =3D PERF_OUTPUT_SYMOFFSET}, {.str =3D "srcline", .field =3D PERF_OUTPUT_SRCLINE}, @@ -559,6 +561,9 @@ static void set_print_ip_opts(struct perf_event_attr *a= ttr) if (PRINT_FIELD(DSO)) output[type].print_ip_opts |=3D EVSEL__PRINT_DSO; =20 + if (PRINT_FIELD(DSOFF)) + output[type].print_ip_opts |=3D EVSEL__PRINT_DSOFF; + if (PRINT_FIELD(SYMOFFSET)) output[type].print_ip_opts |=3D EVSEL__PRINT_SYMOFFSET; =20 @@ -612,6 +617,10 @@ static int perf_session__check_output_opt(struct perf_= session *session) if (evsel =3D=3D NULL) continue; =20 + /* 'dsoff' implys 'dso' field */ + if (output[j].fields & PERF_OUTPUT_DSOFF) + output[j].fields |=3D PERF_OUTPUT_DSO; + set_print_ip_opts(&evsel->core.attr); tod |=3D output[j].fields & PERF_OUTPUT_TOD; } @@ -916,6 +925,8 @@ static int perf_sample__fprintf_brstack(struct perf_sam= ple *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alf.map, fp); + if (PRINT_FIELD(DSOFF) && alf.map && alf.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alf.addr); printed +=3D fprintf(fp, ")"); } =20 @@ -923,6 +934,8 @@ static int perf_sample__fprintf_brstack(struct perf_sam= ple *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alt.map, fp); + if (PRINT_FIELD(DSOFF) && alt.map && alt.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alt.addr); printed +=3D fprintf(fp, ")"); } =20 @@ -959,6 +972,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_= sample *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alf.map, fp); + if (PRINT_FIELD(DSOFF) && alf.map && alf.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alf.addr); printed +=3D fprintf(fp, ")"); } printed +=3D fprintf(fp, "%c", '/'); @@ -966,6 +981,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_= sample *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alt.map, fp); + if (PRINT_FIELD(DSOFF) && alt.map && alt.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alt.addr); printed +=3D fprintf(fp, ")"); } printed +=3D print_bstack_flags(fp, entries + i); @@ -1006,12 +1023,16 @@ static int perf_sample__fprintf_brstackoff(struct p= erf_sample *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alf.map, fp); + if (PRINT_FIELD(DSOFF) && alf.map && alf.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alf.addr); printed +=3D fprintf(fp, ")"); } printed +=3D fprintf(fp, "/0x%"PRIx64, to); if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, "("); printed +=3D map__fprintf_dsoname(alt.map, fp); + if (PRINT_FIELD(DSOFF) && alt.map && alt.map->dso) + printed +=3D fprintf(fp, "+0x%lx", alt.addr); printed +=3D fprintf(fp, ")"); } printed +=3D print_bstack_flags(fp, entries + i); @@ -1378,6 +1399,8 @@ static int perf_sample__fprintf_addr(struct perf_samp= le *sample, if (PRINT_FIELD(DSO)) { printed +=3D fprintf(fp, " ("); printed +=3D map__fprintf_dsoname(al.map, fp); + if (PRINT_FIELD(DSOFF) && al.map && al.map->dso) + printed +=3D fprintf(fp, "+0x%lx", al.addr); printed +=3D fprintf(fp, ")"); } out: @@ -3851,7 +3874,7 @@ int cmd_script(int argc, const char **argv) "comma separated output fields prepend with 'type:'. " "+field to add and -field to remove." "Valid types: hw,sw,trace,raw,synth. " - "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso," + "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,dsoff" "addr,symoff,srcline,period,iregs,uregs,brstack," "brstacksym,flags,data_src,weight,bpf-output,brstackinsn," "brstackinsnlen,brstackoff,callindent,insn,insnlen,synth," diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprint= f.c index 1fb8044d402e..ae8333772c76 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -116,6 +116,7 @@ int sample__fprintf_callchain(struct perf_sample *sampl= e, int left_alignment, int print_ip =3D print_opts & EVSEL__PRINT_IP; int print_sym =3D print_opts & EVSEL__PRINT_SYM; int print_dso =3D print_opts & EVSEL__PRINT_DSO; + int print_dsoff =3D print_opts & EVSEL__PRINT_DSOFF; int print_symoffset =3D print_opts & EVSEL__PRINT_SYMOFFSET; int print_oneline =3D print_opts & EVSEL__PRINT_ONELINE; int print_srcline =3D print_opts & EVSEL__PRINT_SRCLINE; @@ -174,6 +175,8 @@ int sample__fprintf_callchain(struct perf_sample *sampl= e, int left_alignment, if (print_dso && (!sym || !sym->inlined)) { printed +=3D fprintf(fp, " ("); printed +=3D map__fprintf_dsoname(map, fp); + if (print_dsoff && map && map->dso) + printed +=3D fprintf(fp, "+0x%lx", addr); printed +=3D fprintf(fp, ")"); } =20 @@ -209,6 +212,7 @@ int sample__fprintf_sym(struct perf_sample *sample, str= uct addr_location *al, int print_ip =3D print_opts & EVSEL__PRINT_IP; int print_sym =3D print_opts & EVSEL__PRINT_SYM; int print_dso =3D print_opts & EVSEL__PRINT_DSO; + int print_dsoff =3D print_opts & EVSEL__PRINT_DSOFF; int print_symoffset =3D print_opts & EVSEL__PRINT_SYMOFFSET; int print_srcline =3D print_opts & EVSEL__PRINT_SRCLINE; int print_unknown_as_addr =3D print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR; @@ -237,6 +241,8 @@ int sample__fprintf_sym(struct perf_sample *sample, str= uct addr_location *al, if (print_dso) { printed +=3D fprintf(fp, " ("); printed +=3D map__fprintf_dsoname(al->map, fp); + if (print_dsoff && al->map && al->map->dso) + printed +=3D fprintf(fp, "+0x%lx", al->addr); printed +=3D fprintf(fp, ")"); } =20 diff --git a/tools/perf/util/evsel_fprintf.h b/tools/perf/util/evsel_fprint= f.h index 3093d096c29f..c8a9fac2f2dd 100644 --- a/tools/perf/util/evsel_fprintf.h +++ b/tools/perf/util/evsel_fprintf.h @@ -26,6 +26,7 @@ int evsel__fprintf(struct evsel *evsel, struct perf_attr_= details *details, FILE #define EVSEL__PRINT_UNKNOWN_AS_ADDR (1<<6) #define EVSEL__PRINT_CALLCHAIN_ARROW (1<<7) #define EVSEL__PRINT_SKIP_IGNORED (1<<8) +#define EVSEL__PRINT_DSOFF (1<<9) =20 struct addr_location; struct perf_event_attr; --=20 2.25.1