From patchwork Tue Feb 13 07:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 200253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp383902dyb; Mon, 12 Feb 2024 23:54:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIBkZfjfOSC+4a0Edl23dIUdfpFiWtI2EoUORBLONy8fQNV3lBkxXPq14q/KRwYSJbm6U8 X-Received: by 2002:a17:906:b208:b0:a3c:bb37:a676 with SMTP id p8-20020a170906b20800b00a3cbb37a676mr1585066ejz.9.1707810866891; Mon, 12 Feb 2024 23:54:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707810866; cv=pass; d=google.com; s=arc-20160816; b=URVv0KbmGrEeTAteRwvYeFwJhhxdGXDjLu08Nyrmd3+XM3YDLeNC0SsDAODVdFshAR XTx4oaVZm8kzffk9lts8AN/cQbMhgQ1jb1XZrU1SkSz0iEwmRNgFvCs8z8DhmlKWyuiS OFVAZ4PlAkq9+C04fYyLkJOIT/YdO4rsy0+6Wpop7+LR+aGcxz0AazAnFhohrVteDiF5 t5T8H7ufbKpEyWWhAqN1Swojys2qVJ7H/3NkUUvzUBP1E7HCZ42H9oTV9olj3TCAzjDQ i8GN4w34i1pjPSNPgMNa2w4S5QEX1+AqI4PvMmcev2yXGiV+BxJr0W0XBxE6ouRwvLud EudA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9SEbukrbA/HS3Yv+8R7Y5N1FpordbRB0wYABigTmuEE=; fh=g3Rr4Au5chWCIlZGOxuxly969VQqHHxllh9FJ0fxSLQ=; b=r2JLskwbrDZ63Ql5u+GwBo+CSaJWaeVkbeK8OZnpQtiTCUJq59KFNIO7eL6yLlUCmL rELwd0bemNjMYKwHOtooTMizWj0ZMb6T7GtKiaSxfH2TLBVenrkSkLn+V74w7ZzdOpKG dz3yoFv3FwMO5S3i++2cyX9AueThxuBNwyO78LGIHGyrCnXEViR3YqNQkKUjpm6jokxU oq/NF3cJSMsW0OArJX0OmjhZOOGGWtDP9X9p+snBbNDntdtpbqfGI6+0Z3XIsxGcdBl3 2lqyB8ar1elHVMqyayQkECwSm18IK/XVyULC6nE91TEqwBD4MCz1To7brjHuOU650tSK 8JdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nnufl34i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63064-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVsbcOfKLR8I9yJnIBmWrNL6ugNGHYe7bF4Ob+5XwXIZtb7ybeQFvf0Xm0xxGBEz90/pyovR2GsKt95UtXrEPG5ZvwzUA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g26-20020a170906199a00b00a3cf4e76e06si575158ejd.446.2024.02.12.23.54.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 23:54:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nnufl34i; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63064-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63064-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 81FBC1F22957 for ; Tue, 13 Feb 2024 07:54:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9E5D224D6; Tue, 13 Feb 2024 07:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nnufl34i" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4427618C1A; Tue, 13 Feb 2024 07:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810779; cv=none; b=KD5FNiac0OF0mScWSFCXr8pU8yLyGmsoD1vDJaOwUz/4LaDv0EGviS+O5vJpMbnngvQOULG7d9kha9YfzL6/oVjDnt48nlDbz/+UKuQbXK8SHetnK9sBRVl6sWaWUly3uT+Ymc3nYaxumvqAPW2lgt0pdDzanx4dqlKzkhifaVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810779; c=relaxed/simple; bh=/cAFvtSoMi2WFvvFOaWCdmF3lcgANJyG3cErhVuBZ3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G8ul/i2vhAcX4hpxsQuAnRBTsa8VipPNyHguDrC3noTZB5ppejSJ+0Sm/jVOvtCUL4ZY4Xyx9aRwg55vhGU1P+R0LjHtlZonhz+3LBNZOkZz+1lJRuwSYg9xFhubBahXL+RbYfP2m0cfxTGIOjnj4MM+CjbuIh5qtyMU0QCgO8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nnufl34i; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67A32C433C7; Tue, 13 Feb 2024 07:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707810778; bh=/cAFvtSoMi2WFvvFOaWCdmF3lcgANJyG3cErhVuBZ3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnufl34iNC3PJN5Ds6rRUdfaW5U9p2ah3WGrMWoIOVvx6meTPJyvRYbKJ2VaWyEpW JwENBqr0ykiQo0dWSIrefm/0Q3hCBelXViKWu6WnXs1/D+eQxTjCDrspxoXrf5EhhM hkT0uEhvSSnwieywqmxuphXVUYOrios9WcUb1q/hxbZx5KmVcJf1FVVuBL7NihNQp6 fYsmE51MaZ5UWNh3X63jbf74uJzpBmpXClyoZPS6grNXRnBwGCjhjqkr5zPfys4DoT ns/e68RUr2CY0OTxJ/F0Ospavzi4qyYapfM7i+OnslVuD/yU1rBP9yPRbnI3Oreubc snyzjTj+UcECQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 3/4] perf hist: Do not use event index in hpp__fmt() Date: Mon, 12 Feb 2024 23:52:55 -0800 Message-ID: <20240213075256.1983638-4-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240213075256.1983638-1-namhyung@kernel.org> References: <20240213075256.1983638-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790769487809479703 X-GMAIL-MSGID: 1790769487809479703 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. 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 hist_entry *he, if (evsel__is_group_event(evsel)) { int idx; struct hist_entry *pair; - int nr_members = evsel->core.nr_members; + int nr_members = evsel->core.nr_members - 1; union { u64 period; double percent; } *val; + struct evsel *member; + struct evsel **idx_table; val = calloc(nr_members, sizeof(*val)); if (val == NULL) - return 0; + goto out; + + idx_table = calloc(nr_members, sizeof(*idx_table)); + if (idx_table == NULL) + goto out; + + /* + * Build an index table for each evsel to the val array. + * It cannot use evsel->core.idx because removed events might + * create a hole so the index is not consecutive anymore. + */ + idx = 0; + for_each_group_member(member, evsel) + idx_table[idx++] = 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 hist_entry *he, if (!total) continue; - evsel = hists_to_evsel(pair->hists); - idx = evsel__group_idx(evsel); + member = hists_to_evsel(pair->hists); + for (idx = 0; idx < nr_members; idx++) { + if (idx_table[idx] == member) + break; + } + + /* this should not happen */ + if (idx == nr_members) + continue; if (fmt_percent) val[idx].percent = 100.0 * period / total; @@ -75,8 +97,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, val[idx].period = period; } - /* idx starts from 1 to skip the leader event */ - for (idx = 1; idx < nr_members; idx++) { + for (idx = 0; idx < nr_members; idx++) { if (fmt_percent) { ret += hpp__call_print_fn(hpp, print_fn, fmt, len, val[idx].percent); @@ -89,6 +110,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, free(val); } +out: /* * Restore original buf and size as it's where caller expects * the result will be saved.