Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2898221rdb; Mon, 12 Feb 2024 23:53:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRAjLCjXglYuZf1MxB2yYo+U7d0MOYqW+I/iLUyE6pSw/e20OvAzNpfAie0qZ0WRe8Qr0m X-Received: by 2002:a05:6870:b69f:b0:218:f5f2:a4a0 with SMTP id cy31-20020a056870b69f00b00218f5f2a4a0mr8952111oab.59.1707810815645; Mon, 12 Feb 2024 23:53:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707810815; cv=pass; d=google.com; s=arc-20160816; b=0XVYWvGP0PmPTJ/BCjGj8QI3/tYoajtVepGrCJ6ciWekrtv4f21R/T9wlwsbqox4gh w2C9PEID+FjF8UKuVW0IxDCp0P45sFjlQNjIV0zJPfobECvgZQK9nIumZrD3U9hpy3xT R8sNP2PAxrTQlxjrCUv0FAkokTPsA+XHRU045HIyS7/GfujkXfLmy5NC6GRMg+f7LioY fEcY0ycJomgKwAG8odum2j0D0W1JK3QRi62s8INDhOQK//NJV8zYnbWlz84jYRZR+arJ /HUrcRKwMTDDzQ42eGz2bM+Vw1f+xkpsHUX/4OYih5RwYqN1//VaANI+8PFUYWgkQMG6 fJKg== 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=icUOIUv5aPxp/XDHfMIYwPdOZUziOwrmgWjtBk/AqOQ=; fh=IIolhnp5HRgCscabXwxprZl02jkcJKlDH8bD3hJZ0ns=; b=BVfrPP1KqFH/Gl4xEksIQ+dugA1EY04ctRtW6HE8Y9Mc3u63QafQ1nWGAE9OBj7oCF t35ZzPKOICjnKShkPduYZMRmBflXG/0tU13bTT5gtuBssw0BLWShUdCU1wCrogK1a3eQ OCRVLWxToAiFTJdfjNYo7+eLWkhxe+7jnqEzHS0u8jxqz6SPARrVmjXfP8nDQi16Bju2 Ce/DB3NWrDz53LlAIvpKsWQTKJb6h5YGUh+lPg8wlKpzOkDLS8dxZ0gmQ9U4OlJbLNiF evbtO/BtdczLzQ8EhBH0iTPgV9KGjPn9RoVd41hrs9JaSs2JjR/qwr/ogKqrdEXgeVca NcbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5Ia39o+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUX1PjfLr0cnkP8RRNu1N8EB2cZlIXV34hm5VQ0tSF2LVV69S8J1O+cR/SWnx05dEl15K55nDJEo5FXyqpBJgJtWWOvUWn43wNsO8SsLg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s22-20020a639256000000b005bd27be66e1si1594880pgn.719.2024.02.12.23.53.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 23:53:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5Ia39o+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-63063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63063-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4B5F3284073 for ; Tue, 13 Feb 2024 07:53:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91AA01B263; Tue, 13 Feb 2024 07:52:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i5Ia39o+" 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 BC511182CC; 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=1707810778; cv=none; b=Qmj0JJAM0rGR+b6masr7DUMgKBLPTjbPW2lafdTVbBq1QezV6XDY70r52jcb0/Npa8iBeDtYZAPf4tyYBf99zVlkWjGcf95rcyiL0kHdGtzO1F7IeVH74WX5u2Rss1/eEeXumGhVw49S8mqv8A3TBZwZa5U5kJ0V55YBRsY7HGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707810778; c=relaxed/simple; bh=jcUZpV1neXzu3Kp6ToaOsDKLDERo3W3oIzclMpmzJ1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6kkniChvGZSdi5VVxgfzE51psLK6mzs3T8EoX7hn0F0Je+nxV8EPnn5mUXWCEPXpHM7Q6NC+B9hfT1On7qg7/sNkEqnBSwcc0gBw4jL6q3VE8TLeV2mAKZkRyAzOUf70k3jQY1azSmkIjVyjvXazvxioQq2BZK8qH0P9flyff0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i5Ia39o+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECA87C43394; Tue, 13 Feb 2024 07:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707810778; bh=jcUZpV1neXzu3Kp6ToaOsDKLDERo3W3oIzclMpmzJ1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5Ia39o+UXgoq87UnC132bdO3AXQ/WuaXkeWlK28XRnlkd37wk+R3d77ML+/2HZXO xhyxDBLbmlMFOQ/mAig9LIK643sPl2voIr9p5JWunqnslc6uj4iWmIkvEQPsmPkh/Q RbwNcFT3chwNv8hn17yABArqTYfI8QXSUkBVh6b9vOAG5d+4UTyJRIlw71ub9f5rq2 8qhrb5z9kAV/TRiZUQQI68JIk+DH4I3KR8cFIORO7a/dh60UcJ9XJNvciWZaa4J7e5 XuM20i5nEhyC9K7JgrZ7OkMZ9kiXS1I2qR9WzgLrM20VvfMfKbp9y5UWk7ycm7Nyrk lF9UQIbCnv3cg== 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 2/4] perf hist: Simplify hist printing logic for group events Date: Mon, 12 Feb 2024 23:52:54 -0800 Message-ID: <20240213075256.1983638-3-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 Content-Transfer-Encoding: 8bit It can uses an array to save the period (or percent) values for member events and print them together in a loop. This simplify the logic to handle missing samples in members with zero values. No functional change intended. Signed-off-by: Namhyung Kim --- tools/perf/ui/hist.c | 55 +++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 2bf959d08354..5f4c110d840f 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -33,6 +33,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, char *buf = hpp->buf; size_t size = hpp->size; + /* print stand-alone or group leader events separately */ if (fmt_percent) { double percent = 0.0; u64 total = hists__total_period(hists); @@ -45,12 +46,19 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he)); if (evsel__is_group_event(evsel)) { - int prev_idx, idx_delta; + int idx; struct hist_entry *pair; int nr_members = evsel->core.nr_members; + union { + u64 period; + double percent; + } *val; - prev_idx = evsel__group_idx(evsel); + val = calloc(nr_members, sizeof(*val)); + if (val == NULL) + return 0; + /* collect values in the group members */ list_for_each_entry(pair, &he->pairs.head, pairs.node) { u64 period = get_field(pair); u64 total = hists__total_period(pair->hists); @@ -59,47 +67,26 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, continue; evsel = hists_to_evsel(pair->hists); - idx_delta = evsel__group_idx(evsel) - prev_idx - 1; - - while (idx_delta--) { - /* - * zero-fill group members in the middle which - * have no sample - */ - if (fmt_percent) { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); - } else { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); - } - } - - if (fmt_percent) { - ret += hpp__call_print_fn(hpp, print_fn, fmt, len, - 100.0 * period / total); - } else { - ret += hpp__call_print_fn(hpp, print_fn, fmt, - len, period); - } + idx = evsel__group_idx(evsel); - prev_idx = evsel__group_idx(evsel); + if (fmt_percent) + val[idx].percent = 100.0 * period / total; + else + val[idx].period = period; } - idx_delta = nr_members - prev_idx - 1; - - while (idx_delta--) { - /* - * zero-fill group members at last which have no sample - */ + /* idx starts from 1 to skip the leader event */ + for (idx = 1; idx < nr_members; idx++) { if (fmt_percent) { ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); + fmt, len, val[idx].percent); } else { ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); + fmt, len, val[idx].period); } } + + free(val); } /* -- 2.43.0.687.g38aa6559b0-goog