Skip to content

Commit

Permalink
fix scale == 100 & change prettynum()
Browse files Browse the repository at this point in the history
Signed-off-by: Theera K. <[email protected]>
  • Loading branch information
tkittich authored Sep 14, 2024
1 parent 3b5d7f8 commit 3fe42cc
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cmd/arcstat.in
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def snap_stats():
d[key] = cur[key]


def isint(num):
if isinstance(num, int):
return True
if isinstance(num, float):
return num.is_integer()
return False


def prettynum(sz, scale, num=0):
suffix = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']
index = 0
Expand All @@ -404,19 +412,20 @@ def prettynum(sz, scale, num=0):
if scale == -1:
return "%s" % num

while abs(num) > scale and index < 5:
num = num / scale
index += 1
if scale != 100:
while abs(num) > scale and index < 5:
num = num / scale
index += 1

if (sint == 1 and 0 < abs(num) < 1) or \
(sint != 1 and abs(num) < 9.95):
format = "%*.1f%s"
arg = num
else:
width = sz - (0 if index == 0 else 1)
intlen = len("%d" % num)
if sint == 1 and isint(num) or width < intlen + 2:
format = "%*d%s"
arg = round(num)
sf = suffix[index]
return format % (sz - len(sf), arg, sf)
else:
format = "%*.1f%s"
arg = num
return format % (width, arg, suffix[index])


def print_values():
Expand Down

0 comments on commit 3fe42cc

Please sign in to comment.