mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Improved cache memory output
This commit is contained in:
parent
6171d1d2e1
commit
8197548285
@ -162,11 +162,15 @@ def get_size_of(obj,counted=None):
|
|||||||
return size
|
return size
|
||||||
|
|
||||||
def human_readable_size(obj):
|
def human_readable_size(obj):
|
||||||
units = ['','K','M','G','T','P']
|
units = ['','Ki','Mi','Gi','Ti','Pi']
|
||||||
idx = 0
|
magnitude = 0
|
||||||
bytes = get_size_of(obj)
|
|
||||||
while bytes > 1024 and len(units) > idx+1:
|
|
||||||
bytes = bytes / 1024
|
|
||||||
idx += 1
|
|
||||||
|
|
||||||
return f"{bytes:.2f} {units[idx]}B"
|
bytes = get_size_of(obj)
|
||||||
|
while bytes > 1024 and len(units) > magnitude+1:
|
||||||
|
bytes = bytes / 1024
|
||||||
|
magnitude += 1
|
||||||
|
|
||||||
|
if magnitude > 2:
|
||||||
|
return f"{bytes:.2f} {units[magnitude]}B"
|
||||||
|
else:
|
||||||
|
return f"{bytes:.0f} {units[magnitude]}B"
|
||||||
|
Loading…
Reference in New Issue
Block a user