Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1356854ybj; Thu, 7 May 2020 22:38:59 -0700 (PDT) X-Google-Smtp-Source: APiQypKMyXg/I7liB7KO3QSoyOnE7L9+jd65BVMHyokUF4x2yHwNQdIGYo7oaCKTEwtejqdpNe6r X-Received: by 2002:aa7:dc4b:: with SMTP id g11mr701598edu.223.1588916339144; Thu, 07 May 2020 22:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588916339; cv=none; d=google.com; s=arc-20160816; b=cNfQNvjztOEICC5eJhqfrF5eUk3wEQ5H4hfwTsolAZdBTM76YaCT7CxE0LYAeLsaSM gKub/oK6RzirfWzGwuAVI5zDfGbDKDUsv5rZH9bnlP2F70BGX0G534JlXtsIMskN0VyX vqFXSJf2ZyKJZzV+be0gzkeSK+iwVV1MBWOGBzbIecubb/EX76BEkf0nYRYzhD5FkyJ3 zSigiAJ4BU8z6TKVttmlpaRVb2pBVJuSsrPoOqsRcC4BnLuUSWrqWpHgT+/Vpi3mIEdn qkSpwSf0LDRnOWJtnkkKK2UeDlOsU1lfvlcr+BmBciMB4kNIdv3WR/lX+YwAkoDvY8B6 HH2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=Qye1SVonTjqMOsVJuQeCBVCNLKV3+4pjVh0/bspBuQI=; b=so7flm0zreUvAJPVNU9oGvooev/LGIGw08n7/Y8dc7LvpJWXz9OPAzq1ebMC14nwUB iBP8+/gzJUS54N+lgHIG57VKtevgsvY8XbK4SqV6AjYEzPI+KBy2z5gbrr8mdZVmgwEj 8EACmwrHd5Y2lguGlXj/ghUH7ta+r9r/bpELXrOGL6i2O4+e6ir5dnTfRU+/bA1cmYmr yf6eS2ZjjtlizX1EXxOIbHCEoosiIU0gnWuWHyX7YV3orWtJOrc3S5D6ccY+OpYnz1Lu rde7uWLjYeOzI+KJGuDb7BBIdUezh6ocLwH+mIddQ9uY5NtIm+IzDyWTc3epQjFTLks4 TykA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CbDfIOxV; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si389187edw.78.2020.05.07.22.38.37; Thu, 07 May 2020 22:38:59 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=CbDfIOxV; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727851AbgEHFhB (ORCPT + 99 others); Fri, 8 May 2020 01:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727821AbgEHFg5 (ORCPT ); Fri, 8 May 2020 01:36:57 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6AEFC05BD09 for ; Thu, 7 May 2020 22:36:56 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id p31so665363qte.1 for ; Thu, 07 May 2020 22:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Qye1SVonTjqMOsVJuQeCBVCNLKV3+4pjVh0/bspBuQI=; b=CbDfIOxVT2dx5RZ83D4pkiUFNFhJ1sVAiBjizdkmRAvy0BO+EEXFy/kOCH2+kOlyzC 2HkZMRFi8zBHJVdpkv5SmTDm4wXrXSakYtZCKlFJy6GE9FCbZQS6v/BiCflmUiUKit5Q DtUESQzY5X6tgPPinxek9XaFvK95W5b2w1Vcxd4THyaoSj/8IfeWeMHFwOQ4niq6AI0h W1U0ZFn+S7qzVA6xC1h2trc43J0goe2fQ1PUJQwoPCsepiASp2TgeMIOv73mkynRu/mX T7oFZtsStM9SlRg7yw7whM1bd5C03VhGgYbFMoKesas0wrfRbgzNS2BNLzIJgkL0jl0I /xng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Qye1SVonTjqMOsVJuQeCBVCNLKV3+4pjVh0/bspBuQI=; b=UcK5ZXzWndkgb8tOF7bSLJ2wbWva0r9e6N52NIIicQKGDrUQ/0RMbjOn2duvGr7w8S RK0i2plii0359cSPvIYq2mA9vHo+hXIht7uf+B4OcAbX0ks6kCL5kUmYr96h6zTbPCc+ OHUUOXXue5/81jcg8+XZDCSNKt0G9qYIrO92Z/eoR43s0n6kp5IkJnZFl1jrrwavnxeJ ldGZT4EkxMU/JDGDhsT5q2rw3/LEDFqQ64Ce9kgrtbzHk0UxcdZTtCFyk8Zp1TNHWXMu Nyc82XEkL9dKBSCZgm8wLgI4pwWqLS4miVS4YY3lLUfAQAWUknXypRIja/8rM8zOsH6o 1xLg== X-Gm-Message-State: AGi0PubNfp2+uLO/l93rOeyRcfzM5W1iwFw5ldp2dfbTxja6Sjqfd7LV McutBGEW6bmbM2wv6hKb98xArShVKG0p X-Received: by 2002:a05:6214:18c9:: with SMTP id cy9mr1066619qvb.35.1588916215992; Thu, 07 May 2020 22:36:55 -0700 (PDT) Date: Thu, 7 May 2020 22:36:27 -0700 In-Reply-To: <20200508053629.210324-1-irogers@google.com> Message-Id: <20200508053629.210324-13-irogers@google.com> Mime-Version: 1.0 References: <20200508053629.210324-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog Subject: [RFC PATCH v3 12/14] perf metricgroup: order event groups by size From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When adding event groups to the group list, insert them in size order. This performs an insertion sort on the group list. By placing the largest groups at the front of the group list it is possible to see if a larger group contains the same events as a later group. This can make the later group redundant - it can reuse the events from the large group. A later patch will add this sharing. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 2a6456fa178b..69fbff47089f 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -520,7 +520,21 @@ static int __metricgroup__add_metric(struct list_head *group_list, return -EINVAL; } - list_add_tail(&eg->nd, group_list); + if (list_empty(group_list)) + list_add(&eg->nd, group_list); + else { + struct list_head *pos; + + /* Place the largest groups at the front. */ + list_for_each_prev(pos, group_list) { + struct egroup *old = list_entry(pos, struct egroup, nd); + + if (hashmap__size(&eg->pctx.ids) <= + hashmap__size(&old->pctx.ids)) + break; + } + list_add(&eg->nd, pos); + } return 0; } -- 2.26.2.645.ge9eca65c58-goog