Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4827412rwe; Mon, 17 Apr 2023 20:19:00 -0700 (PDT) X-Google-Smtp-Source: AKy350aaKx2hREWaK5hyJzfd9W+9OHI+fHRb2/RpyRTTvYtp23gRafikYPrhrWsn+B4+eq6XEHXU X-Received: by 2002:a17:902:b101:b0:1a6:52f9:d4c7 with SMTP id q1-20020a170902b10100b001a652f9d4c7mr561011plr.60.1681787940250; Mon, 17 Apr 2023 20:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681787940; cv=none; d=google.com; s=arc-20160816; b=OUW6MZR4S8K1wNNUsvC2+KxP70eF9KDBtyPkmYlDBAwubhUst0LjkrZliCF9ft7J93 Y3LG8mtalf26iQwdvU+nJ/WTvagazknfeZTF0y0ForJfBXwH7KpekKeT9oIYc0o8lss0 AHX+gif+9SMvwRbw2X/Nd86JDO1KzU/j3ni1stPSWZfqZ+55D3CNYsx2mJeSpUAVs1xI rIFrm5CVHV1mv85NjWnLN2c2XMJskMVXWc5HxKEvN9Shg0NHqdGXGpRWpknanDlCi8Jj Q6KCM1KcruNb6BpHjeSUraP8FFA4VnWkgGN5GohkgWPR/mpoKEpuXyLTKzcon/A4gA8k qpyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gJmr5WuIeN5akB/VzovzQjB1UPCHPXAh9pIXeTCu+jk=; b=AIcJPvUl0m2MssBuErCkPkYwHeSNvst/FYwIYB7+20Vb7IJr3dIDSw/Xfvj8f2iQ5B gVPKejU8x1HNMsiceQMafZn3Un39Pm/f+hwZqhB+zqndOrKbgDddjmzLN20hSrFPA8ys rvR65Eim/RhD1IGH5EKpTBE8TNoRrPblzUIhcjFLVmaKTfboZ8+K4gyokIMEPl74uK+u b9mJoKv7Yg8/W2dDEjYYDIYj3LCokwcPIZJJY85/8l19RhWAPluEiwxP2+rTByf20air ZzMmq+90vhN+nRiZsvLTOLe2AyOdwt2ovPYXknG75QnGMxjBSx+S6a3iu+KqliGDpJ/k VMNA== 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a170902e5d200b0019926d9c734si14279063plf.602.2023.04.17.20.18.49; Mon, 17 Apr 2023 20:19:00 -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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbjDRDRD (ORCPT + 99 others); Mon, 17 Apr 2023 23:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjDRDQ4 (ORCPT ); Mon, 17 Apr 2023 23:16:56 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635244685; Mon, 17 Apr 2023 20:16:55 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [7.221.188.120]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Q0pwM4LgdzKs8m; Tue, 18 Apr 2023 11:16:03 +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; Tue, 18 Apr 2023 11:15:35 +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 v5 1/2] perf: add helper map__fprintf_dsoname_dsoff Date: Tue, 18 Apr 2023 11:15:18 +0800 Message-ID: <20230418031519.1261310-2-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418031519.1261310-1-changbin.du@huawei.com> References: <20230418031519.1261310-1-changbin.du@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500013.china.huawei.com (7.221.188.120) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 This adds a helper function map__fprintf_dsoname_dsoff() to print dsoname with optional dso offset. Suggested-by: Adrian Hunter Signed-off-by: Changbin Du --- tools/perf/util/map.c | 13 +++++++++++++ tools/perf/util/map.h | 1 + 2 files changed, 14 insertions(+) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index d81b6ca18ee9..7da96b41100f 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -445,6 +445,19 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) return fprintf(fp, "%s", dsoname); } +size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp) +{ + int printed = 0; + + printed += fprintf(fp, " ("); + printed += map__fprintf_dsoname(map, fp); + if (print_off && map && map__dso(map) && !map__dso(map)->kernel) + printed += fprintf(fp, "+0x%" PRIx64, addr); + printed += fprintf(fp, ")"); + + return printed; +} + char *map__srcline(struct map *map, u64 addr, struct symbol *sym) { if (map == NULL) diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index f89ab7c2d327..4cca211b6e66 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -175,6 +175,7 @@ static inline void __map__zput(struct map **map) size_t map__fprintf(struct map *map, FILE *fp); size_t map__fprintf_dsoname(struct map *map, FILE *fp); +size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp); char *map__srcline(struct map *map, u64 addr, struct symbol *sym); int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, FILE *fp); -- 2.25.1