Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp147169rdb; Wed, 14 Feb 2024 16:08:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWgTG4CSFLQZR9miLaWmc1InHVwssGGnmnqJs03c0wo0HarMp7st6ltiBqlYFeFGsmgp9Nn2NYQk7lqXsBVULkAWOlDdn9X8GMf4G1z1Q== X-Google-Smtp-Source: AGHT+IFULx4OydcDhJA+mM+TbLRWa1lle/81XujMwxKrsc9ZJJ8ZKhkQGljDdwAuvsKYoU/i6CKe X-Received: by 2002:a17:90b:3107:b0:298:bc6a:7849 with SMTP id gc7-20020a17090b310700b00298bc6a7849mr276743pjb.32.1707955724694; Wed, 14 Feb 2024 16:08:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955724; cv=pass; d=google.com; s=arc-20160816; b=mP4K5f9R1WbSuTSeTYrzvPFBYl2TtvNSV6BFyBN+A2cJzzyJPmuzIR0JPWy2t5FXOs 0gnRXJ+NTewNB89IoD7LlcRwmsNY93IBOQlqAWNfq+dn5TcGDoySsCH569TgElobVRD+ wpDzeYqH7hS+2lheMW4XtBMXGwtqowvl3nTgBv79dJt54/HKIE8EmfR1pt/eSeeflF6c oOXbzXkrembp1Lu/xusHXn25ap3rSilbU0XUQkSGgwqCwflwUieu9gIGjQla3C/Ke61W Q3FbaV6XX3e6l/+U0ppsrAB6RuGg/t+htZ/1WhupjGyjsFDMkkzIbFHcaqqP+gCKOO3Z GB2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=jYW5x9I6IoVVyZN2S5QMODnYnRF6g1ixxb2U6BARuiA=; fh=2+JRH6HPmw5Z9Rdm8vbCtSWsBC7mhr/svu2wgGG/GGc=; b=B1K4VvIK5j5wo2QrtQnL4w41tgpP4Htf+ZWqsFm8iDD9WjihItLeU/dqg9Y0hi1mf/ zAjIR3W05mj9ZZsgkLmh8XSh7Apci23uRNp7Z7OYyjBFeDFdv9Jb1kKh9EY/3uZwsuYu JKmJ61ZHtzEi8edtq20Pjj7zrjIK2aaswsUONDdFwThsjLK3v8pGouroR7G7gL2Mpe2e emXdCPw9d7pePoQY+LJ0x485lOjbYufSlhs9DZd3l9kyZODRo8Mz8vwmow7f9gZuICjy AxDkVdQAjixYvxUZRGmD12WJm65avrgO7bzn/TFJ7u55+AxIHiie+O2JTHy025DFu9lm m+SQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qxWdQe4a; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-66177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j71-20020a63804a000000b005dc529b708asi22841pgd.743.2024.02.14.16.08.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 16:08:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qxWdQe4a; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-66177-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66177-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4AC5A28181B for ; Thu, 15 Feb 2024 00:08:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8267C1C06; Thu, 15 Feb 2024 00:08:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qxWdQe4a" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF52F19A for ; Thu, 15 Feb 2024 00:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707955706; cv=none; b=GzRGqj9LJI0BzkshvMpdCkqzIZSjAMA2GinglqvXC1vHheEopIBaPB3aICRfbqT39pHZ1B5+KzjaWyQlX4vCNO+NRb2KrKfKMXRju1MSNKHN0A6lYrQnO/6ykmVPx2IrkjKmzLRc4VtUcbblYByy1zQSIRn+gZQyNID1mfIBM+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707955706; c=relaxed/simple; bh=eRVr7WNQeECFAwC9LL6F7iVBaxb9s3Hq0tVpyIkyaTE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=R0TlSYlbBjzt9cnosvrun8X3CTQpCwABVCahlpsIvBTBir657YoirZuwUdAL+D1m2qiyDIVVWQ5Kmy8/BQ03kJPnoGbH1qOAF9r6H5EamZVO68DUi2lnu1WNmSa45tcc9mnuDOtDIIrNo9XPCx5zjws/s2Ku8YbwEZ7KPmWbvCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qxWdQe4a; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1db35934648so34485ad.1 for ; Wed, 14 Feb 2024 16:08:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707955704; x=1708560504; darn=vger.kernel.org; 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=jYW5x9I6IoVVyZN2S5QMODnYnRF6g1ixxb2U6BARuiA=; b=qxWdQe4a3p/nqAb1IJVCef5AYMFjJ1IZOdMRn2MJpzR3AZjgFf6CoX2V5vL7lVmFJa +MqsYyMdSO3E2C79bDse8XIe9qJQn5j4IqOegaUQ8FEpeP06sXfaL5GimRPElU7fqI6+ xrrhtackXZ+tqi3d3+621cDh/zmGGW/zcNWD+DymUPKLZSjqZq9dA4APZH8oTFupYWlp fXMrgE7X2q9UOjzsqgZ5J4sPi0TpWSXw3XXZmH7uJ1mAgkTYz+gk8y6QjJAEk4rSLe/0 nzKj6d8RtTGbj9mUNbiAz+CH1bs9KL8OOwTgcBT9LtA4pstF3km68/gsXAvdtq22m0vs IJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707955704; x=1708560504; 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=jYW5x9I6IoVVyZN2S5QMODnYnRF6g1ixxb2U6BARuiA=; b=D0Q/BxnxEgvm9YWOg8lFAd8qIqsrja9wOYPFnZ+JMHztuVHXodmzHm8FmucCe3wO3u WhEkAT5Iv0qJAcmTT8zo3BNiuWuh8Q8ISTK30l5m9yY2aH34/yNLFNoX7UdndcjFiw5Z f4pIWXJteGWN16BRlXQvOjiwhCstuNcWCd7CfP+M2TNewMr0GNvxuWzFJputa3vQK2MP vrSkl8Vdy/TWZR24HrZMx/+++vDGiNzZaagrfmdmx2aZZ1H6PDELnFZMp1OqLQ0HV74R 07lRWPYlgft8zjiHEzU7Ujb5YKbqZLu5qHOQTq+OlgFaV0Mni6v0FAuiJEa5E2L8ca5A cPrw== X-Forwarded-Encrypted: i=1; AJvYcCUx4YHJs0hl/aQM/zVrRlOOzM2rDaUDa8yn7QtzUDF3aIq3E8lpTo2Q4tCBzohTw2oC876525xN93BonOdVAoz0lO9OLNo+r5zKOgZF X-Gm-Message-State: AOJu0YySzRyn4TZXnise3hbofR+7jlqNU0oGRGWDGqFd4rEf6UCN4R/N HH50G3bI1hQyZpZBbMVkKPyzu/wCxYpfJR6xFnab5jfcois/7wIMXcY93sWzMGOqgDkVVSAi+Yg e64YIfZJiCpNcw/wEKW8qxr5RbsNI1H9c9BOT X-Received: by 2002:a17:903:22d1:b0:1d8:e076:21f3 with SMTP id y17-20020a17090322d100b001d8e07621f3mr434878plg.2.1707955703980; Wed, 14 Feb 2024 16:08:23 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240213075256.1983638-1-namhyung@kernel.org> <20240213075256.1983638-4-namhyung@kernel.org> In-Reply-To: <20240213075256.1983638-4-namhyung@kernel.org> From: Ian Rogers Date: Wed, 14 Feb 2024 16:08:10 -0800 Message-ID: Subject: Re: [PATCH 3/4] perf hist: Do not use event index in hpp__fmt() To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 11:52=E2=80=AFPM Namhyung Kim = wrote: > > The __hpp__fmt() is to print period values in a hist entry. It handles > event groups using linked pair entries. Until now, it used event index > to print values of group members. But we want to make it more robust > and support groups even if some members in the group were removed. I'm unclear how it breaks currently. The evsel idx is set the evlist nr_entries on creation and not updated by a remove. A remove may change a groups leader, should the remove also make the next entry's index idx that of the previous group leader? > Let's use an index table from evsel to value array so that we can skip > dummy events in the output later. > > Signed-off-by: Namhyung Kim > --- > tools/perf/ui/hist.c | 34 ++++++++++++++++++++++++++++------ > 1 file changed, 28 insertions(+), 6 deletions(-) > > diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c > index 5f4c110d840f..9c4c738edde1 100644 > --- a/tools/perf/ui/hist.c > +++ b/tools/perf/ui/hist.c > @@ -48,15 +48,30 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hi= st_entry *he, > if (evsel__is_group_event(evsel)) { > int idx; > struct hist_entry *pair; > - int nr_members =3D evsel->core.nr_members; > + int nr_members =3D evsel->core.nr_members - 1; A comment on the -1 would be useful. Thanks, Ian > union { > u64 period; > double percent; > } *val; > + struct evsel *member; > + struct evsel **idx_table; > > val =3D calloc(nr_members, sizeof(*val)); > if (val =3D=3D NULL) > - return 0; > + goto out; > + > + idx_table =3D calloc(nr_members, sizeof(*idx_table)); > + if (idx_table =3D=3D NULL) > + goto out; > + > + /* > + * Build an index table for each evsel to the val array. > + * It cannot use evsel->core.idx because removed events m= ight > + * create a hole so the index is not consecutive anymore. > + */ > + idx =3D 0; > + for_each_group_member(member, evsel) > + idx_table[idx++] =3D member; > > /* collect values in the group members */ > list_for_each_entry(pair, &he->pairs.head, pairs.node) { > @@ -66,8 +81,15 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct his= t_entry *he, > if (!total) > continue; > > - evsel =3D hists_to_evsel(pair->hists); > - idx =3D evsel__group_idx(evsel); > + member =3D hists_to_evsel(pair->hists); > + for (idx =3D 0; idx < nr_members; idx++) { > + if (idx_table[idx] =3D=3D member) > + break; > + } > + > + /* this should not happen */ > + if (idx =3D=3D nr_members) > + continue; > > if (fmt_percent) > val[idx].percent =3D 100.0 * period / tot= al; > @@ -75,8 +97,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist= _entry *he, > val[idx].period =3D period; > } > > - /* idx starts from 1 to skip the leader event */ > - for (idx =3D 1; idx < nr_members; idx++) { > + for (idx =3D 0; idx < nr_members; idx++) { > if (fmt_percent) { > ret +=3D hpp__call_print_fn(hpp, print_fn= , > fmt, len, val[i= dx].percent); > @@ -89,6 +110,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct his= t_entry *he, > free(val); > } > > +out: > /* > * Restore original buf and size as it's where caller expects > * the result will be saved. > -- > 2.43.0.687.g38aa6559b0-goog >