From patchwork Tue Oct 10 11:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13415206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41AF7CD80A3 for ; Tue, 10 Oct 2023 11:08:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C9E710E335; Tue, 10 Oct 2023 11:08:01 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id DE40010E1D0; Tue, 10 Oct 2023 11:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696936078; x=1728472078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oSW8UAGZ/xuxrulfCMy/ouKz2mQ/bQtyNOA0TQI3wuk=; b=ZJRaWftezB2kMceygho61rGg4lx9gDAUAIpZArsDhL0dd+Jkc+Ulzw7W Z76h4y+OAcLb5ia+fuy2iFhHeeWKAk/a9Iw3IwMjvg7dw5TkF6QZdK4+V an9KHrqFgSlQU3c6J96XqZW5LIIrKyGyRRIVuowjME2Y1bm5p7k1VBbKQ pEihmAy24lhCyHt+9YCd60q1xaK05N7VOaSBv+5oTOwcv3yOs/K6SaBSO JbCIeBbG8yMda/TWTYfeMGHnC7nbN4iC2vLcAqCGAC0uKx2qf+UwhmPhw I9gwgVqZmq9brSLViwxeRrVFC/w5CxOwLri8FOMlQLFi9GOxELQiTb0Fe A==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="450863383" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="450863383" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="819205888" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="819205888" Received: from emikisch-mobl.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.174.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:22 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Tue, 10 Oct 2023 12:07:11 +0100 Message-Id: <20231010110714.749239-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> References: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 1/4] tools/intel_gpu_top: Fix clients header width when no clients X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin Recent refactoring broke the clients header in cases when there are no clients displayed. To fix it we need to account the width of the "NAME" label. Signed-off-by: Tvrtko Ursulin Reviewed-by: Kamil Konieczny --- tools/intel_gpu_top.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 10601e66b18e..60fe06917531 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -1967,6 +1967,8 @@ print_clients_header(struct igt_drm_clients *clients, int lines, int con_w, int con_h, int *class_w) { struct intel_clients *iclients = clients->private_data; + const int max_name_len = clients->max_name_len < 4 ? + 4 : clients->max_name_len; /* At least "NAME" */ if (output_mode == INTERACTIVE) { unsigned int num_active = 0; @@ -1990,9 +1992,8 @@ print_clients_header(struct igt_drm_clients *clients, int lines, num_active++; } - *class_w = width = - (con_w - len - clients->max_name_len - 1) / - num_active; + *class_w = width = (con_w - len - max_name_len - 1) / + num_active; for (i = 0; i <= iclients->classes.max_engine_id; i++) { const char *name = iclients->classes.names[i]; From patchwork Tue Oct 10 11:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13415202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 332FCCD80A3 for ; Tue, 10 Oct 2023 11:08:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B4D410E1D0; Tue, 10 Oct 2023 11:07:59 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B92210E1DC; Tue, 10 Oct 2023 11:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696936078; x=1728472078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MNTQMe0ubRZJzHNzx06CQCw05ZN/OEr78Syc1h/zKi4=; b=PB72HfTPzjOwJJ2roLTwvZhDyE2soh+p8vEJDLZlnFwl7kmRqZ7E+3E+ 08YFl8d2oXmhAZQsuUIRNA3CLoKlCQzTJd0rmydoGgwKLq6mdr/kKJGF3 hwqQn1nP2lQMNa45LMwC4i+4Ts2W+LimXt/a6IkO+7qQ7vFgBBulW6Saz e/8VRTd/uCb9gKCW0pvoFJ2Mi98g2fht/bfF5Th4rTuQyPmm3mKVdlu7q AnbDXRZgkPc6VHfddVliYvvLOBk7WxCMpLvYIyvD9NL7RGq/infavG3c5 rTjSEv/TmZOQiFkYB+dKqiKgwksfTJFbmi2ICbNRwsX60L9qhUuOqj3Hf A==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="450863385" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="450863385" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="819205891" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="819205891" Received: from emikisch-mobl.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.174.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:23 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Tue, 10 Oct 2023 12:07:12 +0100 Message-Id: <20231010110714.749239-3-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> References: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 2/4] tools/intel_gpu_top: Fix client layout on first sample period X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin When I moved the client name to be last, I did not account for the fact current code skips showing engine utilisation until at least two sampling periods have passed. Consequence of this is that client name gets printed as the second field and not under the "NAME" column header. Fix it by emitting spaces instead of engine utilisation until two samples have been collected. Signed-off-by: Tvrtko Ursulin Reviewed-by: Kamil Konieczny --- tools/intel_gpu_top.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 60fe06917531..c5abd0c92155 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -928,12 +928,14 @@ static void free_display_clients(struct igt_drm_clients *clients) static const char *bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" }; -static void n_spaces(const unsigned int n) +static unsigned int n_spaces(const unsigned int n) { unsigned int i; for (i = 0; i < n; i++) putchar(' '); + + return n; } static void @@ -2043,14 +2045,17 @@ print_client(struct igt_drm_client *c, struct engines *engines, double t, int li len = printf("%*s ", clients->max_pid_len, c->pid_str); - for (i = 0; - c->samples > 1 && i <= iclients->classes.max_engine_id; - i++) { + for (i = 0; i <= iclients->classes.max_engine_id; i++) { double pct, max; if (!iclients->classes.capacity[i]) continue; + if (c->samples < 2) { + len += n_spaces(*class_w); + continue; + } + pct = (double)c->val[i] / period_us / 1e3 * 100; /* From patchwork Tue Oct 10 11:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13415204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E934CD80A3 for ; Tue, 10 Oct 2023 11:08:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0EFD610E1DE; Tue, 10 Oct 2023 11:08:00 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 46BB210E1DE; Tue, 10 Oct 2023 11:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696936078; x=1728472078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WYGZRfgQkVG0lThze2e6DNalezisc4ApJVXZcIZZD8o=; b=YtdgQfOAkPlcbOc49y0uWvUAVLikiujoTFdHnuRy5wDvOmmVBGR4OcEA Q3efpAA45bZRB15434Nli0T4jNyajmAVfXbm1dP++OdnjZKy7F1l3hoHB qrFwNPi+yCI3twNm9ARTOl1kkr+P8j+LNWKDwMJxdudwHLUrQx8AsxXGG 6EcewNoj9DDlETKe5ARTfPxG5NSulcR/mr2sYRJsq+2PtbMrp7zc26GqL aOO0ZyaafW1HxoP1Jdr4xUg85/CqwAsBRMrhtRNY8TWiJ1lQN5xsXLow9 sHitkjLeBhxtwvvj8mgfONep9k+e2nd4dS2BCk7hhtQjZMdIaG/3J5xRa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="450863390" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="450863390" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="819205894" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="819205894" Received: from emikisch-mobl.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.174.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:24 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Tue, 10 Oct 2023 12:07:13 +0100 Message-Id: <20231010110714.749239-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> References: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 3/4] tools/intel_gpu_top: Optimise interactive display a bit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin Padding the percentage bars and table columns with spaces happens quite a lot so lets do better than putchar at a time. Have a table of visually empty strings and build the required length out of those chunks. While at it, also move the percentage bar table into its function scope. Signed-off-by: Tvrtko Ursulin --- tools/intel_gpu_top.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index c5abd0c92155..472ce3f13ba9 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -926,14 +926,40 @@ static void free_display_clients(struct igt_drm_clients *clients) free(clients); } -static const char *bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" }; - static unsigned int n_spaces(const unsigned int n) { - unsigned int i; + static const char *spaces[] = { + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", +#define MAX_SPACES 19 + }; + unsigned int i, r = n; - for (i = 0; i < n; i++) - putchar(' '); + while (r) { + if (r > MAX_SPACES) + i = MAX_SPACES - 1; + else + i = r - 1; + fputs(spaces[i], stdout); + r -= i + 1; + } return n; } @@ -941,6 +967,8 @@ static unsigned int n_spaces(const unsigned int n) static void print_percentage_bar(double percent, double max, int max_len, bool numeric) { + static const char *bars[] = + { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" }; int bar_len, i, len = max_len - 2; const int w = 8; From patchwork Tue Oct 10 11:07:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13415205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 353B5CD80A7 for ; Tue, 10 Oct 2023 11:08:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43A9A10E33F; Tue, 10 Oct 2023 11:08:02 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 66A0610E1D0; Tue, 10 Oct 2023 11:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696936078; x=1728472078; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=03nDRWW7EVAGKmebBot0ZRNlqX0pvuY1gK8RtPU+Pps=; b=RcKIhfVOn0z6i2/vqI/6XWn9atjlXmHtg1Bpby4OkSC7/tktsDUPoLoE F+Px3cxQgrFdNVX6E6S4Ylu0anDUKbbum5o4noQtgY8HhwH96CByaIi9E eQCI3uzNh78AlbDgdSYoVSsx5ZausWmv6AoUYlnxoQ05nqTFRW2zhD/dF ma9GDAL9kPrKe9ZyNieJUbf+oAsWEtN2iEGLO4tS6hr74nAWxrfNyG9ni FIBbXQQdjKPMGsm7xsLgrKmvvaKjyIrPBp/EU5rYk6ot0nW8wnti6UnpE oz+4pkrDeMp7K4QP33Z0Dm5lZnJ39wBPR4HLTJJihtswaZVmyJQzK8T32 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="450863400" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="450863400" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10858"; a="819205899" X-IronPort-AV: E=Sophos;i="6.03,212,1694761200"; d="scan'208";a="819205899" Received: from emikisch-mobl.amr.corp.intel.com (HELO localhost.localdomain) ([10.213.174.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2023 04:07:25 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Tue, 10 Oct 2023 12:07:14 +0100 Message-Id: <20231010110714.749239-5-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> References: <20231010110714.749239-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 4/4] tools/intel_gpu_top: Handle narrow terminals more gracefully X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tvrtko Ursulin Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Tvrtko Ursulin Instead of asserting just skip trying to print columns when terminal is too narrow. At the same time fix some type confusion to fix calculations going huge. Signed-off-by: Tvrtko Ursulin Closes: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues/143 Reviewed-by: Kamil Konieczny --- tools/intel_gpu_top.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/intel_gpu_top.c b/tools/intel_gpu_top.c index 472ce3f13ba9..6d1397cb8214 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -926,7 +926,7 @@ static void free_display_clients(struct igt_drm_clients *clients) free(clients); } -static unsigned int n_spaces(const unsigned int n) +static int n_spaces(const int n) { static const char *spaces[] = { " ", @@ -950,7 +950,7 @@ static unsigned int n_spaces(const unsigned int n) " ", #define MAX_SPACES 19 }; - unsigned int i, r = n; + int i, r = n; while (r) { if (r > MAX_SPACES) @@ -972,7 +972,8 @@ print_percentage_bar(double percent, double max, int max_len, bool numeric) int bar_len, i, len = max_len - 2; const int w = 8; - assert(max_len > 0); + if (len < 2) /* For edge lines '|' */ + return; bar_len = ceil(w * percent * len / max); if (bar_len > w * len) @@ -986,6 +987,8 @@ print_percentage_bar(double percent, double max, int max_len, bool numeric) printf("%s", bars[i]); len -= (bar_len + (w - 1)) / w; + if (len < 1) + return; n_spaces(len); putchar('|'); @@ -2001,8 +2004,7 @@ print_clients_header(struct igt_drm_clients *clients, int lines, 4 : clients->max_name_len; /* At least "NAME" */ if (output_mode == INTERACTIVE) { - unsigned int num_active = 0; - int len; + int len, num_active = 0; if (lines++ >= con_h) return lines;