Created
August 13, 2013 10:33
-
-
Save georgepsarakis/6219940 to your computer and use it in GitHub Desktop.
Function to return memory consumption for the script itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from resource import getrusage, RUSAGE_SELF | |
def monitor(unit="M", alert=None): | |
unit = unit.upper() | |
unit_transformation = { | |
"B" : 1./1024., | |
"K" : 1., | |
"M" : 1024., | |
"G" : 1024.*1024., | |
} | |
if not unit in unit_transformation.keys(): | |
unit = "K" | |
mem = getrusage(RUSAGE_SELF).ru_maxrss | |
mem /= unit_transformation[unit] | |
if not alert is None: | |
status = mem > alert | |
else: | |
status = None | |
return (status, mem,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment