From patchwork Mon Apr 24 05:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 86861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2529149vqo; Sun, 23 Apr 2023 23:03:42 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUcBa3uKybu9bcozGsdc/DZ8SuTB+D/MJtG7tYNIds07RH/ZZHXCr4X5txg4LbiaA235qk X-Received: by 2002:a05:6a21:339c:b0:d9:b024:4824 with SMTP id yy28-20020a056a21339c00b000d9b0244824mr16256137pzb.26.1682316222555; Sun, 23 Apr 2023 23:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682316222; cv=none; d=google.com; s=arc-20160816; b=D4H72OjHOWYYJrY7ia45jc13l0JVsavIny0VEUwbJDNVJIws3nElqDpT04e6ygeNkF gRnTaDNcb9nUi1ZIRBRgE+QbTdqDS5Id723qqidLgeuIv7o0MDb7YJsdqg5VSVN24ulP 0f/4MO+sPbNREIxuyBEfkxJgOeGje7hDJCMYuijHeYd9B5ITRXoCPLJjTOXdR1T6PFbp OJd2m9IwcsdujghX+A/Hr41rGPDx1QwHTc6Hp76v0OnozMA224kHg42AB5jVf2F1SQuT U+qBkHpIkTz9cX0Agwp5SwSchEIbPeYlfAfkKtxGjBn/fiXGtlwdvrTAfV8lEMyhq+bN oPtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8LGzNw4QX4YgP4208/nHC+EYKzmffDTYZHKkY1pOFSQ=; b=aI8SE/5YR+O9a+wAy4yrEP5w6dB46Ts84n5bTyCMoX6bIXg/GqdiB2O76Yl96m0JJl 1KkAFrK66oLC3eKlQXyU9yc3oQXgZFD22wCcc3bvXqw71HqgC+EZxnGFNJJ26Fx52dXW 9aLZIe6rCUjWb3hyyGY/MbECAEXcJqcscZQOOyn32rA4gZNwEmSGA1RESwE5w/wdPALX tmkzSLsXal5HVraR5eOf+ngMFnWk76tuhpYeMn6kbc0CSTadyjxMQ7FH6cXO6sMJwwvg sNcmPav07juCj47G7p20wBpD8lYrYaUMaY5m+aUvTPUAv/5mX1ttigm6Y7UqOsJOCe1M knYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XPhRYuml; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a635b11000000b0051394ca5bbdsi10544743pgb.257.2023.04.23.23.03.30; Sun, 23 Apr 2023 23:03:42 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=XPhRYuml; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbjDXF4L (ORCPT + 99 others); Mon, 24 Apr 2023 01:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbjDXFzx (ORCPT ); Mon, 24 Apr 2023 01:55:53 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE7C49E4; Sun, 23 Apr 2023 22:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682315699; x=1713851699; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sxJxWo7sT3H6f3IRpTxjOsEbwQQ+lUcjOow4n1ItELU=; b=XPhRYumlYnFOB+QGvFIcaTsbWt/g/R8a7pahkgjxFnNsOiRgKxCXGRxU mgmZ11Pt5oOJkM+fsTYcfC4zz6ZAZBGjsmc/TzleH60Fg7l/fUAoiOCM3 ZNV8hfNWOMiAe6GMLYBQnLCklhk74twrDk1UZIf6XCN3P/LCbmEsGGM7w J2uFZKD9ST3JvigUlbiNbM84HQ+UNclugRIOSqse6/X893Ty9ov+MbqfG jpKVdBlCP4tK5q/Ya7h2/drHcc171/wsTkQDt8wuCR1J4RxLWWTTOl7WQ O/D/bJg8eHG4htYxVCCmKMK5335Ncwzc5VFe3150GfoxKn0if6v2T9alA g==; X-IronPort-AV: E=McAfee;i="6600,9927,10689"; a="325972506" X-IronPort-AV: E=Sophos;i="5.99,221,1677571200"; d="scan'208";a="325972506" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2023 22:51:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10689"; a="686669259" X-IronPort-AV: E=Sophos;i="5.99,221,1677571200"; d="scan'208";a="686669259" Received: from faerberc-mobl2.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.58.217]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2023 22:51:31 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Changbin Du Subject: [PATCH 1/2] perf dso: Declare dso const as needed Date: Mon, 24 Apr 2023 08:51:06 +0300 Message-Id: <20230424055107.12105-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424055107.12105-1-adrian.hunter@intel.com> References: <20230424055107.12105-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,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?1764036415593543432?= X-GMAIL-MSGID: =?utf-8?q?1764036415593543432?= Declare dso const, so that functions can be called with const struct *dso. Signed-off-by: Adrian Hunter --- tools/perf/util/dso.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 0b7c7633b9f6..dfc4cf3de7a8 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -379,19 +379,19 @@ void dso__reset_find_symbol_cache(struct dso *dso); size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp); size_t dso__fprintf(struct dso *dso, FILE *fp); -static inline bool dso__is_vmlinux(struct dso *dso) +static inline bool dso__is_vmlinux(const struct dso *dso) { return dso->binary_type == DSO_BINARY_TYPE__VMLINUX || dso->binary_type == DSO_BINARY_TYPE__GUEST_VMLINUX; } -static inline bool dso__is_kcore(struct dso *dso) +static inline bool dso__is_kcore(const struct dso *dso) { return dso->binary_type == DSO_BINARY_TYPE__KCORE || dso->binary_type == DSO_BINARY_TYPE__GUEST_KCORE; } -static inline bool dso__is_kallsyms(struct dso *dso) +static inline bool dso__is_kallsyms(const struct dso *dso) { return dso->kernel && dso->long_name[0] != '/'; } From patchwork Mon Apr 24 05:51:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 86866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2529681vqo; Sun, 23 Apr 2023 23:04:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bKSHBqty5zXLDDzH3f8hbh5gikPHSjRvWAA3ZCeEzLihr7PAsdaaOhQEZALqBX5ILfNzxI X-Received: by 2002:a05:6a21:339a:b0:ec:8bae:83a8 with SMTP id yy26-20020a056a21339a00b000ec8bae83a8mr16003863pzb.28.1682316294218; Sun, 23 Apr 2023 23:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682316294; cv=none; d=google.com; s=arc-20160816; b=TlK1mJLT3NzKhSTgkQn3Ir9w5sxxa8GF4nf5BMRzfcI3654f4xEpzZcJajk6cA8sev 0XFHGJ0GXTnaUHjInDC1IPwG/LwChZ8UBwpOPTixPdG7DdCikIvCnbhq0stgEEUxkDDK S1u05crkUW+aPCHvtZoe9NMXshIy+9bBEd0cE1c7HFwXyXdShP7K7TSpkmdUvKJEZ7J7 IgoRWWrqoXofel95clD2pLYA7JeNMossYEuLigNFBNK44rFgPMU9TFgDDTTq2dg2sKnX 9Is0hY32wRZsa8vGOotfi/gvICXc2rNwGycym1wLuZsOvMCp3RT+kiXNPuVt3B1Cn0WC 4zgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MCARQpKnIxBVbb0KROrfuVUOVIMa04gZrGBZfZ6vzIE=; b=Zeu08cE+9b9S7id/aRpkyx1ey5A14leAgBuOX3yXVpGzWcIcv27x3uMmYmbPw0JcEV ZZ0cvt3BVhipCKjXBzN1pnPfwJjprpAfOMqfxZJ8zeRmgG72Xzi2QcfP50JGSGBmtYWO j7x4cDQWAiPtyWksEuY77YLcZh/83wgQXJXea7fz8nE6X63ByyKVcK8OfyqgqYzweyEM 66uY7SLL9Y2R/n55e1RvNQQkYtniZpv6TkYNiUn7G4wvDa25/Ar1dsCWp+fzboKzshZS cuahRHh0XiJSxpn9Mix28DEYlJShEBkYClU4X2HOWCL6tG7Q0P+vm25VquHd6nhIHK8C NePA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RubeAxwN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b00513234112acsi10004336pgp.888.2023.04.23.23.04.42; Sun, 23 Apr 2023 23:04:54 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=RubeAxwN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231364AbjDXF4N (ORCPT + 99 others); Mon, 24 Apr 2023 01:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231317AbjDXFzy (ORCPT ); Mon, 24 Apr 2023 01:55:54 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5475A49FC; Sun, 23 Apr 2023 22:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682315700; x=1713851700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6xleu/fOnIC7s6yeyC8yL6FZe/msxx+96HNpJqwRSLo=; b=RubeAxwNwpy/S5M3HUZD7Du+dmhBPM+0rLUJOTjfzfBUNAMW994XVBOV KedbyYzG1MBmRlwkUN+dSh4AtaAIAAiY9irZrOOHGD7FfTr/MhccUXbiM PdPfOjYeO6vLCnBtiPGKJhcLoj+EYQjWPVklL3UZpMh5mos7m3voknAjk v0OezSgTMHzfTLbPrZc5oiZtFi1K7sOQLNnCV+K1EfgmE703dFIoyfghQ W33Anvy4k6uUpy9RBLR4xOFUHyiG3Ed7l2uDDqUqXGD3ma/EHH/wCRB03 HK3+HCgd5NiMKXE82u+tlCbIaa3bVkiSC2UM51YayQos4mZa0iXiRBTrR g==; X-IronPort-AV: E=McAfee;i="6600,9927,10689"; a="325972517" X-IronPort-AV: E=Sophos;i="5.99,221,1677571200"; d="scan'208";a="325972517" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2023 22:51:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10689"; a="686669275" X-IronPort-AV: E=Sophos;i="5.99,221,1677571200"; d="scan'208";a="686669275" Received: from faerberc-mobl2.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.58.217]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2023 22:51:34 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Changbin Du Subject: [PATCH 2/2] perf script: Refine printing of dso offset (dsoff) Date: Mon, 24 Apr 2023 08:51:07 +0300 Message-Id: <20230424055107.12105-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424055107.12105-1-adrian.hunter@intel.com> References: <20230424055107.12105-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,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?1764036490825477723?= X-GMAIL-MSGID: =?utf-8?q?1764036490825477723?= Print dso offset only for object files, and in those cases force using the dso->long_name if the dso->name starts with '[' or the dso is kcore, in order to avoid special names such as [vdso], or mixing up kcore with vmlinux. Signed-off-by: Adrian Hunter --- tools/perf/util/dso.c | 33 +++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 2 ++ tools/perf/util/map.c | 23 +++++++++++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index a86614599269..046fbfcfdaab 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -67,6 +67,39 @@ char dso__symtab_origin(const struct dso *dso) return origin[dso->symtab_type]; } +bool dso__is_object_file(const struct dso *dso) +{ + switch (dso->binary_type) { + case DSO_BINARY_TYPE__KALLSYMS: + case DSO_BINARY_TYPE__GUEST_KALLSYMS: + case DSO_BINARY_TYPE__JAVA_JIT: + case DSO_BINARY_TYPE__BPF_PROG_INFO: + case DSO_BINARY_TYPE__BPF_IMAGE: + case DSO_BINARY_TYPE__OOL: + return false; + case DSO_BINARY_TYPE__VMLINUX: + case DSO_BINARY_TYPE__GUEST_VMLINUX: + case DSO_BINARY_TYPE__DEBUGLINK: + case DSO_BINARY_TYPE__BUILD_ID_CACHE: + case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO: + case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: + case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: + case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO: + case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: + case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: + case DSO_BINARY_TYPE__GUEST_KMODULE: + case DSO_BINARY_TYPE__GUEST_KMODULE_COMP: + case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: + case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP: + case DSO_BINARY_TYPE__KCORE: + case DSO_BINARY_TYPE__GUEST_KCORE: + case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: + case DSO_BINARY_TYPE__NOT_FOUND: + default: + return true; + } +} + int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type, char *root_dir, char *filename, size_t size) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index dfc4cf3de7a8..b23a157c914d 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -396,6 +396,8 @@ static inline bool dso__is_kallsyms(const struct dso *dso) return dso->kernel && dso->long_name[0] != '/'; } +bool dso__is_object_file(const struct dso *dso); + void dso__free_a2l(struct dso *dso); enum dso_type dso__type(struct dso *dso, struct machine *machine); diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 8c96ce6bfc51..4d9944bbf5e4 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -431,14 +431,21 @@ size_t map__fprintf(struct map *map, FILE *fp) map__start(map), map__end(map), map__pgoff(map), dso->name); } -size_t map__fprintf_dsoname(struct map *map, FILE *fp) +static bool prefer_dso_long_name(const struct dso *dso, bool print_off) +{ + return dso->long_name && + (symbol_conf.show_kernel_path || + (print_off && (dso->name[0] == '[' || dso__is_kcore(dso)))); +} + +static size_t __map__fprintf_dsoname(struct map *map, bool print_off, FILE *fp) { char buf[symbol_conf.pad_output_len_dso + 1]; const char *dsoname = "[unknown]"; const struct dso *dso = map ? map__dso(map) : NULL; if (dso) { - if (symbol_conf.show_kernel_path && dso->long_name) + if (prefer_dso_long_name(dso, print_off)) dsoname = dso->long_name; else dsoname = dso->name; @@ -452,13 +459,21 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) return fprintf(fp, "%s", dsoname); } +size_t map__fprintf_dsoname(struct map *map, FILE *fp) +{ + return __map__fprintf_dsoname(map, false, fp); +} + size_t map__fprintf_dsoname_dsoff(struct map *map, bool print_off, u64 addr, FILE *fp) { + const struct dso *dso = map ? map__dso(map) : NULL; int printed = 0; + if (print_off && (!dso || !dso__is_object_file(dso))) + print_off = false; printed += fprintf(fp, " ("); - printed += map__fprintf_dsoname(map, fp); - if (print_off && map && map__dso(map) && !map__dso(map)->kernel) + printed += __map__fprintf_dsoname(map, print_off, fp); + if (print_off) printed += fprintf(fp, "+0x%" PRIx64, addr); printed += fprintf(fp, ")");