Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2150757rwd; Thu, 15 Jun 2023 23:10:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oV22K15hHSKHXVvQS9zi75o5l8TEzb+R0dfR12IEJd+vybFerc68Q9CvSdz4aB4W834Mj X-Received: by 2002:a62:180a:0:b0:664:37b9:ddfb with SMTP id 10-20020a62180a000000b0066437b9ddfbmr7397733pfy.2.1686895839328; Thu, 15 Jun 2023 23:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686895839; cv=none; d=google.com; s=arc-20160816; b=C+LN6ky3U5Td55RgMSoaurX0eAHlgCq84Y7AGzh7Zo+yWkkz0A4mJWr38vn7W1n01Z YlU3Wofq4cUe8MlkvupYGyeM3jBzKCuvVh1A1U0avzjqeg1XMO5U202aNVlJ5eNsMvG3 dFhI1VUzQlfT2p0MwxPSHCnfF2ybz8YlG8kQunBPPbBbkLgVS6bHVC4GdtG3ozl/mbH9 Wu9kg66jHCZM0WjsFbbKtpZ9KMstpdgP7x/wu9PxMaqXTAlHygpi8jRR3NZhWt70rv8N LKDtcnFfrCchNDOo9I2/wAL0NjJQeyOcwvCckZwKwlox7N6kCHLXjD/0+LUmhIlNim+k BmOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ZwQw4AmMsj8rS1EO+I7cEg+kMMUbG54Oey3YjSE5diw=; b=f10vWZYwa/oU29y6aFXgv70Q7AgiIt2c2Q/zKdeZD6Btaq3wHx6TD7tz0jn+3HZXfb SyoglohKJBaWhxIwfbQ9JSDe1/hbsLNbWRovFpuwjMsgWs+1UJ6HnwmCLFmm2cpqe9wD 9CauTXdCQADTthpHW7mKnZv4wh2Xnn/MJWtxBy6wDEKesn4hk10r0cJHtUC+wmDHnK8a 84zvoF6rfIs960gwGlazwVTfkPcls/Znx++w9gAf7Yna2QF1cZxfFCtmxTTX+4r6v7gD mspyHg0uCoJT9Kd7wA//kiiQj85FtD2DJxLFShrLPJ5EuqZ51K7Xs2LV4zru7ASo5/+C Ibzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ew+f7NHQ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22-20020aa795b6000000b00666acab17acsi1889524pfk.318.2023.06.15.23.10.25; Thu, 15 Jun 2023 23:10:39 -0700 (PDT) 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=@google.com header.s=20221208 header.b=ew+f7NHQ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbjFPFsi (ORCPT + 99 others); Fri, 16 Jun 2023 01:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbjFPFsg (ORCPT ); Fri, 16 Jun 2023 01:48:36 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABE26270C for ; Thu, 15 Jun 2023 22:48:35 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3409d944009so67005ab.1 for ; Thu, 15 Jun 2023 22:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686894515; x=1689486515; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZwQw4AmMsj8rS1EO+I7cEg+kMMUbG54Oey3YjSE5diw=; b=ew+f7NHQuAVwZ6l9cHvNdo8Rj7TGVkbcYkaVPzglzvEspiDGM9BIAbB+nOI5BFRHxq O3Rz+l8/avezmgajTEW6WlveMWCuo7Sr9PZARD5tSs5Hw1qgqUVZKHszLzfE3fl+JdvV 8QrTUXpxABeNTDNnTpc8AiCLiEvexxY9J/480urLRwCoo9bCCMk3iqQ67OQpYXw5ZQWi g3RZ0eMDgMRMBaW5kOLu48MYKLnxD6Rr3YdTUu0oW7FlKFXy0i9oycnn1XuIU/oSPZPk kgKliKYW/phvNL/OBA2viXxT+OIREPXeEWyGZQUNlIUtqlBoy3G7pjpHEj9EuOYGyS9d YnkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686894515; x=1689486515; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZwQw4AmMsj8rS1EO+I7cEg+kMMUbG54Oey3YjSE5diw=; b=kb++3gOgmVfKhqPSrw4N2C/Sy/PQCQEbDwPL5KBwcjhkeI3gr1tDclYhlNaYvufnMu fNFOeMLa/NNSBFwin+QX8NU9mhrzW1UVpxGWYMOjAPaG5Qk9/lyTQr0jWL6tMt6idtJK tjiLeeMLiQPyQ82IxvWiEAFUbIVBLmOK+Z2c0hOE/yKu1T34y6fALizPCzylbHDeCHvP ey1EcYX6zZKRwNT48wuDv2nyxCWvwtMuCVQ7bZCMHOYfc9aL2L6AnSI3M2My4h2qanGn BB5DVa2bVBKdAvqU+VUcgG36rWIvqS3kntepiGyeCdWiHYPuPfdcP1aCTULhm93uLS2R 4xQg== X-Gm-Message-State: AC+VfDzUlyLo+QEzywWho6b8CCoRHe6ra6u0JN5yWiiGa2c0BWBQbXXM qYqguNoEmGos2M0RK0bEAPyEWCTzIDliNw6xHJdLfA== X-Received: by 2002:a05:6e02:12e2:b0:33b:5343:c1be with SMTP id l2-20020a056e0212e200b0033b5343c1bemr409461iln.29.1686894514956; Thu, 15 Jun 2023 22:48:34 -0700 (PDT) MIME-Version: 1.0 References: <20230616031420.3751973-1-kan.liang@linux.intel.com> <20230616031420.3751973-2-kan.liang@linux.intel.com> In-Reply-To: <20230616031420.3751973-2-kan.liang@linux.intel.com> From: Ian Rogers Date: Thu, 15 Jun 2023 22:48:23 -0700 Message-ID: Subject: Re: [PATCH V4 1/5] perf metrics: Sort the Default metricgroup To: kan.liang@linux.intel.com Cc: acme@kernel.org, mingo@redhat.com, peterz@infradead.org, namhyung@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, ak@linux.intel.com, eranian@google.com, ahmad.yasin@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Thu, Jun 15, 2023 at 8:14=E2=80=AFPM wrote: > > From: Kan Liang > > The new default mode will print the metrics as a metric group. The > metrics from the same metric group must be adjacent to each other in the > metric list. But the metric_list_cmp() sorts metrics by the number of > events. > > Add a new sort for the Default metricgroup, which sorts by > default_metricgroup_name and metric_name. > > Add is_default in the struct metric_event to indicate that it's from > the Default metricgroup. > > Store the displayed metricgroup name of the Default metricgroup into > the metric expr for output. > > Signed-off-by: Kan Liang Reviewed-by: Ian Rogers Thanks, Ian > --- > tools/perf/util/metricgroup.c | 26 ++++++++++++++++++++++++++ > tools/perf/util/metricgroup.h | 3 +++ > 2 files changed, 29 insertions(+) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.= c > index 8b19644ade7d..a6a5ed44a679 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -79,6 +79,7 @@ static struct rb_node *metric_event_new(struct rblist *= rblist __maybe_unused, > return NULL; > memcpy(me, entry, sizeof(struct metric_event)); > me->evsel =3D ((struct metric_event *)entry)->evsel; > + me->is_default =3D false; > INIT_LIST_HEAD(&me->head); > return &me->nd; > } > @@ -1160,6 +1161,25 @@ static int metric_list_cmp(void *priv __maybe_unus= ed, const struct list_head *l, > return right_count - left_count; > } > > +/** > + * default_metricgroup_cmp - Implements complex key for the Default metr= icgroup nit: what is the meaning of complex key here? > + * that first sorts by default_metricgroup_name= , then > + * metric_name. > + */ > +static int default_metricgroup_cmp(void *priv __maybe_unused, > + const struct list_head *l, > + const struct list_head *r) > +{ > + const struct metric *left =3D container_of(l, struct metric, nd); > + const struct metric *right =3D container_of(r, struct metric, nd)= ; > + int diff =3D strcmp(right->default_metricgroup_name, left->defaul= t_metricgroup_name); > + > + if (diff) > + return diff; > + > + return strcmp(right->metric_name, left->metric_name); > +} > + > struct metricgroup__add_metric_data { > struct list_head *list; > const char *pmu; > @@ -1515,6 +1535,7 @@ static int parse_groups(struct evlist *perf_evlist, > LIST_HEAD(metric_list); > struct metric *m; > bool tool_events[PERF_TOOL_MAX] =3D {false}; > + bool is_default =3D !strcmp(str, "Default"); > int ret; > > if (metric_events_list->nr_entries =3D=3D 0) > @@ -1549,6 +1570,9 @@ static int parse_groups(struct evlist *perf_evlist, > goto out; > } > > + if (is_default) > + list_sort(NULL, &metric_list, default_metricgroup_cmp); > + > list_for_each_entry(m, &metric_list, nd) { > struct metric_event *me; > struct evsel **metric_events; > @@ -1637,6 +1661,8 @@ static int parse_groups(struct evlist *perf_evlist, > expr->metric_unit =3D m->metric_unit; > expr->metric_events =3D metric_events; > expr->runtime =3D m->pctx->sctx.runtime; > + expr->default_metricgroup_name =3D m->default_metricgroup= _name; > + me->is_default =3D is_default; > list_add(&expr->nd, &me->head); > } > > diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.= h > index bf18274c15df..d5325c6ec8e1 100644 > --- a/tools/perf/util/metricgroup.h > +++ b/tools/perf/util/metricgroup.h > @@ -22,6 +22,7 @@ struct cgroup; > struct metric_event { > struct rb_node nd; > struct evsel *evsel; > + bool is_default; /* the metric evsel from the Default metricgroup= */ > struct list_head head; /* list of metric_expr */ > }; > > @@ -55,6 +56,8 @@ struct metric_expr { > * more human intelligible) and then add "MiB" afterward when dis= played. > */ > const char *metric_unit; > + /** Displayed metricgroup name of the Default metricgroup */ > + const char *default_metricgroup_name; > /** Null terminated array of events used by the metric. */ > struct evsel **metric_events; > /** Null terminated array of referenced metrics. */ > -- > 2.35.1 >