From patchwork Tue Sep 27 15:57:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9352201 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 5CA0060757 for ; Tue, 27 Sep 2016 16:00:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F6D12928A for ; Tue, 27 Sep 2016 16:00:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4448829290; Tue, 27 Sep 2016 16:00:59 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 74F562928A for ; Tue, 27 Sep 2016 16:00:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1boulr-0007VD-CG; Tue, 27 Sep 2016 15:58:15 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1boulq-0007TM-3H for xen-devel@lists.xenproject.org; Tue, 27 Sep 2016 15:58:14 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 46/B2-08498-5179AE75; Tue, 27 Sep 2016 15:58:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsXitHRDpK7I9Ff hBqu/W1t83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkLz51mLJjEX7F2Xy9rA+NN7i5GDg4JAX+J IzN0uhg5OdgEdCQuzt3JBhIWEVCRuL3XoIuRi4NZ4DOTxMue6ewgNcICqRKrzl1gAbFZBFQlF nR+ZAWxeQVcJTY2fQCrkRDQlXh47jdYnBMo3tu2gAnEFhJwkbg7E6ZeUOLkzCdgc5gFNCVat/ 9mh7DlJZq3zmaGqFeU6J/3gA1iJrfE7dNTmScw8s9C0j4LSfssJO0LGJlXMWoUpxaVpRbpGhn rJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEhiADEOxg/DM/8BCjJAeTkiivRvur cCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvB5TgXKCRanpqRVpmTnAaIBJS3DwKInwcoKkeYsLE nOLM9MhUqcYFaXEeRtAEgIgiYzSPLg2WAReYpSVEuZlBDpEiKcgtSg3swRV/hWjOAejkjCvCM gUnsy8Erjpr4AWMwEtXnriBcjikkSElFQD4+zK2A+7qnM043WkLRX8hB+HW7g0s0WY1X6RfVf NsnHhF+Mvpwp+LDu4cWfkno5JT9dzvjrBemFvou3RBZLOAcyFbz+8/HTrKJNhv88Zr7Sg2z+Z n26ew/8r0O23VFT2dcG4w5EvlXjTBVR9v76+Pfmu9kGOH08mCq/+21W39/bRFtk5M5nMLymxF GckGmoxFxUnAgCWJRYduwIAAA== X-Env-Sender: prvs=071b8e69e=roger.pau@citrix.com X-Msg-Ref: server-4.tower-21.messagelabs.com!1474991877!29175510!6 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15540 invoked from network); 27 Sep 2016 15:58:12 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-4.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 27 Sep 2016 15:58:12 -0000 X-IronPort-AV: E=Sophos;i="5.30,405,1470700800"; d="scan'208";a="380934413" From: Roger Pau Monne To: Date: Tue, 27 Sep 2016 17:57:08 +0200 Message-ID: <1474991845-27962-14-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) In-Reply-To: <1474991845-27962-1-git-send-email-roger.pau@citrix.com> References: <1474991845-27962-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Jan Beulich , boris.ostrovsky@oracle.com, Roger Pau Monne Subject: [Xen-devel] [PATCH v2 13/30] xen: introduce a new format specifier to print sizes in human-readable form X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new %pB format specifier to print sizes (in bytes) in a human-readable form. Signed-off-by: Roger Pau Monné --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu --- docs/misc/printk-formats.txt | 5 +++++ xen/common/vsprintf.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt index 525108f..0ee3504 100644 --- a/docs/misc/printk-formats.txt +++ b/docs/misc/printk-formats.txt @@ -30,3 +30,8 @@ Domain and vCPU information: %pv Domain and vCPU ID from a 'struct vcpu *' (printed as "dv") + +Size in human readable form: + + %pZ Size in human-readable form (input size must be in bytes). + e.g. 24MB diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index f92fb67..2dadaec 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -386,6 +386,21 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, *str = 'v'; return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0); } + case 'Z': + { + static const char units[][3] = {"B", "KB", "MB", "GB", "TB"}; + size_t size = (size_t)arg; + int i = 0; + + /* Advance parents fmt string, as we have consumed 'B' */ + ++*fmt_ptr; + + while ( ++i < sizeof(units) && size >= 1024 ) + size >>= 10; /* size /= 1024 */ + + str = number(str, end, size, 10, -1, -1, 0); + return string(str, end, units[i-1], -1, -1, 0); + } } if ( field_width == -1 )