Received: by 10.223.164.202 with SMTP id h10csp5990972wrb; Tue, 21 Nov 2017 20:06:49 -0800 (PST) X-Google-Smtp-Source: AGs4zMb0E9ugd8PNMUrLTf3LrvLgsM7+XMH1gFg+vNG+I8qH3z9ElQ2k4b8ElL11u0pmScv5Jx3M X-Received: by 10.98.247.26 with SMTP id h26mr17463501pfi.233.1511323609484; Tue, 21 Nov 2017 20:06:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511323609; cv=none; d=google.com; s=arc-20160816; b=cBgCFYc5c2Sv2VOF+jtK5LJOa294Ax+pEshJQShLw+B8vcBG7YcAkpqr8usVtV7rjh gmgLzQPofHFr32zaCv7hEGynWgG5xRqucBRoCjBROuJse1yuIPvordT98SeOEA3dnWFl IL6jedCTMOIqWxiAJI0uqy7aF2te8kbPqiFKm6YL8vSYtxjhecwpicR6K77VuGzIQUqA Hr5DIUOdQoh8UCXho3VHbyv96hgnzzdVr7JE2WjfqtPS+k0cCdNYz/T+tHo/NxXPipb5 2RvUBNNK83/3VE3PWIEHHeaLhF2SEDOJ4Y9lanoA6eLKV1i5AK0T5tXhFri1M1ZDNruC 7sEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VunN/YFEsTI2kjwdwEiqcIemodElgtOTITrxwRr5ljs=; b=MXt6hIvpJaMObhA+uGJCIZWx6g8DKCSn20yYsPQlbpSs+op2QbI2508irgTyFlAkX7 jxCtqY2F1frG43jbL494NQSfe9OJ6XEMv3YMIOJ0asW7Z0iEQ2AXhbRtn+uPu8aPUabB jogdl4PFBdkKTPdR5y4U3PmwOcvzA6NsgGJDUOGFNQLqmm5xSV0Rca2yJRDzXYvce2FD YvNUFDqFp9gPnVqbyLJfNwHRSOa0j1g8jjPQiZxR/1s01n5nNtaWF7k7/YxKJgX1mI/B 7YJN8g6od+xbcMqFfYtlZXYBkeESOxDoj7EPVgjcJLePRWjH/pxE2ekq3vsOWcFDogH2 Uo+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si12465037pgn.160.2017.11.21.20.06.38; Tue, 21 Nov 2017 20:06:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751500AbdKVEGC (ORCPT + 76 others); Tue, 21 Nov 2017 23:06:02 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51116 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751409AbdKVEGB (ORCPT ); Tue, 21 Nov 2017 23:06:01 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAM44deH035171 for ; Tue, 21 Nov 2017 23:06:00 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ed0seacs5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 21 Nov 2017 23:06:00 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 04:05:58 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 04:05:55 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAM45ttB40829174; Wed, 22 Nov 2017 04:05:55 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA60BA405E; Wed, 22 Nov 2017 04:00:35 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E5D4A4040; Wed, 22 Nov 2017 04:00:34 +0000 (GMT) Received: from oc1548405160.ibm.com (unknown [9.77.209.101]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 Nov 2017 04:00:34 +0000 (GMT) From: Seeteena Thoufeek To: shuah@kernel.org, trenn@suse.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: s1seetee@linux.vnet.ibm.com Subject: [PATCH v3] Fix header-name to read state name and adjust column width Date: Wed, 22 Nov 2017 09:35:50 +0530 X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 x-cbid: 17112204-0040-0000-0000-000003F12BB0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112204-0041-0000-0000-000025F3F535 Message-Id: <1511323550-15684-1-git-send-email-s1seetee@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220054 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The names of the idle states in the output of cpupower monitor command are truncated to 4 characters. Hence, On POWER9, since the states are named "stop0, stop1, stop2, stop4, stop11", this output is ambiguous 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; -- 1.8.3.1 From 1584112543466214094@xxx Wed Nov 15 06:30:47 +0000 2017 X-GM-THRID: 1584112543466214094 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread