-
-
Save yaniv-aknin/81c0024473f77204cf1f to your computer and use it in GitHub Desktop.
rough memory situation snapshotting function
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 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