From patchwork Tue Apr 18 03:15:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 84566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2559460vqo; Mon, 17 Apr 2023 20:42:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bWG8/uceTs6DX4jE5GFw9KR2Ccta/l/7vEOxqAXHJiybwX1OY8JWfv9/hQ8bDlW7VWdE0z X-Received: by 2002:a17:90a:f182:b0:246:d49c:bf64 with SMTP id bv2-20020a17090af18200b00246d49cbf64mr704012pjb.19.1681789331731; Mon, 17 Apr 2023 20:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681789331; cv=none; d=google.com; s=arc-20160816; b=H1MY+q+X5f6EqXerpDOy7EDFYFTMl9dsxRqiR4ikUxdbus11rnp51GHeFwyXWgIXRN huU3+uRgXcfYCUkVsQdCv4kvPZCO9ZnqQXeJL/kJR3kI5XLmpCNm2EKq5iy8jUcUnjN1 CGCTW8uknEP5JGK6IoSPCxv9tOZTdHjPrHqwX0TJ1jCxFA1fmFPT8q5/YkWAUAOOU58M AqXSGHYiLXzBohVe8ItzmXpoXRjPaX+nFSda0Dgt+LpuLDGoKhsWL59h6Dx5LfPT30v3 cxXatFOKDDUX/+xGksYEOWGtbA3DGcLyPlXNPEpk9++oB9GptLZ9d0UrY5R23vDrrDNc TSmw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn18-20020a17090b38d200b00247a4bad97esi3148808pjb.52.2023.04.17.20.42.00; Mon, 17 Apr 2023 20:42:11 -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 S229700AbjDRDRD (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763483930292771421?= X-GMAIL-MSGID: =?utf-8?q?1763483930292771421?= 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);