[hg] galaxy 2818: Memory debugging patch from James
details: http://www.bx.psu.edu/hg/galaxy/rev/72020a46127e changeset: 2818:72020a46127e user: Nate Coraor <nate@bx.psu.edu> date: Fri Oct 02 09:36:07 2009 -0400 description: Memory debugging patch from James 4 file(s) affected in this change: eggs.ini lib/galaxy/web/buildapp.py lib/galaxy/web/framework/base.py lib/galaxy/web/framework/memdebug.py diffs (89 lines): diff -r 4fb6326ced59 -r 72020a46127e eggs.ini --- a/eggs.ini Fri Oct 02 09:30:50 2009 -0400 +++ b/eggs.ini Fri Oct 02 09:36:07 2009 -0400 @@ -23,6 +23,7 @@ python_lzo = 1.08 threadframe = 0.2 guppy = 0.1.8 +PSI = 0.3b1.1 [eggs:noplatform] amqplib = 0.6.1 @@ -86,6 +87,7 @@ Paste = http://cheeseshop.python.org/packages/source/P/Paste/Paste-1.5.1.tar.gz PasteDeploy = http://cheeseshop.python.org/packages/source/P/PasteDeploy/PasteDeploy-1.3.1... PasteScript = http://cheeseshop.python.org/packages/source/P/PasteScript/PasteScript-1.3.6... +PSI = http://pypi.python.org/packages/source/P/PSI/PSI-0.3b1.1.tar.gz Routes = http://pypi.python.org/packages/source/R/Routes/Routes-1.6.3.tar.gz simplejson = http://cheeseshop.python.org/packages/source/s/simplejson/simplejson-1.5.tar... SQLAlchemy = http://pypi.python.org/packages/source/S/SQLAlchemy/SQLAlchemy-0.4.7p1.tar.g... diff -r 4fb6326ced59 -r 72020a46127e lib/galaxy/web/buildapp.py --- a/lib/galaxy/web/buildapp.py Fri Oct 02 09:30:50 2009 -0400 +++ b/lib/galaxy/web/buildapp.py Fri Oct 02 09:36:07 2009 -0400 @@ -64,7 +64,12 @@ sys.exit( 1 ) atexit.register( app.shutdown ) # Create the universe WSGI application - webapp = galaxy.web.framework.WebApplication( app, session_cookie='galaxysession' ) + if app.config.log_memory_usage: + from galaxy.web.framework.memdebug import MemoryLoggingWebApplication + webapp = MemoryLoggingWebApplication( app, session_cookie='galaxysession' ) + else: + webapp = galaxy.web.framework.WebApplication( app, session_cookie='galaxysession' ) + # Find controllers add_controllers( webapp, app ) # Force /history to go to /root/history -- needed since the tests assume this webapp.add_route( '/history', controller='root', action='history' ) diff -r 4fb6326ced59 -r 72020a46127e lib/galaxy/web/framework/base.py --- a/lib/galaxy/web/framework/base.py Fri Oct 02 09:30:50 2009 -0400 +++ b/lib/galaxy/web/framework/base.py Fri Oct 02 09:36:07 2009 -0400 @@ -122,7 +122,7 @@ # Special key for AJAX debugging, remove to avoid confusing methods kwargs.pop( '_', None ) try: - body = method( trans, **kwargs ) + body = self.call_body_method( method, trans, kwargs ) except Exception, e: body = self.handle_controller_exception( e, trans, **kwargs ) if not body: @@ -139,6 +139,9 @@ start_response( trans.response.wsgi_status(), trans.response.wsgi_headeritems() ) return self.make_body_iterable( trans, body ) + + def call_body_method( self, method, trans, kwargs ): + return method( trans, **kwargs ) def make_body_iterable( self, trans, body ): if isinstance( body, ( types.GeneratorType, list, tuple ) ): diff -r 4fb6326ced59 -r 72020a46127e lib/galaxy/web/framework/memdebug.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/web/framework/memdebug.py Fri Oct 02 09:36:07 2009 -0400 @@ -0,0 +1,26 @@ +""" +Implementation of WebApplication that logs memory usage before and after +calling each controller method. +""" + +import pkg_resources +pkg_resources.require( "PSI" ) +import psi.process + +import os +import logging + +from galaxy.web.framework import WebApplication + +log = logging.getLogger( __name__ ) +pid = os.getpid() + +class MemoryLoggingWebApplication( WebApplication ): + def call_body_method( self, method, trans, kwargs ): + cls = method.im_class + process = psi.process.Process( pid ) + log.debug( "before controller=%s.%s method=%s rss=%d vsz=%d", cls.__module__, cls.__name__, method.__name__, process.rss, process.vsz ) + rval = method( trans, **kwargs ) + process = psi.process.Process( pid ) + log.debug( "after controller=%s.%s method=%s rss=%d vsz=%d", cls.__module__, cls.__name__, method.__name__, process.rss, process.vsz ) + return rval \ No newline at end of file
participants (1)
-
Nate Coraor