From patchwork Thu Dec 15 19:28:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 33810 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp561348wrn; Thu, 15 Dec 2022 11:33:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf59S7uY2WosXnTK2j4hwn6t0lDakojqoLcx2Tpjs2qZZlzDEXaF8EzJ/JojVUNZ+DMzKUHm X-Received: by 2002:a62:a509:0:b0:56b:f127:f21f with SMTP id v9-20020a62a509000000b0056bf127f21fmr28680447pfm.13.1671132781103; Thu, 15 Dec 2022 11:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671132781; cv=none; d=google.com; s=arc-20160816; b=gh3CHKIdg9LaJLff21L9J70SVak92FrQ7B8h8ak7DCjMWCFAT8HaWFaxHOxBGTjg4C acSENbHsOX3BDo1AYQjASdt2OsKdEeULLKuTLE+AyBN67T9ttv8PaRQBVHpgtoaiXyQl bpTvJFt6cMfw+XpVaUCenutHoaWT2aDdG65xYmBjr3RiMY0byGtxoJVvbv6JBGGqtnt6 2YQWgScj9Q+PGZ7ONtmq52D6x+mVxMRpeVjHhd++cFXqcX3e2dZBI46/eS3wGmw9SrTp /74u/jQZKBBTwO6ITB+PN93LoaSpJzVs0nfPZmZG5uZGofsUZ1kGjvkaMcjUzgj4sQ7E nQdw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020aa78f89000000b0056c882d3d06si3318608pfs.199.2022.12.15.11.32.46; Thu, 15 Dec 2022 11:33:01 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752309727090955782?= X-GMAIL-MSGID: =?utf-8?q?1752309727090955782?= 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, };