Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1230933imm; Tue, 5 Jun 2018 11:03:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJbxcg+ldE241c1gHY7I3uV097yWG2geSYa4VMy0rSjpuMQdn1rFUZUY52rp5v8UkAwFWtm X-Received: by 2002:a17:902:b488:: with SMTP id y8-v6mr27044513plr.157.1528221811265; Tue, 05 Jun 2018 11:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528221811; cv=none; d=google.com; s=arc-20160816; b=MSPzjkU9ypQ9PSUbG2RfxsSc3cxaC/zN7vi+GqR1fjigUg7IVr/pc8SSRYnmTMF5zY /TfeqqRQwqLtXV3FM30w+V0BnK9hyE8oX5/PsML6zi0K9eHXAwSqi+jfK4OZ3kOwaSWC YLVJ/DZdOwoeb+Z3MCnkhpLp/nLe7N9uQP8TF0bsLjX2Ad6nIiR2NYoIN5fxRVGEIbnC aulc2kDPha0jHuxrVXKCsLtNalHYSmfrz2fOLrMM6FQYxlW3gJKzWd1je/419JKbTlol 9YOz3cQMh8FgKvEtS5wtSg0RSJDlx4sGRHuZIfWDBs1Ka4846yL5FupZUiQcoBjh4Vad 4wIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=8ZbPefSoPZbCx1c2pzp9nTxmxy5WQbliZpQZT+nohEc=; b=swhrQ48ELnhww5TFq0VeaWkBGR6VFvDpmDgV26ZVC7+NqxYCZnRN+SvWDegq26Nb4C 2KCEyzngNxNlraJrmS2D5gB9MMjUOAz38EtqP4r3so/6cT97vpP+OyAo5CFCiJPbXn0f UO8/pWe3jl8dh42eIMGGGw6hYu2u1koS7CJNt0o5OkIHUXFjMbQvXShZFhzSsILcPJUA osYUoPuSnl/kLLlXoWN65JtRwtZZcvBOTeJTEZDBAzoPHFMSooK1ov9bXIBZw14IV019 kruLCdJ17XEO2FcSswb+RT8ltiEtkOM6QJWOm3QLA4eUlAkF+ORrJUrQANvZcFUQXU8k lOWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yM1tFNDW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13-v6si22271202ple.274.2018.06.05.11.03.16; Tue, 05 Jun 2018 11:03:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yM1tFNDW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752489AbeFERvk (ORCPT + 99 others); Tue, 5 Jun 2018 13:51:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:45964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752463AbeFERvf (ORCPT ); Tue, 5 Jun 2018 13:51:35 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8A7BF2075B; Tue, 5 Jun 2018 17:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528221095; bh=WsoSktybVgIM+u5eLTa+NCg0ezzF0vtdYc3vuZgDB5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yM1tFNDWXrQ5xOnOGykSZWn+iNAG31DW7IjOifJE/dKyP4Z7N4VeN/3lvkWBinAfG jdv0SH+Q3llRXfJd0OmQ4R/kGWRwJwi5yRCTi4XMw08XKHCf1dBTWYjaCfXVlvNJgJ x3pLPo2GJ/P7zCtBzbfagyQD8Q7ldqkdTHA7pyG0= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 18/46] perf srcline: Introduce map__srcline() to make code more compact Date: Tue, 5 Jun 2018 14:50:02 -0300 Message-Id: <20180605175030.32549-19-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180605175030.32549-1-acme@kernel.org> References: <20180605175030.32549-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo Replacing a common open coded sequence. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-2d7d1nzd3ksqornloqeer99r@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/map.c | 12 ++++++---- tools/perf/util/map.h | 1 + tools/perf/util/sort.c | 60 +++++++++++--------------------------------------- 3 files changed, 22 insertions(+), 51 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 6ae97eda370b..92abc8e248c5 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -415,16 +415,20 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp) return fprintf(fp, "%s", dsoname); } +char *map__srcline(struct map *map, u64 addr, struct symbol *sym) +{ + if (map == NULL) + return SRCLINE_UNKNOWN; + return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr); +} + int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, FILE *fp) { - char *srcline; int ret = 0; if (map && map->dso) { - srcline = get_srcline(map->dso, - map__rip_2objdump(map, addr), NULL, - true, true, addr); + char *srcline = map__srcline(map, addr, NULL); if (srcline != SRCLINE_UNKNOWN) ret = fprintf(fp, "%s%s", prefix, srcline); free_srcline(srcline); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 97e2a063bd65..4cb90f242bed 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -169,6 +169,7 @@ static inline void __map__zput(struct map **map) int map__overlap(struct map *l, struct map *r); size_t map__fprintf(struct map *map, FILE *fp); size_t map__fprintf_dsoname(struct map *map, 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); diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 4058ade352a5..71096dbfeb88 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -333,13 +333,7 @@ struct sort_entry sort_sym = { char *hist_entry__get_srcline(struct hist_entry *he) { - struct map *map = he->ms.map; - - if (!map) - return SRCLINE_UNKNOWN; - - return get_srcline(map->dso, map__rip_2objdump(map, he->ip), - he->ms.sym, true, true, he->ip); + return map__srcline(he->ms.map, he->ip, he->ms.sym); } static int64_t @@ -375,28 +369,14 @@ static int64_t sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_from) { - struct map *map = left->branch_info->from.map; - if (!map) - left->branch_info->srcline_from = SRCLINE_UNKNOWN; - else - left->branch_info->srcline_from = get_srcline(map->dso, - map__rip_2objdump(map, - left->branch_info->from.al_addr), - left->branch_info->from.sym, - true, true, - left->branch_info->from.al_addr); + left->branch_info->srcline_from = map__srcline(left->branch_info->from.map, + left->branch_info->from.al_addr, + left->branch_info->from.sym); } if (!right->branch_info->srcline_from) { - struct map *map = right->branch_info->from.map; - if (!map) - right->branch_info->srcline_from = SRCLINE_UNKNOWN; - else - right->branch_info->srcline_from = get_srcline(map->dso, - map__rip_2objdump(map, - right->branch_info->from.al_addr), - right->branch_info->from.sym, - true, true, - right->branch_info->from.al_addr); + right->branch_info->srcline_from = map__srcline(right->branch_info->from.map, + right->branch_info->from.al_addr, + right->branch_info->from.sym); } return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); } @@ -420,28 +400,14 @@ static int64_t sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_to) { - struct map *map = left->branch_info->to.map; - if (!map) - left->branch_info->srcline_to = SRCLINE_UNKNOWN; - else - left->branch_info->srcline_to = get_srcline(map->dso, - map__rip_2objdump(map, - left->branch_info->to.al_addr), - left->branch_info->from.sym, - true, true, - left->branch_info->to.al_addr); + left->branch_info->srcline_to = map__srcline(left->branch_info->to.map, + left->branch_info->to.al_addr, + left->branch_info->to.sym); } if (!right->branch_info->srcline_to) { - struct map *map = right->branch_info->to.map; - if (!map) - right->branch_info->srcline_to = SRCLINE_UNKNOWN; - else - right->branch_info->srcline_to = get_srcline(map->dso, - map__rip_2objdump(map, - right->branch_info->to.al_addr), - right->branch_info->to.sym, - true, true, - right->branch_info->to.al_addr); + right->branch_info->srcline_to = map__srcline(right->branch_info->to.map, + right->branch_info->to.al_addr, + right->branch_info->to.sym); } return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); } -- 2.14.3