Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4832336rwe; Mon, 17 Apr 2023 20:26:04 -0700 (PDT) X-Google-Smtp-Source: AKy350bfbnoootbOn7vwJmi+mBEYLZIZzK3X5zn3oQEXxj3QIoWlgiZK9qIBlft88RG7QEKsv2bx X-Received: by 2002:a05:6a20:3d28:b0:ed:1d7a:3339 with SMTP id y40-20020a056a203d2800b000ed1d7a3339mr16654388pzi.57.1681788363821; Mon, 17 Apr 2023 20:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681788363; cv=none; d=google.com; s=arc-20160816; b=CmAErwXvGqN8+49LhBS4wEKqIU7EZ0ItEd/dqx8PL27/zIGOGTNblaqJWk5ieS/1pS i/YuvvQPBWIL6vAJPU4YfpbfBtNjlWguRq2OQFKC5dOn/1bN/GgQ1HESZuf8XD9VHrzX uVb74wnHXTQRbCpbZMVJ/2qyG18OPbx9SUodi5+/JkyVWeoT5IV1ttcRvfHhAkNmdKjt f7r5btNu17pSPQXjeJ38fHC9JrwmlYBXIa3rZz+K1Pa3dWnP/YXGD0CJ0XEIGveWgecT /W3DMi1xwtoCjtIeSYaItNFZetwCM1RjGHZIhyO1+qlkKIZ/JTJ3yEmrtz/5QbRQ5eSy 7iuQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020aa79f42000000b0063b6e71d1f1si9659342pfr.40.2023.04.17.20.25.50; Mon, 17 Apr 2023 20:26:03 -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 S230352AbjDRDTP (ORCPT + 99 others); Mon, 17 Apr 2023 23:19:15 -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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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