From patchwork Tue Apr 18 03:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 84569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2563167vqo; Mon, 17 Apr 2023 20:54:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Yq1IgODnF4a4mTZ1+zGJ/MTdooM5va7ssdcopKBVbhaewGD0u3XqzO3jOqRrReu6mzPrEh X-Received: by 2002:a05:6a00:c8f:b0:63d:24e4:f9c with SMTP id a15-20020a056a000c8f00b0063d24e40f9cmr6251564pfv.17.1681790069646; Mon, 17 Apr 2023 20:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681790069; cv=none; d=google.com; s=arc-20160816; b=c1CHv+szXpiicbZF5UfOw1aL1eOjJlTTr4SnIcXIJcK0SeKttYigk3ddhMwjBZX6sn XebtlMMUo8oJWgXZTE5u5Z5jYdw90G6pg6rEhCm321EsKvAZj4Z632XLYkSzL7oP88Ax B1gEspuyL4esPV/Sed2Gind/t/CD4nANEne5NPSWnIbeyWuLXd/r7tNyI5UNtcigiHNc NJiiwcDbcvLj+W2dHUl409prCMy9GwxQhv5j7eNHlDqu27S4Gem871CkRYTWYcVaZkLu khdU/CgU15KzncwfeUI6Vj6VNOd8qwWp1vV31MoycbUl5oVuhBqM4cjwHUZJNbPv8Fh8 nJng== 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=renHxtKxtxm21sPDwD7XxW1TqcytnRSwTRHYxnThi876PTA1SqCVl2uVBzucZbod38 ZsJwjeyh5NQDL2lXl9VNO230S/0/INw36/tHsH+miaD6WhhrUe3NUxUkHe+JICDkQesj wHh3lOqvxcgKod8SxP1l6Y657Hx1pApj57j7+gA+EwHpudHZvNmIv80Np1Sx1kd8Dd6V A2XwHejCpWy7sRvbUqeKG98GmBZluTnh7ZIgaMtCHU1/3nKtOpuSZWqCkpKIk+uc9uS2 jirZFSh2X6HJyx93J0AUnPtQgTqJaagyDfEDj3hPaHvxcbZP4mtHm11ZBmVH6bht4myE 7C+w== 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 j2-20020a63e742000000b00517aaf50a82si594447pgk.854.2023.04.17.20.54.15; Mon, 17 Apr 2023 20:54:29 -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 S230355AbjDRDTQ (ORCPT + 99 others); Mon, 17 Apr 2023 23:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230106AbjDRDSz (ORCPT ); Mon, 17 Apr 2023 23:18:55 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850F55FC5; Mon, 17 Apr 2023 20:18:49 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [7.221.188.120]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Q0pvF2R4zzncDk; Tue, 18 Apr 2023 11:15:05 +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:18:46 +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 2/3] perf: add helper map__fprintf_dsoname_dsoff Date: Tue, 18 Apr 2023 11:18:24 +0800 Message-ID: <20230418031825.1262579-3-changbin.du@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230418031825.1262579-1-changbin.du@huawei.com> References: <20230418031825.1262579-1-changbin.du@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.54.157] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) 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?1763484703728765008?= X-GMAIL-MSGID: =?utf-8?q?1763484703728765008?= 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 Acked-by: Adrian Hunter --- 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);