From patchwork Thu Aug 10 12:54:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: seeteena X-Patchwork-Id: 9893681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BDB5C60236 for ; Thu, 10 Aug 2017 12:55:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF9D528ABA for ; Thu, 10 Aug 2017 12:55:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A47DD28AC6; Thu, 10 Aug 2017 12:55:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37A0E28ABA for ; Thu, 10 Aug 2017 12:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752037AbdHJMzO (ORCPT ); Thu, 10 Aug 2017 08:55:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32828 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751387AbdHJMzM (ORCPT ); Thu, 10 Aug 2017 08:55:12 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7ACs5Ex084757 for ; Thu, 10 Aug 2017 08:55:12 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0a-001b2d01.pphosted.com with ESMTP id 2c8qtp0ay2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 10 Aug 2017 08:55:11 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Aug 2017 22:55:08 +1000 Received: from d23relay10.au.ibm.com (202.81.31.229) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 10 Aug 2017 22:55:07 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7ACt62v36044822; Thu, 10 Aug 2017 22:55:06 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7ACt5k2003719; Thu, 10 Aug 2017 22:55:06 +1000 Received: from oc1548405160.ibm.com ([9.79.211.140]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7ACt0nv003465 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 10 Aug 2017 22:55:03 +1000 From: Seeteena Thoufeek To: trenn@suse.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, rafael.j.wysocki@intel.com Cc: s1seetee@linux.vnet.ibm.com Subject: [PATCH v3] Fix header-name to read state name and adjust column width Date: Thu, 10 Aug 2017 18:24:54 +0530 X-Mailer: git-send-email 1.8.3.1 X-TM-AS-MML: disable x-cbid: 17081012-0040-0000-0000-0000034D9371 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17081012-0041-0000-0000-00000CCAE3C9 Message-Id: <1502369694-9720-1-git-send-email-s1seetee@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-10_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1708100213 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP root:~# cpupower monitor |Idle_Stats PKG |CORE|CPU | snoo | stop | stop 0| 8| 0| 0.00| 0.00| 2.79 0| 8| 1| 0.00| 0.00| 70.68 In this patch, we modify the output to print the state name and adjust the column width, that results in a legible output. root:~#cpupower monitor |Idle_Stats PKG |CORE|CPU |snooze|stop0_li|stop1_li 0| 8| 0| 0.00| 0.00| 60.04 0| 8| 1| 0.00| 0.00| 38.97 0| 8| 2| 0.00| 0.00| 0.00 0| 8| 3| 0.00| 0.00| 0.00 0| 12| 4| 0.00| 0.00| 99.25 0| 12| 5| 0.00| 0.00| 0.00 0| 12| 6| 0.00| 0.00| 99.71 0| 12| 7| 0.00| 0.00| 99.85 8|2048| 8| 0.00| 0.00| 54.66 8|2048| 9| 0.00| 0.00| 0.00 8|2048| 10| 0.00| 0.00| 0.00 8|2048| 11| 0.00| 0.00| 97.83 8|2052| 12| 0.00| 0.00| 0.00 8|2052| 13| 0.00| 0.00| 0.00 8|2052| 14| 0.00| 0.00| 1.99 8|2052| 15| 0.00| 0.00| 99.87 Tested on POWER8, POWER9 and x86. Signed-off-by: Seeteena Thoufeek --- .../cpupower/utils/idle_monitor/cpupower-monitor.c | 62 +++++++++++++++------- .../cpupower/utils/idle_monitor/cpupower-monitor.h | 6 ++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c index 05f953f..949b3bc 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c @@ -21,6 +21,10 @@ #include "idle_monitor/cpupower-monitor.h" #include "idle_monitor/idle_monitors.h" #include "helpers/helpers.h" +#define xstr(s) str(s) +#define str(s) #s +#define COL_WIDTH_MIN 6 +#define COL_WIDTH_MAX 8 /* Define pointers to all monitors. */ #define DEF(x) & x ## _monitor , @@ -85,7 +89,7 @@ int fill_string_with_spaces(char *s, int n) void print_header(int topology_depth) { int unsigned mon; - int state, need_len; + int state, need_len, name_len; cstate_t s; char buf[128] = ""; int percent_width = 4; @@ -116,17 +120,19 @@ void print_header(int topology_depth) for (mon = 0; mon < avail_monitors; mon++) { if (mon != 0) printf("|| "); - else - printf(" "); for (state = 0; state < monitors[mon]->hw_states_num; state++) { if (state != 0) - printf(" | "); + printf("|"); s = monitors[mon]->hw_states[state]; - sprintf(buf, "%s", s.name); + name_len = strlen(s.name); + if (name_len <= COL_WIDTH_MIN) + percent_width = COL_WIDTH_MIN; + else + percent_width = COL_WIDTH_MAX; + sprintf(buf, "%.*s", percent_width, s.name); fill_string_with_spaces(buf, percent_width); printf("%s", buf); } - printf(" "); } printf("\n"); } @@ -134,12 +140,12 @@ void print_header(int topology_depth) void print_results(int topology_depth, int cpu) { - unsigned int mon; - int state, ret; + unsigned int mon, percent_width, name_len, width; + int state, ret, i; double percent; unsigned long long result; cstate_t s; - + char buf[128] = ""; /* Be careful CPUs may got resorted for pkg value do not just use cpu */ if (!bitmask_isbitset(cpus_chosen, cpu_top.core_info[cpu].cpu)) return; @@ -163,23 +160,37 @@ void print_results(int topology_depth, int cpu) printf("|"); s = monitors[mon]->hw_states[state]; - + name_len = strlen(s.name); + if (name_len > COL_WIDTH_MIN) { + percent_width = COL_WIDTH_MAX; + width = percent_width - COL_WIDTH_MIN; + fill_string_with_spaces(buf, width); + printf("%s", buf); + } if (s.get_count_percent) { ret = s.get_count_percent(s.id, &percent, cpu_top.core_info[cpu].cpu); - if (ret) - printf("******"); - else if (percent >= 100.0) - printf("%6.1f", percent); - else - printf("%6.2f", percent); + if (ret) { + for (i = 0; i < COL_WIDTH_MIN; i++) + printf("*"); + } else if (percent >= 100.0) { + printf("%"xstr(COL_WIDTH_MIN)".1f", + percent); + } + else { + printf("%"xstr(COL_WIDTH_MIN)".2f", + percent); + } } else if (s.get_count) { ret = s.get_count(s.id, &result, cpu_top.core_info[cpu].cpu); - if (ret) - printf("******"); - else - printf("%6llu", result); + if (ret) { + for (i = 0; i < COL_WIDTH_MIN; i++) + printf("*"); + } else { + printf("%"xstr(COL_WIDTH_MIN)"llu", + result); + } } else { printf(_("Monitor %s, Counter %s has no count " "function. Implementation error\n"), diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h index 9e43f33..f6dcb9f 100644 --- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h @@ -15,7 +15,11 @@ #define MONITORS_MAX 20 #define MONITOR_NAME_LEN 20 -#define CSTATE_NAME_LEN 5 +/* + * CSTATE_NAME_LEN is limited by the CPUIDLE_NAME_LEN defined + * in include/linux/cpuidle.h. + */ +#define CSTATE_NAME_LEN 16 #define CSTATE_DESC_LEN 60 int cpu_count;