zfsonlinux/zfs-patches/0013-Rewrite-fHits-in-arc_summary.py-with-SI-units.patch
Fabian Grünbichler 6beaed3f99 add remaining zfs-0.7.6 changes as patches
since Debian unstable has not been updated yet.
2018-02-21 09:52:27 +01:00

102 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Scot W. Stevenson" <scot.stevenson@gmail.com>
Date: Sat, 4 Nov 2017 21:33:28 +0100
Subject: [PATCH] Rewrite fHits() in arc_summary.py with SI units
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Complete rewrite of fHits(). Move units from non-standard English
abbreviations to SI units, thereby avoiding confusion because of
"long scale" and "short scale" numbers. Remove unused parameter
"Decimal". Add function string. Aim to confirm to PEP8.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Signed-off-by: Scot W. Stevenson <scot.stevenson@gmail.com>
Closes #6815
(cherry picked from commit 88e4e0d5dd1800add5191633d65797ce1c2eb4cf)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
cmd/arc_summary/arc_summary.py | 62 ++++++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py
index 6b818edc7..cbb7d20bc 100755
--- a/cmd/arc_summary/arc_summary.py
+++ b/cmd/arc_summary/arc_summary.py
@@ -111,36 +111,40 @@ def fBytes(b=0):
return result
-def fHits(Hits=0, Decimal=2):
- khits = (10 ** 3)
- mhits = (10 ** 6)
- bhits = (10 ** 9)
- thits = (10 ** 12)
- qhits = (10 ** 15)
- Qhits = (10 ** 18)
- shits = (10 ** 21)
- Shits = (10 ** 24)
-
- if Hits >= Shits:
- return str("%0." + str(Decimal) + "f") % (Hits / Shits) + "S"
- elif Hits >= shits:
- return str("%0." + str(Decimal) + "f") % (Hits / shits) + "s"
- elif Hits >= Qhits:
- return str("%0." + str(Decimal) + "f") % (Hits / Qhits) + "Q"
- elif Hits >= qhits:
- return str("%0." + str(Decimal) + "f") % (Hits / qhits) + "q"
- elif Hits >= thits:
- return str("%0." + str(Decimal) + "f") % (Hits / thits) + "t"
- elif Hits >= bhits:
- return str("%0." + str(Decimal) + "f") % (Hits / bhits) + "b"
- elif Hits >= mhits:
- return str("%0." + str(Decimal) + "f") % (Hits / mhits) + "m"
- elif Hits >= khits:
- return str("%0." + str(Decimal) + "f") % (Hits / khits) + "k"
- elif Hits == 0:
- return str("%d" % 0)
+def fHits(hits=0):
+ """Create a human-readable representation of the number of hits.
+ The single-letter symbols used are SI to avoid the confusion caused
+ by the different "short scale" and "long scale" representations in
+ English, which use the same words for different values. See
+ https://en.wikipedia.org/wiki/Names_of_large_numbers and
+ https://physics.nist.gov/cuu/Units/prefixes.html
+ """
+
+ numbers = [
+ [10**24, 'Y'], # yotta (septillion)
+ [10**21, 'Z'], # zetta (sextillion)
+ [10**18, 'E'], # exa (quintrillion)
+ [10**15, 'P'], # peta (quadrillion)
+ [10**12, 'T'], # tera (trillion)
+ [10**9, 'G'], # giga (billion)
+ [10**6, 'M'], # mega (million)
+ [10**3, 'k']] # kilo (thousand)
+
+ if hits >= 1000:
+
+ for limit, symbol in numbers:
+
+ if hits >= limit:
+ value = hits/limit
+ break
+
+ result = "%0.2f%s" % (value, symbol)
+
else:
- return str("%d" % Hits)
+
+ result = "%d" % hits
+
+ return result
def fPerc(lVal=0, rVal=0, Decimal=2):
--
2.14.2