Created
May 11, 2012 11:39
-
-
Save bleskes/2659155 to your computer and use it in GitHub Desktop.
A WSGI Middleware to interact with Heapy
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
class HeapyMiddleware(object): | |
""" WSGI middlware to activate heapy """ | |
def __init__(self,app): | |
self.app = app | |
def __call__(self, environ, start_response): | |
if environ.get("PATH_INFO") == "/__heapy__": | |
# dump a heapy analysis when the url __heapy__ is called | |
from guppy import hpy | |
hp=hpy() | |
content = str(hp.heap()) | |
start_response("200 OK",[('Content-type' , 'text/html')]) | |
return [ content ] | |
if environ.get("PATH_INFO") == "/__monitor_on__": | |
# activate heapy monitoring. | |
from guppy.heapy.Remote import on | |
on() | |
start_response("200 OK",[('Content-type' , 'text/html')]) | |
return [ "heapy monitor is on." ] | |
if environ.get("PATH_INFO") == "/__monitor_off__": | |
# turn off heapy monitor | |
from guppy.heapy.Remote import off | |
off() | |
start_response("200 OK",[('Content-type' , 'text/html')]) | |
return [ "heapy monitor is off." ] | |
return self.app(environ,start_response) | |
application = HeapyMiddleware(application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment