Files
edx-platform/openedx/core/operations.py
Matt Drayer 1eab25f292 mattdrayer/increment-edx-lint: Bump to v0.2.9 and address pylint/pep8 violations
* Fix paver violations to stablize edx-lint update
* Parens, Line2Long
* Fix missing docstrings
* Fix PEP8 issues
* Address PR feedback (thanks @nedbat!)
2015-10-19 10:11:59 -04:00

41 lines
959 B
Python

"""
Workflows useful for reporting on runtime characteristics of the system
"""
import os
import signal
import tempfile
import gc
from datetime import datetime
from meliae import scanner
def dump_memory(signum, frame):
"""
Dump memory stats for the current process to a temp directory.
Uses the meliae output format.
"""
timestamp = datetime.now().isoformat()
format_str = '{}/meliae.{}.{}.{{}}.dump'.format(
tempfile.gettempdir(),
timestamp,
os.getpid(),
)
scanner.dump_all_objects(format_str.format('pre-gc'))
# force garbarge collection
for gen in xrange(3):
gc.collect(gen)
scanner.dump_all_objects(
format_str.format("gc-gen-{}".format(gen))
)
def install_memory_dumper(dump_signal=signal.SIGPROF):
"""
Install a signal handler on `signal` to dump memory stats for the current process.
"""
signal.signal(dump_signal, dump_memory)