Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp194878pxb; Tue, 19 Oct 2021 00:28:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqR7Xyvf+SIuP68az/2Nq1mZvcWpWZ+7N7fP1t1ATTuQtF2wJHKIgjBSf0b07Hn0bM9Kkq X-Received: by 2002:a17:907:3e8e:: with SMTP id hs14mr35533862ejc.35.1634628507674; Tue, 19 Oct 2021 00:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634628507; cv=none; d=google.com; s=arc-20160816; b=GaQtqpUfXcgEb7OwWskYX+2rQivAnEjS3a8flgp4sn3eButq9ntFqV//tkPRdUOlYT pAG9FVGcs7DHoopjizQ8u/wtAmq/3ueMs2bKZpcW7DzzDc7wj5L3S0LC++ls74Fubnz8 vNZFfuc9Mo5ONNqe8ZrH+NUUW64goP9CYztYBJyfts6ahVznMimCKgmoBu7jFKA4wBzj i2OE1HSrEJE2fpRYjO9gURTPQs0SbUPIo0KahICM2GFeXDEFovJUGGrdSWBzJv4d1CR8 0EzM6dPiLVJ7BUIKSdw7wHXaKbv9q/w2mtQ0y+Z5j0e79jBfxayqJPVTJtnc5/47aDnM Iy0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=KRjTv7YwAvuGQDZgfYx4u3kmSrAFlDgDouzGyby3mbo=; b=GEY4tKk1rPcvIT9w06YKnvQlPzJQlJdcTO11bSqGLsk3l2MA23e0dkW8vZY9RFCOO0 Pxq1qXDu3IL95CLl8OlSHjPZ0H2mGTc57mvQztlW7OMS7+zgcL5a3FzBoFqOWVsS+aZq TcJYPaKFxOZEJVWJC3SgiEJQekvRdA9iPWK7+n88WyUvLejC/rteRzdDcEbE0uKv6Pnv fOUZqpvkdWGitmTTPyEc6BezRofhatSpBHVu8pFQ8YCcFSmyHRP+rqnhXxhaJ1PwNdEw mNrtvsdG3yYxrjWpvyxmKsurYhhKopcULE7B/K1jyyQHWCIE+j7MTgqWsbf2HhxCbzoN lGoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si22286075ejt.663.2021.10.19.00.27.40; Tue, 19 Oct 2021 00:28:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234458AbhJSH1U (ORCPT + 99 others); Tue, 19 Oct 2021 03:27:20 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:25167 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234415AbhJSH1R (ORCPT ); Tue, 19 Oct 2021 03:27:17 -0400 Received: from dggeme762-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HYQFf4jrrz1DHjK; Tue, 19 Oct 2021 15:23:18 +0800 (CST) Received: from huawei.com (10.67.189.2) by dggeme762-chm.china.huawei.com (10.3.19.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Tue, 19 Oct 2021 15:25:03 +0800 From: Lexi Shao To: , CC: , , , , , , , , , , Subject: [PATCH] perf script: Show binary offsets for userspace addr Date: Tue, 19 Oct 2021 15:24:17 +0800 Message-ID: <20211019072417.122576-1-shaolexi@huawei.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.2] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme762-chm.china.huawei.com (10.3.19.108) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Show binary offsets for userspace addr with map in perf script output with callchain. In commit 19610184693c("perf script: Show virtual addresses instead of offsets"), the addr shown in perf script output with callchain is changed from binary offsets to virtual address to fix the incorrectness when displaying symbol offset. This is inconvenient in scenario that the binary is stripped and symbol cannot be resolved. If someone wants to further resolve symbols for specific binaries later, he would need an extra step to translate virtual address to binary offset with mapping information recorded in perf.data, which can be difficult for people not familiar with perf. This patch modifies function sample__fprintf_callchain to print binary offset for userspace addr with dsos, and virtual address otherwise. It does not affect symbol offset calculation so symoff remains correct. Before applying this patch: test 1512 78.711307: 533129 cycles: aaaae0da07f4 [unknown] (/tmp/test) aaaae0da0704 [unknown] (/tmp/test) ffffbe9f7ef4 __libc_start_main+0xe4 (/lib64/libc-2.31.so) After this patch: test 1519 111.330127: 406953 cycles: 7f4 [unknown] (/tmp/test) 704 [unknown] (/tmp/test) 20ef4 __libc_start_main+0xe4 (/lib64/libc-2.31.so) Fixes: 19610184693c("perf script: Show virtual addresses instead of offsets") Signed-off-by: Lexi Shao --- tools/perf/util/evsel_fprintf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c index bfedd7b23521..8c2ea8001329 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -11,6 +11,7 @@ #include "strlist.h" #include "symbol.h" #include "srcline.h" +#include "dso.h" static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...) { @@ -144,12 +145,17 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, if (print_arrow && !first) printed += fprintf(fp, " <-"); - if (print_ip) - printed += fprintf(fp, "%c%16" PRIx64, s, node->ip); - if (map) addr = map->map_ip(map, node->ip); + if (print_ip) { + /* Show binary offset for userspace addr */ + if (map && !map->dso->kernel) + printed += fprintf(fp, "%c%16" PRIx64, s, addr); + else + printed += fprintf(fp, "%c%16" PRIx64, s, node->ip); + } + if (print_sym) { printed += fprintf(fp, " "); node_al.addr = addr; -- 2.12.3