Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1256494lqj; Mon, 3 Jun 2024 15:44:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV4AAKwwm0Mc5rH88h6bKGvf+NM9AXdh+v/7C7Izx3VfwqluqTbvwXEbLbgK7mUvejOg16ROTyOBqSEjFCIpnG1L9ZHWnHSO6Y9UfSNzw== X-Google-Smtp-Source: AGHT+IF4CXzM7eiSV6cuFxEZocevWhEeWFl340AFEz94QSP5RfYIjKnJefiIV/e1tJmO/eQcUIGF X-Received: by 2002:a50:9ea2:0:b0:57a:7885:433d with SMTP id 4fb4d7f45d1cf-57a78854378mr902641a12.38.1717454673431; Mon, 03 Jun 2024 15:44:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717454673; cv=pass; d=google.com; s=arc-20160816; b=gz8TXuKQPpoET60mYlw2V1rqmHcUA/r1NDxhuU1V8FfOO2H88s5A7N2GBIZDmfIuZT CdrSeJNODbs9maA9YkDBx74YaXx9xGOtqW3wWfm6QfhsatifBsXV+FqOy7CNZnrSlC3P FY9kEzEOEi9xlpDmta0o844oPgvjxLsCDYzoEahFAaV8tF9ImK70H1MKIZLKjNg405KL ZChDPdaxE7bTbFbwYJgrXFWGNFHecGkovocT3OIm0sj0EYNkM69VAZ+OUFNQvibVDsxt JrpmQXpZsFWya9TYfEcCNge1VBalY1lbzJaqRtRuEJLBkgn+Y9aeZ1lu7RILgCf+b2dy f3qg== 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=LqtmRnIBqPDnOTwdOT56/KknR9KVMRLSubPIZ49xfa8=; fh=fHhbvXgCev/wpffLVpfaAi8pPyv7hrTyhVPgsZ7HNrs=; b=oE8nvHwJKELxdTohxu6vEsJ3mjJX/OQv57kl/zCsSpox13sKfyV1Ca935CNBIDKsfr S5iDEs7snBT/rRGFrdYqr9UqjZDEB0MyXKzBr/g3WF149RdmxS53+HpEwu9G08uZvslN O+QQM2fIEz22Il/CHm+HADeNxd5A1OD7cbB0EUrcuGOsM/SgTEm72pvF6RZJIrdH592b MnaG1M/VbYs58G6bSv2P73tdOL5F/kxEzfblwMOnowab3nK5n28liWV9vwu5kLUQhiYA uq1qbhXem5CFv3OydlCRc3GFylPxvbooNHfDvygrPnIKwWaihYrXX0DW/xJKKfz7aMro kNvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UaUcSg8h; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31b80e19si4562315a12.73.2024.06.03.15.44.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 15:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UaUcSg8h; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-199788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199788-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 296501F2278E for ; Mon, 3 Jun 2024 22:44:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE42C13D25F; Mon, 3 Jun 2024 22:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UaUcSg8h" 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 D68E713CF97; Mon, 3 Jun 2024 22:44:14 +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=1717454654; cv=none; b=cwypVuqoxaMerZ2ZtHZvPDTbvpSQ4QP6VvbOQjLgSHRcnzGW3EfXMkKpR0mohcYGudbCTc20HEQ++Kt1HzkJ3zI30hVpmTkEYv4rA+DdpVg3vPN0E5c1NLu6APrYNZI1UDHZnJIM8O+NNQUeYkO9SpG6SyWXBqhBr8KopGejfnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717454654; c=relaxed/simple; bh=TdJfb4b0EK7Er1ltY544EIHAZOToWommLg0CWKrIXRE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pcFJgSAYXTMviru9A/bDagK6glHervOWUt8aR6+TCzUC5VWLxNbuQ1tBrBPG3i4BLE7wulrieMZXvRIwmKhxTp1COPaVm6WkawtlKdmqIFbWouFbRFEkNZCLlbDCnhLMBLXUkudHplS7T6CHY3ogWJryGz9RpcM6Y48ivViLBDQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UaUcSg8h; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B475C32782; Mon, 3 Jun 2024 22:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717454654; bh=TdJfb4b0EK7Er1ltY544EIHAZOToWommLg0CWKrIXRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UaUcSg8htavfY3pUGIgBMBi7dgY+GqzZOKLr0qz7IQu3MB+ZU9At1vvdEcnvNVj4E tWJopEz+ZRc0xL/JyieuLGFGYCSS33XJCYVIksflKM7BJ77NOFjJGcYcWTdClXJR6X OpWO4sVwIt9YrizsR1ltW5mofhn62XTp1WigrdTXqAGXl5/Q/Pp56XOSnhxQY+G2uq sLt++gPesjV4QZN1QHELdPDyESWpL8Zf6eTwlQk7Q9vSYojYxvSBJ8WnUkgW13jutC hOmzDKYQ7I/tUrZ8a8yoeMfGdzRd/fmkval5+4AUPDE6Bp5KIAqkUTfxl1ufaxLHL0 e8L2dtnSj2YKA== 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 Subject: [PATCH 1/4] perf hist: Factor out __hpp__fmt_print() Date: Mon, 3 Jun 2024 15:44:09 -0700 Message-ID: <20240603224412.1910049-2-namhyung@kernel.org> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240603224412.1910049-1-namhyung@kernel.org> References: <20240603224412.1910049-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 Split the logic to print the histogram values according to the format string. This was used in 3 different places so it's better to move out the logic into a function. Signed-off-by: Namhyung Kim --- tools/perf/ui/hist.c | 83 +++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 685ba2a54fd8..e30fcb1e87e7 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c @@ -23,35 +23,42 @@ __ret; \ }) -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) +static int __hpp__fmt_print(struct perf_hpp *hpp, struct hists *hists, u64 val, + int nr_samples, const char *fmt, int len, + hpp_snprint_fn print_fn, enum perf_hpp_fmt_type fmtype) { - int ret; - struct hists *hists = he->hists; - struct evsel *evsel = hists_to_evsel(hists); - char *buf = hpp->buf; - size_t size = hpp->size; - if (fmtype == PERF_HPP_FMT_TYPE__PERCENT) { double percent = 0.0; u64 total = hists__total_period(hists); if (total) - percent = 100.0 * get_field(he) / total; + percent = 100.0 * val / total; - ret = hpp__call_print_fn(hpp, print_fn, fmt, len, percent); - } else if (fmtype == PERF_HPP_FMT_TYPE__AVERAGE) { - double average = 0; + return hpp__call_print_fn(hpp, print_fn, fmt, len, percent); + } - if (he->stat.nr_events) - average = 1.0 * get_field(he) / he->stat.nr_events; + if (fmtype == PERF_HPP_FMT_TYPE__AVERAGE) { + double avg = nr_samples ? (1.0 * val / nr_samples) : 0; - ret = hpp__call_print_fn(hpp, print_fn, fmt, len, average); - } else { - ret = hpp__call_print_fn(hpp, print_fn, fmt, len, get_field(he)); + return hpp__call_print_fn(hpp, print_fn, fmt, len, avg); } + return hpp__call_print_fn(hpp, print_fn, fmt, len, val); +} + +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; + struct hists *hists = he->hists; + struct evsel *evsel = hists_to_evsel(hists); + char *buf = hpp->buf; + size_t size = hpp->size; + + ret = __hpp__fmt_print(hpp, hists, get_field(he), he->stat.nr_events, + fmt, len, print_fn, fmtype); + if (evsel__is_group_event(evsel)) { int prev_idx, idx_delta; struct hist_entry *pair; @@ -72,30 +79,16 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, while (idx_delta--) { /* - * zero-fill group members in the middle which - * have no sample + * 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. */ - if (fmtype != PERF_HPP_FMT_TYPE__RAW) { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); - } else { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); - } + ret += __hpp__fmt_print(hpp, pair->hists, 0, 0, + fmt, len, print_fn, fmtype); } - if (fmtype == PERF_HPP_FMT_TYPE__PERCENT) { - ret += hpp__call_print_fn(hpp, print_fn, fmt, len, - 100.0 * period / total); - } else if (fmtype == PERF_HPP_FMT_TYPE__AVERAGE) { - double avg = nr_samples ? (period / nr_samples) : 0; - - ret += hpp__call_print_fn(hpp, print_fn, fmt, - len, avg); - } else { - ret += hpp__call_print_fn(hpp, print_fn, fmt, - len, period); - } + ret += __hpp__fmt_print(hpp, pair->hists, period, nr_samples, + fmt, len, print_fn, fmtype); prev_idx = evsel__group_idx(evsel); } @@ -104,15 +97,11 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he, while (idx_delta--) { /* - * zero-fill group members at last which have no sample + * zero-fill group members at last which have no sample. + * the hists is not correct but it's fine like above. */ - if (fmtype != PERF_HPP_FMT_TYPE__RAW) { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0.0); - } else { - ret += hpp__call_print_fn(hpp, print_fn, - fmt, len, 0ULL); - } + ret += __hpp__fmt_print(hpp, evsel__hists(evsel), 0, 0, + fmt, len, print_fn, fmtype); } } -- 2.45.1.288.g0e0cd299f1-goog