From patchwork Wed Oct 11 08:38:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13416890 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 BA457CD68E6 for ; Wed, 11 Oct 2023 08:38:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E41910E5B5; Wed, 11 Oct 2023 08:38:52 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id BFDB710E5AB; Wed, 11 Oct 2023 08:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013530; x=1728549530; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h2u6JPoZBKdqCKrz5ddYElOvwAyN7GAo4zuTE4uMRzg=; b=QG63m2sCiqapUu8tTNDzZ3DKTWM92jGiCrX8uJWilakHq/odhOA8GnBY BNp4vTQEx+jGF2UKaz+4slbsvm8H2t4GK8PbA5fWz+9S7edTFxBh0kxec b+IZYy647aJ01/NYw6QF2r/zBCaazn+s2Z8nyaySottV3JDJ+rWEEb0B2 fohLDBhGfeAAPWeNsf3ajbVotelR/lTJwaS3C8uJZe0EixssTG/nMZgte cUcARx80IyTmt2LHippikzaKo1seCB5pWgX5u60sODy1sRdwjU5Y5BLzm U02YRNhHUwizDzzQbrURDb3C9Q26bRPlV3q/HDhFRHnZu6pgxmG9+Ee9K w==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="383473305" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="383473305" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:38:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="877584852" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="877584852" Received: from cjodwyer-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.194.149]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:38:48 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Wed, 11 Oct 2023 09:38:42 +0100 Message-Id: <20231011083845.798413-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 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 Wed Oct 11 08:28:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 13416872 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 D2520CD6115 for ; Wed, 11 Oct 2023 08:29:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3071310E591; Wed, 11 Oct 2023 08:29:06 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id EDEF810E591; Wed, 11 Oct 2023 08:29:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697012944; x=1728548944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OYekpnUKJSKnlJSMp4tXfU94DvFxn3byh6US8nHwg50=; b=E4a6GjgaIyFuTxVaPTLDKWFiLFgr6BBPNwC15B9u15AD+ecsTqjgkjps 8rPMBBOVmxvEPGWboOC0zH+5rJBKRPeulqnfWzY8WVASh9QtAUSy2iFfM FJheMS+DyE8h45oC0bIlto4E4nbQsyO+UQXOxEnti7kgS71E2X3q8mEyW aMtjJXVnqiiq8VUxyQiAwMKPHlpVImKWDgK4lmRLusIZbiMkMn9t6wq8V vdD14X9y2bvwwQVMc/7LZvGLFfLdn7APqegzRMoeV42P2itV8ifiCtV2H ww8a5D+OGdOnKdduEzc5ASDi1KvgL5I+RrzG9ABvhsmqQSQ9NmO0+pJwi g==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="3201437" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="3201437" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:29:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="730414393" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="730414393" Received: from cjodwyer-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.194.149]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:29:02 -0700 From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org, Intel-gfx@lists.freedesktop.org Date: Wed, 11 Oct 2023 09:28:57 +0100 Message-Id: <20231011082857.797045-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010163518.hgcqkap3dx655hrk@kamilkon-desk.igk.intel.com> References: <20231010163518.hgcqkap3dx655hrk@kamilkon-desk.igk.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. v2: * Fix checkpatch and use ARRAY_SIZE. (Kamil) Signed-off-by: Tvrtko Ursulin Kamil Konieczny --- 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..6bd03ab8d7fa 100644 --- a/tools/intel_gpu_top.c +++ b/tools/intel_gpu_top.c @@ -926,14 +926,39 @@ 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[] = { + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }; + unsigned int i, r = n; - for (i = 0; i < n; i++) - putchar(' '); + while (r) { + if (r > ARRAY_SIZE(spaces)) + i = ARRAY_SIZE(spaces) - 1; + else + i = r - 1; + fputs(spaces[i], stdout); + r -= i + 1; + } return n; } @@ -941,6 +966,9 @@ 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;