Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp34080ybk; Fri, 8 May 2020 17:42:43 -0700 (PDT) X-Google-Smtp-Source: APiQypKN8VMyPWa+3KPBU0A4Se66awm4k2EndQDb2/MMVreX34F1UPIGLpxItLoS1ghRDMjQ/mwG X-Received: by 2002:a50:8d0b:: with SMTP id s11mr4268906eds.75.1588984962792; Fri, 08 May 2020 17:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588984962; cv=none; d=google.com; s=arc-20160816; b=qNfpg672FtCzd/Ld3PNnQvaUoBSqaJXCHUVRr39QVx2J1GEkR+sGGVr+TfqUqinfmU rzm3QXB75494eBrwINFIMrV9aZVXQj6mbmR1Rze6A3PxZsMPXJWDMlBeHcUTPpdSx6PF OOo/Jid+O5yliypTaR7Z0LpuIa+nLcanckG3JgKcbOPYiunN8CFI59lrA73AagbF+T4i 5OjyPkhyBbNmzcza/DFjORla2KJVLcEswZyYOxhBM70H74XF7Lf/TXMM9mDUEALPqh7R zvcxPq0JL5laP8rwnPWIYRjIvjvrw+iJYdiSHJnaeTz3B6VLHtKKimwfO2nY5mv3exv7 MIXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=DiUjvkF6vCMGtTuhzeX2uqz+eNOu/2CgaqSxS5DH4H8=; b=hUvFyVRnvqQ6jyhavg2M4qtGzk77O71UJiV89ak+qRmGtiugZ0ip5jCsMXR2LoPEVE 94AV5qyrLkLhqtXkJNCTsZLbhQ+Le0v4HGeHT15wKbrw/3sgDeCsIM6diz3/e8DLxynN nN6Z9J083Hr3x3KGdLoXicVrVDbZuUPUH3PftUAvLgHzRh23YTcqRVs50GfOV4V1fURR JbWE7qBq41uIkfC5WtBNwENLfDm9bkQgxNVOPJwgkiyx+sYSdM4QCqTomwU5JaVtvQGF gKJSo671uNMn/87qekvx8Tcx8kc0tamKtJv3onPOuezuBw3leEPu7Zn8WjM+ikBPLOSQ ibQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nlpf2Tni; 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 cm24si1730384edb.586.2020.05.08.17.42.20; Fri, 08 May 2020 17:42:42 -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=nlpf2Tni; 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 S1728564AbgEIAkO (ORCPT + 99 others); Fri, 8 May 2020 20:40:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728565AbgEIAkN (ORCPT ); Fri, 8 May 2020 20:40:13 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D3FC061A0C for ; Fri, 8 May 2020 17:40:12 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id d197so1862798ybh.6 for ; Fri, 08 May 2020 17:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DiUjvkF6vCMGtTuhzeX2uqz+eNOu/2CgaqSxS5DH4H8=; b=nlpf2Tni9SbwpK2ejywX/nSoEvPGALiyyk0dSewDdpZrPgmU3+Y5AAEvGSRYO5PzdE NGXYKbZbxCqLHeKBUpw7BGuttAxG+AaTIauH0d5FhH8rrYKL5DiddCalSGt1QglN1T5/ Ist1+TWx/yOPa/8c0qoqc0TK3y/H8rYsQqc1bH3BsfvOQP4spAcFSYooVliUDefOEuEn FFkzpk5ARs0/lboa7VIHuWLiNChQHwelej02dQsQjeB8PxieTVbTIStfcp6bpwaRXWRy Bz1vMEs2LULJ0yL52jOrVN2xhz1qdMnTId0pIRqa6PkIOVGOgr0TKjeVy6tXhLdqyWnX 0/OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DiUjvkF6vCMGtTuhzeX2uqz+eNOu/2CgaqSxS5DH4H8=; b=nKfRTQirP4Kt9qjP4kL+WoNLePhpgLkrBLegt/9MiCeZhHM56M/0kFMxm/bNUxCtf3 Lyufdpi773jqiMICbpB2SqaRtwKzyEGcVT0zmAb6r8/VjkfTE5Mec3q7a9wmN+4WiFpE +4Nh71rIqjmStXR3FfMwb6709Mul/CD8KNRKWgU8uS0MFGJaUGaG+DQjhXmMqOGMiQN+ 5vZNiKh83WxmWaVtcwWQrhnc4bSknnLH3RlfvT53dGIj4P/GUFO8QF1lNAmXEoaa7Peb 3XuN0uWLv82w0DhTGROAe8vAOiUQ+312tYa194CQgUqYqYyfTRSQQKCi8dJ9i4A9XV3m Vdmw== X-Gm-Message-State: AGi0Pubq2GynM7KfLBqSbnVO8NGKTd40b5LSVoXdy/D0arhVWrMKQUm2 1AfdF5udtP4qhVRXtapsI/l1y/qgEFyI67Nte+Hfkw== X-Received: by 2002:a5b:9cb:: with SMTP id y11mr9151074ybq.177.1588984811458; Fri, 08 May 2020 17:40:11 -0700 (PDT) MIME-Version: 1.0 References: <20200508053629.210324-1-irogers@google.com> <20200508053629.210324-13-irogers@google.com> <20200509002518.GF3538@tassilo.jf.intel.com> In-Reply-To: <20200509002518.GF3538@tassilo.jf.intel.com> From: Ian Rogers Date: Fri, 8 May 2020 17:40:00 -0700 Message-ID: Subject: Re: [RFC PATCH v3 12/14] perf metricgroup: order event groups by size To: Andi Kleen Cc: 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 , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , LKML , Networking , bpf , linux-perf-users , Vince Weaver , Stephane Eranian 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 On Fri, May 8, 2020 at 5:25 PM Andi Kleen wrote: > > On Thu, May 07, 2020 at 10:36:27PM -0700, Ian Rogers wrote: > > 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. > > I'm not sure if size is that great an heuristic. The dedup algorithm should > work in any case even if you don't order by size, right? Consider two metrics: - metric 1 with events {A,B} - metric 2 with events {A,B,C,D} If the list isn't sorted then as the matching takes the first group with all the events, metric 1 will match {A,B} and metric 2 {A,B,C,D}. If the order is sorted to {A,B,C,D},{A,B} then metric 1 matches within the {A,B,C,D} group as does metric 2. The events in metric 1 aren't used and are removed. The dedup algorithm is very naive :-) > I suppose in theory some kind of topological sort would be better. We could build something more complex, such as a directed acyclic graph where metrics with a subset of events are children of parent metrics. Children could have >1 parent for example {A,B,C,D},{A,B,E},{A,B} where {A,B} is a subset of both {A,B,C,D} and {A,B,E} and so a child of both. Presumably in that case it'd be better to match {A,B} with {A,B,E} to reduce multiplexing. As we're merging smaller groups into bigger, the sorting of the list is a quick and dirty approximation of this. Thanks, Ian > -Andi > > > > 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 > >