Skip to content

Commit

Permalink
Add the ability to send SIGPROF to an edx-platform process to obtain …
Browse files Browse the repository at this point in the history
…a memory dump
  • Loading branch information
cpennington committed Feb 2, 2015
1 parent 03594aa commit a69c4ef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cms/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import contracts
contracts.disable_all()

import os
import openedx.core.operations
openedx.core.operations.install_memory_dumper()

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cms.envs.aws")

import cms.startup as startup
Expand Down
4 changes: 3 additions & 1 deletion lms/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import contracts
contracts.disable_all()

import os
import openedx.core.operations
openedx.core.operations.install_memory_dumper()

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.envs.aws")

import lms.startup as startup
Expand Down
17 changes: 17 additions & 0 deletions openedx/core/operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import signal
import tempfile

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."""
scanner.dump_all_objects('{}/meliae.{}.{}.dump'.format(tempfile.gettempdir(), datetime.now().isoformat(), os.getpid()))

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)
3 changes: 3 additions & 0 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ lazy==1.1
lxml==3.3.6
mako==0.9.1
Markdown==2.2.1
--allow-external meliae
--allow-unverified meliae
meliae==0.4.0
mongoengine==0.7.10
networkx==1.7
nltk==2.0.4
Expand Down
3 changes: 3 additions & 0 deletions requirements/edx/pre.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ numpy==1.6.2

# Needed to make sure that options in base.txt are allowed
pip==6.0.7

# Needed for meliae
Cython==0.21.2

0 comments on commit a69c4ef

Please sign in to comment.