Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1573961rwb; Thu, 15 Dec 2022 11:47:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf6qUITN299rC861kl13k8eSX9GzB1Dy9V0964nUntOvlGxWmvM39xP/wf+0VRAT15rw0TJJ X-Received: by 2002:a17:902:e194:b0:189:aab9:cd80 with SMTP id y20-20020a170902e19400b00189aab9cd80mr25776171pla.64.1671133679351; Thu, 15 Dec 2022 11:47:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671133679; cv=none; d=google.com; s=arc-20160816; b=zJKhu+WgBB7E0IFmtZdcd0Q117LNKSjpT21LIbdxcjyULzfUsYbGq8vWCXTCBTFY+t 11VtGOFks06wKSzCH5zFB6tpb2KU0YqGApwfz+KBYG90KNB661MMhpFWhCzbPB+f2YOl HWZnQELDG50BX9qoN/E5yS03GzvS36fKMx43c9+g5ogIMBasMSopZ9eU6frdH2lyO95Z MjQ2o0Q5tIE4Gm7LpHCOLkbx/cai6zoApTrEl/7ZriULUlnThur/RE99cp8dp21k6qjz 4ME/KIkS9cd/tFZ8Cu3zq5Z8Ek8kcMJAyaxnFeezrpP+omHmg5+i7nQr6GlHC/TUe/1Y f0rA== 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:sender :dkim-signature; bh=PJJL5CU7ptHXr+iHLPpq+YgdyRtPuip5im73Jo4lYDM=; b=rI3G0+FkeqdPHOptAS9giKruYbctEd81k619mPGla5ug4ZXfkJxIqwVdZTaJdhI6Mh 60BYqToPXgTX5eEryaeQekFfpuHvcQHA2XJ83zsghsnDtmEdwqDGTRHVocGOTCKOnrid 8W+fvbs87fNNlFlPbxXX8H/jbQxTIQp8+rn9RdmajRVGQWVqUALkRTSyPuL9z5QS/Or+ o66EH/gw444HqdaJXK3Iw75kofJ4/eb4R7zlQRz7315tgrWCxDBNITtVgS5XPfFUWkKw E9+pZ/15amBaJT+MQEoxzTgEtXSV1rTdggP6dOoUuUNwOpvAFVoLyWd4LEvBEcyoxzLv E7PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R2FycQjg; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a170902e80600b0017a0f71990dsi151974plg.141.2022.12.15.11.47.50; Thu, 15 Dec 2022 11:47:59 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=R2FycQjg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbiLOT3F (ORCPT + 68 others); Thu, 15 Dec 2022 14:29:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbiLOT2f (ORCPT ); Thu, 15 Dec 2022 14:28:35 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8446550D50; Thu, 15 Dec 2022 11:28:31 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id x2so6599227plb.13; Thu, 15 Dec 2022 11:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=PJJL5CU7ptHXr+iHLPpq+YgdyRtPuip5im73Jo4lYDM=; b=R2FycQjgluMgwJfWkdtp6gE6fj/eN6kjSEw5X/LK9opDYuWTGtP0YQ3rQKEu89EyHs BqrSj7SZ8qJhdlgx5bPS0DVtBA9iMVJPIotietniCz6iDuatLriqtkqUWiOT0JWa2tq6 Ixq0zD90mL6WORlCLzq0DF9V5FzWZTjGu05zubAEAJ3A6pFXcFiNJ8wH6H4bD8wChEHc k8wIVz6qFxyDn+MABc6A2UEFSm6O4TSFDujsypFP+xfu/k5ea2vYIsDgswOUrOUJ71Id N8jI9D4g5J11rnc+vrr3WOcLZ/KDJ0o7HJ8uVpkHgNAmBWv5H3rlKiOwkr6nb3XrQlD5 mUyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PJJL5CU7ptHXr+iHLPpq+YgdyRtPuip5im73Jo4lYDM=; b=zz/7QdIRsCbUcLwKw8toVonCmQClZm/Wg67+X4XCuXOC6Gdmj4ObcOr3Tlkc72peMd UTlc0hhfgAml/Jcyd+aJeK+H0yx+xk39HvuhZ47u8sM7owXw9Uxxb6BaPisMIPfAejEi qx7kvOJXj1DrZCXQd2cjQRLCBBEdD2hw1RIKIWEwYDOlCYbjsn7kQX18fPSWsQja5yH7 sw+ejTU84oCLo7ZXOi0XHDylLgLFH0jvKhQ2z2/VhdhichQpCNnqi7CPkwH7azBVu3Ku zX8qlCQHm6A5PGfpOBin2kIUkNGl6dDnqrNtyRAOM6rg5fpjHd2wUolIsZj3ZaYLrmwE HoRA== X-Gm-Message-State: ANoB5pksDIpvHzvvnQzxT+NSa1rmgqn6JNt4AhzTbmLYyOpjspvd4u/I XTvbfgDgq0IVaHpemXVREDo= X-Received: by 2002:a17:90a:e608:b0:219:705e:67b2 with SMTP id j8-20020a17090ae60800b00219705e67b2mr30567281pjy.10.1671132510943; Thu, 15 Dec 2022 11:28:30 -0800 (PST) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:ecc1:3e44:be34:129c]) by smtp.gmail.com with ESMTPSA id ep14-20020a17090ae64e00b00219cf5c3829sm3475129pjb.57.2022.12.15.11.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 11:28:30 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Andi Kleen , Milian Wolff , Leo Yan Subject: [PATCH 9/9] perf hist: Improve srcline_{from,to} sort key performance Date: Thu, 15 Dec 2022 11:28:17 -0800 Message-Id: <20221215192817.2734573-10-namhyung@kernel.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221215192817.2734573-1-namhyung@kernel.org> References: <20221215192817.2734573-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no 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 Likewise, modify ->cmp() callback to compare sample address and map address. And add ->collapse() and ->sort() to check the actual srcfile string. Also add ->init() to make sure it has the srcfile. Signed-off-by: Namhyung Kim --- tools/perf/util/sort.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index c290539dcf43..e188f74698dd 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -432,6 +432,12 @@ static char *addr_map_symbol__srcline(struct addr_map_symbol *ams) static int64_t sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) +{ + return left->branch_info->from.addr - right->branch_info->from.addr; +} + +static int64_t +sort__srcline_from_collapse(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_from) left->branch_info->srcline_from = addr_map_symbol__srcline(&left->branch_info->from); @@ -442,6 +448,18 @@ sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right) return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from); } +static int64_t +sort__srcline_from_sort(struct hist_entry *left, struct hist_entry *right) +{ + return sort__srcline_from_collapse(left, right); +} + +static void sort__srcline_from_init(struct hist_entry *he) +{ + if (!he->branch_info->srcline_from) + he->branch_info->srcline_from = addr_map_symbol__srcline(&he->branch_info->from); +} + static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { @@ -451,6 +469,9 @@ static int hist_entry__srcline_from_snprintf(struct hist_entry *he, char *bf, struct sort_entry sort_srcline_from = { .se_header = "From Source:Line", .se_cmp = sort__srcline_from_cmp, + .se_collapse = sort__srcline_from_collapse, + .se_sort = sort__srcline_from_sort, + .se_init = sort__srcline_from_init, .se_snprintf = hist_entry__srcline_from_snprintf, .se_width_idx = HISTC_SRCLINE_FROM, }; @@ -459,6 +480,12 @@ struct sort_entry sort_srcline_from = { static int64_t sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) +{ + return left->branch_info->to.addr - right->branch_info->to.addr; +} + +static int64_t +sort__srcline_to_collapse(struct hist_entry *left, struct hist_entry *right) { if (!left->branch_info->srcline_to) left->branch_info->srcline_to = addr_map_symbol__srcline(&left->branch_info->to); @@ -469,6 +496,18 @@ sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right) return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to); } +static int64_t +sort__srcline_to_sort(struct hist_entry *left, struct hist_entry *right) +{ + return sort__srcline_to_collapse(left, right); +} + +static void sort__srcline_to_init(struct hist_entry *he) +{ + if (!he->branch_info->srcline_to) + he->branch_info->srcline_to = addr_map_symbol__srcline(&he->branch_info->to); +} + static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { @@ -478,6 +517,9 @@ static int hist_entry__srcline_to_snprintf(struct hist_entry *he, char *bf, struct sort_entry sort_srcline_to = { .se_header = "To Source:Line", .se_cmp = sort__srcline_to_cmp, + .se_collapse = sort__srcline_to_collapse, + .se_sort = sort__srcline_to_sort, + .se_init = sort__srcline_to_init, .se_snprintf = hist_entry__srcline_to_snprintf, .se_width_idx = HISTC_SRCLINE_TO, }; -- 2.39.0.314.g84b9a713c41-goog