Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1353302rwl; Fri, 7 Apr 2023 14:34:48 -0700 (PDT) X-Google-Smtp-Source: AKy350YppeVwtAV2X1/bEe5X09Tga0auhW2lq/anfSyXeR4NB53cybfxHz9oVD2yKrdyfGDg4UYY X-Received: by 2002:a17:906:4690:b0:930:1178:2220 with SMTP id a16-20020a170906469000b0093011782220mr12039ejr.40.1680903288727; Fri, 07 Apr 2023 14:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680903288; cv=none; d=google.com; s=arc-20160816; b=GCvf89ZGhykGgcpR6Zr/vasgvMCTYwUC/cdGj+gkt+TGE7zOnsZRamJ9UuHgBcg8jk 0fnQW2nkw/H1/AHTUqE3y9mZHQusE6sXPISQ7Xo08GEKvLhoEoj2JKkYL3TgqpXwm7pP HG4JHn+Omdrl3Zn0W70d36BntK2ruRbVaAxOZ1BBCc95V2VwUzer1Ux9B+H2JQ8JbE3q Y/32ryVCt2wxQzSjJl46eZefYHjxs1uQiipY+c3sVYL+dM5QYWJH/xtcBLsR8Y0shz9L 3Eo2MP+ABe74Oh1HNPNEfSAxKsAc0Gtb6apFkcbbVOXpU/aT4ACn/R6+1H0XmGrIwk3C lOdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=xs0FUE1jpFw30hM7QjOF57Idcb1+qBMdjMB+YFuZZKw=; b=uBypyrc5ttfBtRaFqJVj8vMyWBSO9LCQZq2qjdmsYwoK+sOr7pbn3YqDqUV7yAxXKt tr71wbmePbNFqog53t2SExTBBeU4iJzIJ5VPE/N1XvHzE+hgGVvm1uof/YBUspWIrdQa 7mQlTN1axe3BIvzTryuaKljeM3SKXilN3xigGyOlgHJIEYbhqm6AwqJPuRlsP4fsMAvU hFQRKUCstKJVwm4Iz6zQiqrpwV83m4BASV07jhe2eJwPdk3TGF8yeXv7EG5r/SzdjM86 dg1Y2vO84+PtXBq82V0spD4+tCOuI75WLmMbk8kCbDLTWvV8zU1mZPYczxGQDjnWMRMa W+EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gv42-20020a1709072bea00b00929c73cd44csi3818721ejc.529.2023.04.07.14.34.24; Fri, 07 Apr 2023 14:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbjDGVZD convert rfc822-to-8bit (ORCPT + 99 others); Fri, 7 Apr 2023 17:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229524AbjDGVZC (ORCPT ); Fri, 7 Apr 2023 17:25:02 -0400 Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C64BB80; Fri, 7 Apr 2023 14:25:00 -0700 (PDT) Received: by mail-ua1-f45.google.com with SMTP id bh10so1341626uab.13; Fri, 07 Apr 2023 14:25:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680902700; x=1683494700; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k612bZuPeU9BYYEiReSh/KaPrQNbIQVI8+7Ue/dHlFU=; b=ZqCe5YuRynpr+udmNt/axrpRzStIpDI4/vuDE9MZVg5AJGPoe9yTIdqes+Yu2sAOao MW953jGSWaGMyIXVQ/P6j+jg3lSj5Jc2iGAR26ov3ma8Ugu6bLTgzGaO2OIX/bFJ5Il4 Vqfqv43Mx9Kf8eeSNTu7ZBPKa8ZrmDng1r/cP3Ng2CoVa/nF0WPrmmK3poKEqj29y71s 8NUixi6A0gAuUjhkYnJ86DJzlkxspmcxm1BfI723/ZOqvIopL0+CcJ/9rqYzSSMF6nQg T+lbIGpLfIpiWCN6VYKoFlRIEzxzBMampo+RML7EAvqiKMRMp33e7eoQdurW6TU7gNLD TNow== X-Gm-Message-State: AAQBX9feiibzwawY2wf6jB2NhpobTTBh6QO9X0gqi1gflaL4s3G3OOiu YAIse+teZTzmaEZGWnf5bn2CVhIWEwOR/rWZGoU= X-Received: by 2002:a05:6122:a09:b0:431:eb68:41b with SMTP id 9-20020a0561220a0900b00431eb68041bmr1412113vkn.11.1680902699507; Fri, 07 Apr 2023 14:24:59 -0700 (PDT) MIME-Version: 1.0 References: <20230407055212.2701635-1-changbin.du@huawei.com> <20230407055212.2701635-3-changbin.du@huawei.com> In-Reply-To: <20230407055212.2701635-3-changbin.du@huawei.com> From: Namhyung Kim Date: Fri, 7 Apr 2023 14:24:48 -0700 Message-ID: Subject: Re: [PATCH v2 2/2] perf: script: add new output field 'dsoff' to print dso offset To: Changbin Du Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Hui Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Changbin, On Thu, Apr 6, 2023 at 10:53 PM Changbin Du wrote: > > 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 [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) > ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) > ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_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+0x1c4b5) > ls 2695501 3011030.487018: 500000 cycles: ffffffff99045b3e [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffff9968e107 [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffffc1f54afb [unknown] ([unknown]) > ls 2695501 3011030.487018: 500000 cycles: ffffffff9968382f [unknown] ([unknown]) > ls 2695501 3011030.487019: 500000 cycles: ffffffff99e00094 [unknown] ([unknown]) > ls 2695501 3011030.487019: 500000 cycles: 152cc718a8d0 __errno_location@plt+0x0 (/usr/lib/x86_64-linux-gnu/libselinux.so.1+0x68d0) > ls 2695501 3011030.487019: 500000 cycles: ffffffff992a6db0 [unknown] ([unknown]) > > Signed-off-by: Changbin Du > --- > tools/perf/Documentation/perf-script.txt | 2 +- > tools/perf/builtin-script.c | 5 +++++ > tools/perf/util/evsel_fprintf.c | 6 ++++++ > tools/perf/util/evsel_fprintf.h | 1 + > 4 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt > index 777a0d8ba7d1..ff9a52e44688 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, symoff, > + comm, tid, pid, time, cpu, event, trace, ip, sym, dso, dsoff, addr, symoff, > srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, > brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen, synth, > phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat, > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c > index a792214d1af8..ccc409893c4b 100644 > --- a/tools/perf/builtin-script.c > +++ b/tools/perf/builtin-script.c > @@ -133,6 +133,7 @@ enum perf_output_field { > PERF_OUTPUT_VCPU = 1ULL << 38, > PERF_OUTPUT_CGROUP = 1ULL << 39, > PERF_OUTPUT_RETIRE_LAT = 1ULL << 40, > + PERF_OUTPUT_DSOFF = 1ULL << 41, > }; > > struct perf_script { > @@ -174,6 +175,7 @@ struct output_option { > {.str = "ip", .field = PERF_OUTPUT_IP}, > {.str = "sym", .field = PERF_OUTPUT_SYM}, > {.str = "dso", .field = PERF_OUTPUT_DSO}, > + {.str = "dsoff", .field = PERF_OUTPUT_DSOFF}, > {.str = "addr", .field = PERF_OUTPUT_ADDR}, > {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET}, > {.str = "srcline", .field = PERF_OUTPUT_SRCLINE}, > @@ -574,6 +576,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr) > if (PRINT_FIELD(DSO)) > output[type].print_ip_opts |= EVSEL__PRINT_DSO; > > + if (PRINT_FIELD(DSOFF)) > + output[type].print_ip_opts |= EVSEL__PRINT_DSOFF; What if the user gives 'dsoff' without 'dso'. Better to set the EVSEL__PRINT_DSO as well? Thanks, Namhyung > + > if (PRINT_FIELD(SYMOFFSET)) > output[type].print_ip_opts |= EVSEL__PRINT_SYMOFFSET; > > diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.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 *sample, int left_alignment, > int print_ip = print_opts & EVSEL__PRINT_IP; > int print_sym = print_opts & EVSEL__PRINT_SYM; > int print_dso = print_opts & EVSEL__PRINT_DSO; > + int print_dsoff = print_opts & EVSEL__PRINT_DSOFF; > int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET; > int print_oneline = print_opts & EVSEL__PRINT_ONELINE; > int print_srcline = print_opts & EVSEL__PRINT_SRCLINE; > @@ -174,6 +175,8 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, > if (print_dso && (!sym || !sym->inlined)) { > printed += fprintf(fp, " ("); > printed += map__fprintf_dsoname(map, fp); > + if (print_dsoff && map && map->dso) > + printed += fprintf(fp, "+0x%lx", addr); > printed += fprintf(fp, ")"); > } > > @@ -209,6 +212,7 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, > int print_ip = print_opts & EVSEL__PRINT_IP; > int print_sym = print_opts & EVSEL__PRINT_SYM; > int print_dso = print_opts & EVSEL__PRINT_DSO; > + int print_dsoff = print_opts & EVSEL__PRINT_DSOFF; > int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET; > int print_srcline = print_opts & EVSEL__PRINT_SRCLINE; > int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR; > @@ -237,6 +241,8 @@ int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, > if (print_dso) { > printed += fprintf(fp, " ("); > printed += map__fprintf_dsoname(al->map, fp); > + if (print_dsoff && al->map && al->map->dso) > + printed += fprintf(fp, "+0x%lx", al->addr); > printed += fprintf(fp, ")"); > } > > diff --git a/tools/perf/util/evsel_fprintf.h b/tools/perf/util/evsel_fprintf.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) > > struct addr_location; > struct perf_event_attr; > -- > 2.25.1 >