Created
July 26, 2015 11:25
-
-
Save endofline/46bf9cdce9d246547391 to your computer and use it in GitHub Desktop.
Rough Memory Usage Estimate for Hangoutsbot
This file contains hidden or 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
import logging, os, sys, resource | |
import psutil # pip3 install psutil | |
import plugins | |
logger = logging.getLogger(__name__) | |
def _initialise(bot): | |
plugins.register_admin_command(["resourcememory", "psutilmemory"]) | |
def resourcememory(bot, event, *args): | |
"""print basic information about memory usage with resource library""" | |
# http://fa.bianp.net/blog/2013/different-ways-to-get-memory-consumption-or-lessons-learned-from-memory_profiler/ | |
rusage_denom = 1024. | |
if sys.platform == 'darwin': | |
# ... it seems that in OSX the output is different units ... | |
rusage_denom = rusage_denom * rusage_denom | |
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom | |
message = "memory (resource): {} MB".format(mem) | |
logger.info(message) | |
bot.send_message_parsed(event.conv, "<b>" + message + "</b>") | |
def psutilmemory(bot, event, *args): | |
"""print basic information about memory usage with psutil library""" | |
# return the memory usage in MB | |
# http://fa.bianp.net/blog/2013/different-ways-to-get-memory-consumption-or-lessons-learned-from-memory_profiler/ | |
process = psutil.Process(os.getpid()) | |
mem = process.memory_info()[0] / float(2 ** 20) | |
message = "memory (psutil): {} MB".format(mem) | |
logger.info(message) | |
bot.send_message_parsed(event.conv, "<b>" + message + "</b>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment