Skip to content

Instantly share code, notes, and snippets.

@endofline
Created July 26, 2015 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endofline/46bf9cdce9d246547391 to your computer and use it in GitHub Desktop.
Save endofline/46bf9cdce9d246547391 to your computer and use it in GitHub Desktop.
Rough Memory Usage Estimate for Hangoutsbot
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