Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1283692lqt; Fri, 7 Jun 2024 13:29:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW0eyTVlowrKYWVfjkTUNEnMH3q966MoFaWJ/wNS/yhxox6tjV6PkpHCVg9muDd9pxm9nTmLGp5vTZDenKZ8BJy4Owi64yz+60761kzqA== X-Google-Smtp-Source: AGHT+IF9v65Zs3FEyvrzWB1SXR8sufAt0uS1Lb/QslUfGwf/XYBFA//J0TN9dpeSHp6s7L7W3IqK X-Received: by 2002:a17:90a:71c5:b0:2bd:f751:e184 with SMTP id 98e67ed59e1d1-2c2bc7d9869mr4069945a91.0.1717792182127; Fri, 07 Jun 2024 13:29:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717792182; cv=pass; d=google.com; s=arc-20160816; b=LIuILU6pgH+wlEQK42MVB4PvRKPqLk1SA1ih+O3NnyNmvRiG5yvYSulCGwYiLMBVoC 9txnDKQEdk4WZFHU50QTPBB9MmXmlrVR1qjcZjFqyyF0K4aCef3CSvZoLpd3sHLYkuuG Urv+3lQ7tME8OUJ144xfeTIS/GR7QRbvUKfz9NqJZ4iuqkJzeYjGUs8TLDhhQ6YrIlhS YOpcOr7f/tkb11Q+nV00e4qgKxehDEjbNnUkpk0hOlAXvzkQY17JijMr6rXVbX+cav8t ecIQ9N7oHJSLQVidH17cfgGZmH8B5HSfp5+F2N+AVUQH3EfknvZxPEhWzViZCmZ6G6Sm eTCA== 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=bOuGNXPPk/35OHhGOXA0NLhgzKeEiqw0kxSAjKxmbhc=; fh=VvmxeZa3Qe1p4ODl48ZXIELSHJLsywFHVgxPDK6aBdM=; b=QfEeQ0zloGAPcVCoQhAsoETKHC88r0AMbCfJMnV+kKUUcAAq5zf0I0sk5UK0WxqkzU P8W9wMQXKSBMAP0m5jVG+xVBNbW07XzIOwXt0zrmrQ/2PN5cqE8SnElWb12PApkKqiIz 1mEGqXOf76uDCdoirUfxZyIoU4vRTPvI8LX60Yhjep6kJLG+uU4jF4KyhaN1mCdcm1mq Q84R/ny9InFdqHrX7SF693BAeKpR6+v1cHCpPmxkgex06+I90w4rtfv937XlrRllax2e QowKR2WTnT2evX0ncdqj+IOwnEbp3osTZO7h4dqbPHxVkTn0iNL8ZvLrhFDC8UkKi1bt fv/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iVK5dgGy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206705-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2d0e2b281si881776a91.1.2024.06.07.13.29.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 13:29:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206705-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=iVK5dgGy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206705-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206705-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 1E93728A4CF for ; Fri, 7 Jun 2024 20:29:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9D20154BE4; Fri, 7 Jun 2024 20:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iVK5dgGy" 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 E720814F9E6; Fri, 7 Jun 2024 20:29:20 +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=1717792161; cv=none; b=qdoTv2/WM8f648iC26/bLFidC+8HbQBj+5oHBLbDk9CAxYFeoyGLpoBw20EH8Yuq9VB1Axzwnc9ovuqIIjdDvCGhFXtGdikzCnqe2UbA6nJhIzb3IkL/ClehZxpB6Swtm7W3vry+alh7F+2ykWZooItnKZXNGJ7Za1TOV6cSZ1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717792161; c=relaxed/simple; bh=xXti8bLSkXlSV64cAc0cnIOYVS1QeNw8TsTY2C0Saao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uFpgtVlGLvBVPRSRkqffJwjfKCvKiADWdjWSkcCJM9FJczD66cDZEAphN2wzzZg4yyXYz0YHMgP9j5frdNV9kTPkyv66cT6RNZIuIuTo3e3n99/wLVv0/NS4oSwBDE7EY5S1w3g6P2x32nwpsaXZr9zA7wphB/uO+M2KQHz5KKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iVK5dgGy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DC54C32781; Fri, 7 Jun 2024 20:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717792160; bh=xXti8bLSkXlSV64cAc0cnIOYVS1QeNw8TsTY2C0Saao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iVK5dgGypnZXiwuPVfKv978Ag9qXUdW7nSmBok7TFN0yB+V+ITPvNdr0rOGfXk+3q hmuP8DTb4bg/wVDPg5f66qsYkKwqJkMsdlibswjXrPMUrpOxl02i52+z8+UQa1qJuV G58Wm/oaP2ZpqsVbp067MvU0+cbrZvmv09ThU5Aao27UAcYzhDB2ka2uhU4qQiUQ1s ydrOhU/BeNaUm64zrYgGGC582ccDEU+AQ6//2HuMpL/nKV/3JKavRWFoRt05dLO3ru z+c5BsNiAm+cnRXNGG3MBHXWYp7UF5dgFwKOtqIQDmblJ+GC2Usg7NHp+LHu0vQ2j/ VPoC82kDGVKtw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 2/4] perf hist: Simplify __hpp_fmt() using hpp_fmt_data Date: Fri, 7 Jun 2024 13:29:16 -0700 Message-ID: <20240607202918.2357459-3-namhyung@kernel.org> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog In-Reply-To: <20240607202918.2357459-1-namhyung@kernel.org> References: <20240607202918.2357459-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 The struct hpp_fmt_data is to keep the values for each group members so it doesn't need to check the event index in the group. Tested-by: Arnaldo Carvalho de Melo Signed-off-by: Namhyung Kim --- tools/perf/ui/hist.c | 75 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index e30fcb1e87e7..7e863cd92781 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -46,65 +46,62 @@ static int __hpp__fmt_print(struct perf_hpp *hpp, struct hists *hists, u64 val, return hpp__call_print_fn(hpp, print_fn, fmt, len, val); } +struct hpp_fmt_value { + struct hists *hists; + u64 val; + int samples; +}; + static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, hpp_field_fn get_field, const char *fmt, int len, hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) { - int ret; + int ret = 0; struct hists *hists = he->hists; struct evsel *evsel = hists_to_evsel(hists); + struct evsel *pos; char *buf = hpp->buf; size_t size = hpp->size; + int i, nr_members = 1; + struct hpp_fmt_value *values; + + if (evsel__is_group_event(evsel)) + nr_members = evsel->core.nr_members; + + values = calloc(nr_members, sizeof(*values)); + if (values == NULL) + return 0; + + i = 0; + for_each_group_evsel(pos, evsel) + values[i++].hists = evsel__hists(pos); - ret = __hpp__fmt_print(hpp, hists, get_field(he), he->stat.nr_events, - fmt, len, print_fn, fmtype); + values[0].val = get_field(he); + values[0].samples = he->stat.nr_events; if (evsel__is_group_event(evsel)) { - int prev_idx, idx_delta; struct hist_entry *pair; - int nr_members = evsel->core.nr_members; - - prev_idx = evsel__group_idx(evsel); list_for_each_entry(pair, &he->pairs.head, pairs.node) { - u64 period = get_field(pair); - u64 total = hists__total_period(pair->hists); - int nr_samples = pair->stat.nr_events; - - if (!total) - continue; + for (i = 0; i < nr_members; i++) { + if (values[i].hists != pair->hists) + 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 samples, pair->hists is not correct but it's - * fine since the value is 0. - */ - ret += __hpp__fmt_print(hpp, pair->hists, 0, 0, - fmt, len, print_fn, fmtype); + values[i].val = get_field(pair); + values[i].samples = pair->stat.nr_events; + break; } - - ret += __hpp__fmt_print(hpp, pair->hists, period, nr_samples, - fmt, len, print_fn, fmtype); - - prev_idx = evsel__group_idx(evsel); } + } - idx_delta = nr_members - prev_idx - 1; - - while (idx_delta--) { - /* - * zero-fill group members at last which have no sample. - * the hists is not correct but it's fine like above. - */ - ret += __hpp__fmt_print(hpp, evsel__hists(evsel), 0, 0, - fmt, len, print_fn, fmtype); - } + for (i = 0; i < nr_members; i++) { + ret += __hpp__fmt_print(hpp, values[i].hists, values[i].val, + values[i].samples, fmt, len, + print_fn, fmtype); } + free(values); + /* * Restore original buf and size as it's where caller expects * the result will be saved. -- 2.45.2.505.gda0bf45e8d-goog