From patchwork Tue May 5 15:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 219866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92990C47254 for ; Tue, 5 May 2020 15:37:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6044C206B9 for ; Tue, 5 May 2020 15:37:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="V4lu4DOo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729736AbgEEPhr (ORCPT ); Tue, 5 May 2020 11:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729561AbgEEPhr (ORCPT ); Tue, 5 May 2020 11:37:47 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D935EC061A0F for ; Tue, 5 May 2020 08:37:46 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id q43so2079238qtj.11 for ; Tue, 05 May 2020 08:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=6XH0FPT08YBoUx+mfK4TeZ+oCrUvAXy0ysNUHVi9yfY=; b=V4lu4DOohkEbU/ygGOhKvQ5skq0xGYACi2bYX+2rJikgFeHm1c6nANeCfPkHDGG82P 29omG+HlqmzrezTYL7DvLbxGXstOzFYkTN0K89KNsUfR0l42C0LiIVGhuXGTH2zxQcV5 Tx8fN2fgcHXRtABfxzoHXf+ixWdGRb6bWmWIc88lzTAKaCRtYs22jA9u6CzGsrqXHYyq 2zBuKu3AhNqi6i/EtvzEins272cMEbPkRTLRGczFM+do0CGpqvqjGncDhlp/2RYiyb2H 2WNc/bw5HDan7UIqxpg6Thi38c/6QV/yBbwPlsbkIdkJIIyuqueCPci8isnReOpXEBNc 72Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=6XH0FPT08YBoUx+mfK4TeZ+oCrUvAXy0ysNUHVi9yfY=; b=fPgC3J5OTqT/hQYwu2dUQodlmMkwzwZkEENeqSsgjmE2Pql15vil/3AuMe0LeGpDER VwDcA/nXoKC/TSrng7D5bMbyvXtxWLSNkWY9fSojPPQBYLsw7dc310GpUlU8Wy5LWPcd ngUJinHUKKE7wfcFtq+GevTut/otDBhO3/RR3Vb3kyAW5PDvHcchfE/LIjnH92/Tbhge xRnfvy8Wv9Pjy1Xa3Cr3pxgYmU1U+0I7OOA1hDPgUffrWubAIAqRC4it0+d9kMthaWNv k8NXZd9t+MhBbDNog8HEVk9P5lFKJKHrwi7YMAdeoINFSQHLUzh9q5dX7mm+tIZWRWlN UjZA== X-Gm-Message-State: AGi0PubZavx1xRnNkrccLVRoGZJHrEOYpvEFPRIoxaL4AUEzoff1hHyY dTeuKtSDEh1RoxEBLKk/DceEYs+7e5PPdQ== X-Google-Smtp-Source: APiQypKox1e7l+91oxCJzNRNLS2Iz4JvcwylazpIeYqgWziOLrFGkz3eC9+OnVZLSKgjUYZHzCrqQQOpbldpYg== X-Received: by 2002:a05:6214:1702:: with SMTP id db2mr3338445qvb.201.1588693065830; Tue, 05 May 2020 08:37:45 -0700 (PDT) Date: Tue, 5 May 2020 08:37:41 -0700 Message-Id: <20200505153741.223354-1-edumazet@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [PATCH iproute2] ss: add support for Gbit speeds in sprint_bw() From: Eric Dumazet To: David Ahern , Stephen Hemminger Cc: netdev , Eric Dumazet , Eric Dumazet Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Also use 'g' specifier instead of 'f' to remove trailing zeros, and increase precision. Examples of output : Before After 8.0Kbps 8Kbps 9.9Mbps 9.92Mbps 55001Mbps 55Gbps Signed-off-by: Eric Dumazet --- misc/ss.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 3ef151fbf1f1b3856e95a1baa751a1cdd27d10b7..ab206b2011ec92b899709d2c78ce7310e88ec80e 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -2382,10 +2382,12 @@ static char *sprint_bw(char *buf, double bw) { if (numeric) sprintf(buf, "%.0f", bw); - else if (bw > 1000000.) - sprintf(buf, "%.1fM", bw / 1000000.); - else if (bw > 1000.) - sprintf(buf, "%.1fK", bw / 1000.); + else if (bw >= 1e9) + sprintf(buf, "%.3gG", bw / 1e9); + else if (bw >= 1e6) + sprintf(buf, "%.3gM", bw / 1e6); + else if (bw >= 1e3) + sprintf(buf, "%.3gK", bw / 1e3); else sprintf(buf, "%g", bw);