]>
Commit | Line | Data |
---|---|---|
6beaed3f FG |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: "Scot W. Stevenson" <scot.stevenson@gmail.com> | |
3 | Date: Sat, 4 Nov 2017 21:33:28 +0100 | |
4 | Subject: [PATCH] Rewrite fHits() in arc_summary.py with SI units | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | Complete rewrite of fHits(). Move units from non-standard English | |
10 | abbreviations to SI units, thereby avoiding confusion because of | |
11 | "long scale" and "short scale" numbers. Remove unused parameter | |
12 | "Decimal". Add function string. Aim to confirm to PEP8. | |
13 | ||
14 | Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> | |
15 | Reviewed-by: George Melikov <mail@gmelikov.ru> | |
16 | Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov> | |
17 | Signed-off-by: Scot W. Stevenson <scot.stevenson@gmail.com> | |
18 | Closes #6815 | |
19 | (cherry picked from commit 88e4e0d5dd1800add5191633d65797ce1c2eb4cf) | |
20 | Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> | |
21 | --- | |
22 | cmd/arc_summary/arc_summary.py | 62 ++++++++++++++++++++++-------------------- | |
23 | 1 file changed, 33 insertions(+), 29 deletions(-) | |
24 | ||
25 | diff --git a/cmd/arc_summary/arc_summary.py b/cmd/arc_summary/arc_summary.py | |
26 | index 6b818edc7..cbb7d20bc 100755 | |
27 | --- a/cmd/arc_summary/arc_summary.py | |
28 | +++ b/cmd/arc_summary/arc_summary.py | |
29 | @@ -111,36 +111,40 @@ def fBytes(b=0): | |
30 | return result | |
31 | ||
32 | ||
33 | -def fHits(Hits=0, Decimal=2): | |
34 | - khits = (10 ** 3) | |
35 | - mhits = (10 ** 6) | |
36 | - bhits = (10 ** 9) | |
37 | - thits = (10 ** 12) | |
38 | - qhits = (10 ** 15) | |
39 | - Qhits = (10 ** 18) | |
40 | - shits = (10 ** 21) | |
41 | - Shits = (10 ** 24) | |
42 | - | |
43 | - if Hits >= Shits: | |
44 | - return str("%0." + str(Decimal) + "f") % (Hits / Shits) + "S" | |
45 | - elif Hits >= shits: | |
46 | - return str("%0." + str(Decimal) + "f") % (Hits / shits) + "s" | |
47 | - elif Hits >= Qhits: | |
48 | - return str("%0." + str(Decimal) + "f") % (Hits / Qhits) + "Q" | |
49 | - elif Hits >= qhits: | |
50 | - return str("%0." + str(Decimal) + "f") % (Hits / qhits) + "q" | |
51 | - elif Hits >= thits: | |
52 | - return str("%0." + str(Decimal) + "f") % (Hits / thits) + "t" | |
53 | - elif Hits >= bhits: | |
54 | - return str("%0." + str(Decimal) + "f") % (Hits / bhits) + "b" | |
55 | - elif Hits >= mhits: | |
56 | - return str("%0." + str(Decimal) + "f") % (Hits / mhits) + "m" | |
57 | - elif Hits >= khits: | |
58 | - return str("%0." + str(Decimal) + "f") % (Hits / khits) + "k" | |
59 | - elif Hits == 0: | |
60 | - return str("%d" % 0) | |
61 | +def fHits(hits=0): | |
62 | + """Create a human-readable representation of the number of hits. | |
63 | + The single-letter symbols used are SI to avoid the confusion caused | |
64 | + by the different "short scale" and "long scale" representations in | |
65 | + English, which use the same words for different values. See | |
66 | + https://en.wikipedia.org/wiki/Names_of_large_numbers and | |
67 | + https://physics.nist.gov/cuu/Units/prefixes.html | |
68 | + """ | |
69 | + | |
70 | + numbers = [ | |
71 | + [10**24, 'Y'], # yotta (septillion) | |
72 | + [10**21, 'Z'], # zetta (sextillion) | |
73 | + [10**18, 'E'], # exa (quintrillion) | |
74 | + [10**15, 'P'], # peta (quadrillion) | |
75 | + [10**12, 'T'], # tera (trillion) | |
76 | + [10**9, 'G'], # giga (billion) | |
77 | + [10**6, 'M'], # mega (million) | |
78 | + [10**3, 'k']] # kilo (thousand) | |
79 | + | |
80 | + if hits >= 1000: | |
81 | + | |
82 | + for limit, symbol in numbers: | |
83 | + | |
84 | + if hits >= limit: | |
85 | + value = hits/limit | |
86 | + break | |
87 | + | |
88 | + result = "%0.2f%s" % (value, symbol) | |
89 | + | |
90 | else: | |
91 | - return str("%d" % Hits) | |
92 | + | |
93 | + result = "%d" % hits | |
94 | + | |
95 | + return result | |
96 | ||
97 | ||
98 | def fPerc(lVal=0, rVal=0, Decimal=2): | |
99 | -- | |
100 | 2.14.2 | |
101 |