Skip to content

Commit

Permalink
rename function arg
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Mar 24, 2018
1 parent d6445f6 commit bf79914
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ class BatteryTime(enum.IntEnum):
# ===================================================================


def usage_percent(used, total, _round=None):
def usage_percent(used, total, round_=None):
"""Calculate percentage usage of 'used' against 'total'."""
try:
ret = (used / total) * 100
except ZeroDivisionError:
ret = 0.0 if isinstance(used, float) or isinstance(total, float) else 0
if _round is not None:
return round(ret, _round)
if round_ is not None:
return round(ret, round_)
else:
return ret

Expand Down
4 changes: 2 additions & 2 deletions psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ def get_procfs_path():

def virtual_memory():
total, avail, free, pinned, inuse = cext.virtual_mem()
percent = usage_percent((total - avail), total, _round=1)
percent = usage_percent((total - avail), total, round_=1)
return svmem(total, avail, percent, inuse, free)


def swap_memory():
"""Swap system memory as a (total, used, free, sin, sout) tuple."""
total, free, sin, sout = cext.swap_mem()
used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, sin, sout)


Expand Down
4 changes: 2 additions & 2 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ def virtual_memory():
shared = int(line.split()[1]) * 1024
avail = inactive + cached + free
used = active + wired + cached
percent = usage_percent((total - avail), total, _round=1)
percent = usage_percent((total - avail), total, round_=1)
return svmem(total, avail, percent, used, free,
active, inactive, buffers, cached, shared, wired)


def swap_memory():
"""System swap memory as (total, used, free, sin, sout) namedtuple."""
total, used, free, sin, sout = cext.swap_mem()
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, sin, sout)


Expand Down
4 changes: 2 additions & 2 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def virtual_memory():
if avail > total:
avail = free

percent = usage_percent((total - avail), total, _round=1)
percent = usage_percent((total - avail), total, round_=1)

# Warn about missing metrics which are set to 0.
if missing_fields:
Expand Down Expand Up @@ -509,7 +509,7 @@ def swap_memory():
free *= unit_multiplier

used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
# get pgin/pgouts
try:
f = open_binary("%s/vmstat" % get_procfs_path())
Expand Down
4 changes: 2 additions & 2 deletions psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def virtual_memory():
total, active, inactive, wired, free = cext.virtual_mem()
avail = inactive + free
used = active + inactive + wired
percent = usage_percent((total - avail), total, _round=1)
percent = usage_percent((total - avail), total, round_=1)
return svmem(total, avail, percent, used, free,
active, inactive, wired)


def swap_memory():
"""Swap system memory as a (total, used, free, sin, sout) tuple."""
total, used, free, sin, sout = cext.swap_mem()
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, sin, sout)


Expand Down
2 changes: 1 addition & 1 deletion psutil/_psposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def disk_usage(path):
# User usage percent compared to the total amount of space
# the user can use. This number would be higher if compared
# to root's because the user has less space (usually -5%).
usage_percent_user = usage_percent(used, total_user, _round=1)
usage_percent_user = usage_percent(used, total_user, round_=1)

# NB: the percentage is -5% than what shown by df due to
# reserved blocks that we are currently not considering:
Expand Down
4 changes: 2 additions & 2 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def virtual_memory():
# note: there's no difference on Solaris
free = avail = os.sysconf('SC_AVPHYS_PAGES') * PAGE_SIZE
used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return svmem(total, avail, percent, used, free)


Expand Down Expand Up @@ -163,7 +163,7 @@ def swap_memory():
total += int(int(t) * 512)
free += int(int(f) * 512)
used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent,
sin * PAGE_SIZE, sout * PAGE_SIZE)

Expand Down
6 changes: 3 additions & 3 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def virtual_memory():
avail = availphys
free = availphys
used = total - avail
percent = usage_percent((total - avail), total, _round=1)
percent = usage_percent((total - avail), total, round_=1)
return svmem(total, avail, percent, used, free)


Expand All @@ -227,7 +227,7 @@ def swap_memory():
total = mem[2]
free = mem[3]
used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sswap(total, used, free, percent, 0, 0)


Expand All @@ -247,7 +247,7 @@ def disk_usage(path):
path = path.decode(ENCODING, errors="strict")
total, free = cext.disk_usage(path)
used = total - free
percent = usage_percent(used, total, _round=1)
percent = usage_percent(used, total, round_=1)
return _common.sdiskusage(total, used, free, percent)


Expand Down

0 comments on commit bf79914

Please sign in to comment.