From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B09CC38A2A for ; Thu, 7 May 2020 08:15:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7725520753 for ; Thu, 7 May 2020 08:15:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a1D0g4qg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbgEGIPD (ORCPT ); Thu, 7 May 2020 04:15:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727106AbgEGIPA (ORCPT ); Thu, 7 May 2020 04:15:00 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DEE9C0610D5 for ; Thu, 7 May 2020 01:15:00 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id x8so4875277qkf.3 for ; Thu, 07 May 2020 01:15:00 -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=wdUpgcjdyvRHeAuiwINZJwatakpGlpcmPaMYucAxya4=; b=a1D0g4qgq2DeZVYxZXmwzJvFe80E+NY6Bl81ZXr1D2+xAl8ZNsS0+tJz9pxiOODZQE 6pJFFiDn3fEWNQQ5lrrjMYapn6poOSYZtu6PN0DoTmMrD4O2LkXxmyYf4XoZdMLy2FDP kEmpHV/MX3b6DZcKXWZYgy29uupIcAuwPc/RJzfEZ/Rn1SypACWfGKtvagqouxnMc+Se fJp0uZhkxRe7LTOnqHzqpSKdGKl375V2yIAzJ1aw5aG8/v7YD4el/AuJZKSYXHgff9PO 9695v/gBHe1pjJ7KY1yMmDhcIQNhKpQUkImim277Mw6mGWUzKGp3FctFIkMGsnx6HxE4 2FcA== 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=wdUpgcjdyvRHeAuiwINZJwatakpGlpcmPaMYucAxya4=; b=D4YhSzw7nkWxS69kcP9U2eYWCl+vFxRuv4EDEqZmHMKx+dnhQYuUfPeNSKv/pZlzMQ tCQljmTpKJsTlPH0Bm9ZSluuu7PBevuXpLZaZVLHrCeOdrTHxRiwEC5JeBb6DJfdM9kU dAVce3/eTj6DVxlNdJLeu5NE51dkRNtJWRR5+AB9/RQbd1zk/XFZDRu1L92vhumMBQaE FkTUJTycC+axG1d8RVH8iMeP7Z0PN69HG0thbzKfwIa2IDdda33L1+uisE+otzx5Pkng svk2gT+3yvVyo1c4y/VU9pYeX281FAIK5/iageQFr2L4mA93cGgCGHn5XAMcMYSnHs9y Oh0g== X-Gm-Message-State: AGi0PuacDCHpEsMtniHEW5k3BoWbGIdG8Rrj9BYR4JXRqim0hkPKpRfT W0Oy/4/ADF6tyxveagZV3vA1gtztnyE6 X-Google-Smtp-Source: APiQypKfY5bUdzcKD5EFsOUTDzmIo6WlYY0MBP0ESNMa+3S6spMM1XtYeHvtMwk6ZY1SEl8iBwSWx7hYrFlz X-Received: by 2002:ad4:4f01:: with SMTP id fb1mr12775550qvb.162.1588839299303; Thu, 07 May 2020 01:14:59 -0700 (PDT) Date: Thu, 7 May 2020 01:14:35 -0700 In-Reply-To: <20200507081436.49071-1-irogers@google.com> Message-Id: <20200507081436.49071-7-irogers@google.com> Mime-Version: 1.0 References: <20200507081436.49071-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [RFC PATCH 6/7] 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, 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 0a00c0f87872..25e3e8df6b45 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -519,7 +519,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.526.g744177e7f7-goog