Skip to content

Instantly share code, notes, and snippets.

@yaniv-aknin
Created October 2, 2012 07:16
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 yaniv-aknin/81c0024473f77204cf1f to your computer and use it in GitHub Desktop.
Save yaniv-aknin/81c0024473f77204cf1f to your computer and use it in GitHub Desktop.
rough memory situation snapshotting function
from os import popen
import logging
from uuid import uuid4
try:
from magical_place import some_map_like_backing_store # Redis, memcached, database, whatever
except ImportError:
some_map_like_backing_store = {}
logging.basicConfig(level=logging.DEBUG)
def make_memory_report():
return "\n****\n".join([
popen('ps auxww').read(),
open('/proc/meminfo').read()
])
def store_memory_report(label="unknown"):
key = 'memory_report_' + uuid4().hex
some_map_like_backing_store[key] = key, make_memory_report()
logging.debug('memory report: label=%s, key=%s', label, key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment