Changeset 1605:f2e583f7cab9

Show
Ignore:
Timestamp:
11/04/08 16:04:49 (2 months ago)
Author:
Greg Von Kuster <greg@bx.psu.edu>
branch:
default
Message:

Add ability to track memory usage in code secments - requires config addition:

# Log memory usage
log_memory_usage = False

Added logging statements in tool execution methods and most methods in the user and root controllers.

Also fixes for checking config settings that should be boolean ( e.g., memdump, heartbeat ).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/galaxy/app.py

    r1591 r1605  
    3939        self.heartbeat = None 
    4040        self.memdump = None 
     41        self.memory_usage = None 
    4142        # Start the heartbeat process if configured and available 
    4243        if self.config.use_heartbeat: 
     
    5051            if memdump.Memdump: 
    5152                self.memdump = memdump.Memdump() 
     53        # Enable memory_usage logging if configured 
     54        if self.config.log_memory_usage: 
     55            from galaxy.util import memory_usage 
     56            self.memory_usage = memory_usage 
    5257    def shutdown( self ): 
    5358        self.job_manager.shutdown() 
  • lib/galaxy/config.py

    r1604 r1605  
    5656        self.pbs_dataset_path = kwargs.get('pbs_dataset_path', "" ) 
    5757        self.pbs_stage_path = kwargs.get('pbs_stage_path', "" ) 
    58         self.use_heartbeat = string_as_bool( kwargs.get( 'use_heartbeat', "False" ) ) 
    59         self.use_memdump = kwargs.get( 'use_memdump', False ) 
     58        self.use_heartbeat = string_as_bool( kwargs.get( 'use_heartbeat', False ) ) 
     59        self.use_memdump = string_as_bool( kwargs.get( 'use_memdump', False ) ) 
     60        self.log_memory_usage = string_as_bool( kwargs.get( 'log_memory_usage', False ) ) 
    6061        self.ucsc_display_sites = kwargs.get( 'ucsc_display_sites', "main,test,archaea" ).lower().split(",") 
    6162        self.gbrowse_display_sites = kwargs.get( 'gbrowse_display_sites', "wormbase,flybase,elegans" ).lower().split(",") 
  • lib/galaxy/eggs/__init__.py

    r1574 r1605  
    485485        elif egg_name == "threadframe": 
    486486            try: 
    487                 if self.config.get( "app:main", "use_heartbeat" ) == "True"
     487                if self.config.get( "app:main", "use_heartbeat" )
    488488                    return True 
    489489                else: 
     
    493493        elif egg_name == "guppy": 
    494494            try: 
    495                 if self.config.get( "app:main", "use_memdump" ) == "True"
     495                if self.config.get( "app:main", "use_memdump" )
    496496                    return True 
    497497                else: 
  • lib/galaxy/tools/actions/__init__.py

    r1600 r1605  
    6666     
    6767    def execute(self, tool, trans, incoming={}, set_output_hid=True ): 
     68        if trans.app.memory_usage: 
     69            # Keep track of memory usage 
     70            m0 = trans.app.memory_usage.memory() 
    6871        out_data = {} 
    6972        # Collect any input datasets from the incoming parameters 
     
    199202            job.add_output_dataset( name, dataset ) 
    200203        trans.app.model.flush() 
     204        if trans.app.memory_usage: 
     205            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     206            log.info("End of tool %s execution for job id %d, memory used increased by %s"  % ( tool.id, job.id, m1 ) ) 
    201207        # Some tools are not really executable, but jobs are still created for them ( for record keeping ). 
    202208        # Examples include tools that redirect to other applications ( epigraph ).  These special tools must 
  • lib/galaxy/tools/actions/upload.py

    r1603 r1605  
    1616     
    1717    def execute( self, tool, trans, incoming={}, set_output_hid = True ): 
     18        if trans.app.memory_usage: 
     19            # Keep track of memory usage 
     20            m0 = trans.app.memory_usage.memory() 
    1821        data_file = incoming['file_data'] 
    1922        file_type = incoming['file_type'] 
     
    9497        log.info( 'job id %d ended ok, file size: %s' % ( job.id, file_size_str ) ) 
    9598        trans.log_event( 'job id %d ended ok, file size: %s' % ( job.id, file_size_str ), tool_id=tool.id ) 
     99        if trans.app.memory_usage: 
     100            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     101            log.info("End of tool %s execution for job id %d, memory used increased by %s"  % ( tool.id, job.id, m1 ) ) 
    96102        return dict( output=hda ) 
    97103 
  • lib/galaxy/web/controllers/root.py

    r1600 r1605  
    117117        Sets the mime-type according to the extension 
    118118        """ 
     119        if trans.app.memory_usage: 
     120            # Keep track of memory usage 
     121            m0 = self.app.memory_usage.memory() 
    119122        if hid is not None: 
    120123            try: 
     
    147150                trans.response.headers["Content-Disposition"] = "attachment; filename=GalaxyHistoryItem-%s-[%s]%s" % (data.hid, fname, toext) 
    148151            trans.log_event( "Display dataset id: %s" % str(id) ) 
     152            if self.app.memory_usage: 
     153                m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     154                log.info( "End of root/display, memory used increased by %s"  % m1 ) 
    149155            try: 
    150156                return open( data.file_name ) 
     
    322328    def history_delete( self, trans, id=None, **kwd): 
    323329        """Deletes a list of histories, ensures that histories are owned by current user""" 
     330        if trans.app.memory_usage: 
     331            # Keep track of memory usage 
     332            m0 = self.app.memory_usage.memory() 
    324333        history_names = [] 
    325334        if id: 
     
    349358        else: 
    350359            return trans.show_message( "You must select at least one history to delete." ) 
     360        if self.app.memory_usage: 
     361            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     362            log.info( "End of root/history_delete, memory used increased by %s"  % m1 ) 
    351363        return trans.show_message( "History deleted: %s" % ",".join(history_names), 
    352364                                           refresh_frames=['history']) 
     
    355367    def history_undelete( self, trans, id=[], **kwd): 
    356368        """Undeletes a list of histories, ensures that histories are owned by current user""" 
     369        if trans.app.memory_usage: 
     370            # Keep track of memory usage 
     371            m0 = self.app.memory_usage.memory() 
    357372        history_names = [] 
    358373        errors = [] 
     
    386401        else: 
    387402            errors.append( "You must select at least one history to undelete." ) 
     403        if self.app.memory_usage: 
     404            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     405            log.info( "End of root/history_undelete, memory used increased by %s"  % m1 ) 
    388406        return self.history_available( trans, id=','.join( id ), show_deleted=True, ok_msg = ok_msg, error_msg = "  ".join( errors )  ) 
    389407     
     
    391409    def clear_history( self, trans ): 
    392410        """Clears the history for a user""" 
     411        if trans.app.memory_usage: 
     412            # Keep track of memory usage 
     413            m0 = self.app.memory_usage.memory() 
    393414        history = trans.get_history() 
    394415        for dataset in history.datasets: 
     
    397418        self.app.model.flush() 
    398419        trans.log_event( "History id %s cleared" % (str(history.id)) ) 
     420        if self.app.memory_usage: 
     421            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     422            log.info( "End of root/clear_history, memory used increased by %s"  % m1 ) 
    399423        trans.response.send_redirect( url_for("/index" ) ) 
    400424 
     
    402426    @web.require_login( "share histories with other users" ) 
    403427    def history_share( self, trans, id=None, email="", **kwd ): 
     428        if trans.app.memory_usage: 
     429            # Keep track of memory usage 
     430            m0 = self.app.memory_usage.memory() 
    404431        send_to_err = "" 
    405432        if not id: 
     
    428455            self.app.model.flush() 
    429456            return trans.show_message( "History (%s) has been shared with: %s" % (",".join(history_names),email) ) 
     457        if self.app.memory_usage: 
     458            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     459            log.info( "End of root/history_share, memory used increased by %s"  % m1 ) 
    430460        return trans.fill_template( "/history/share.mako", histories=histories, email=email, send_to_err=send_to_err) 
    431461 
     
    436466        List all available histories 
    437467        """ 
     468        if trans.app.memory_usage: 
     469            # Keep track of memory usage 
     470            m0 = self.app.memory_usage.memory() 
    438471        if as_xml: 
    439472            trans.response.set_content_type('text/xml') 
     
    442475            id = id.split( "," ) 
    443476        trans.log_event( "History id %s available" % str( id ) ) 
    444          
    445477        history_operations = dict( share=self.history_share, rename=self.history_rename, delete=self.history_delete, undelete=self.history_undelete ) 
    446          
     478        if self.app.memory_usage: 
     479            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     480            log.info( "End of root/history_available, memory used increased by %s"  % m1 ) 
    447481        if do_operation in history_operations: 
    448482            return history_operations[do_operation]( trans, id=id, show_deleted=show_deleted, ok_msg=ok_msg, error_msg=error_msg, **kwd  ) 
    449  
    450483        return trans.fill_template( "/history/list.mako", ids=id, 
    451484                                    user=trans.get_user(), 
     
    458491    @web.expose 
    459492    def history_import( self, trans, id=None, confirm=False, **kwd ): 
     493        if trans.app.memory_usage: 
     494            # Keep track of memory usage 
     495            m0 = self.app.memory_usage.memory() 
    460496        msg = "" 
    461497        user = trans.get_user() 
     
    498534            trans.set_history( new_history ) 
    499535            trans.log_event( "History imported, id: %s, name: '%s': " % (str(new_history.id) , new_history.name ) ) 
     536            if self.app.memory_usage: 
     537                m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     538                log.info( "End of root/history_import, memory used increased by %s"  % m1 ) 
    500539            return trans.show_ok_message( """ 
    501540                History "%s" has been imported. Click <a href="%s">here</a> 
     
    512551            return trans.response.send_redirect( web.url_for( action='history_available' ) ) 
    513552        else: 
     553            if trans.app.memory_usage: 
     554                # Keep track of memory usage 
     555                m0 = self.app.memory_usage.memory() 
    514556            new_history = trans.app.model.History.get( id ) 
    515557            if new_history: 
     
    523565                trans.set_history( new_history ) 
    524566                trans.log_event( "History switched to id: %s, name: '%s'" % (str(new_history.id), new_history.name ) ) 
     567                if self.app.memory_usage: 
     568                    m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     569                    log.info( "End of root/history_switch, memory used increased by %s"  % m1 ) 
    525570                return trans.show_message( "History switched to: %s" % new_history.name, 
    526571                                           refresh_frames=['history']) 
     
    530575    @web.expose 
    531576    def history_new( self, trans ): 
     577        if trans.app.memory_usage: 
     578            # Keep track of memory usage 
     579            m0 = self.app.memory_usage.memory() 
    532580        trans.new_history() 
    533581        trans.log_event( "Created new History, id: %s." % str(trans.get_history().id) ) 
     582        if self.app.memory_usage: 
     583            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     584            log.info( "End of root/history_new, memory used increased by %s"  % m1 ) 
    534585        return trans.show_message( "New history created", refresh_frames = ['history'] ) 
    535586 
     
    537588    @web.require_login( "renames histories" ) 
    538589    def history_rename( self, trans, id=None, name=None, **kwd ): 
     590        if trans.app.memory_usage: 
     591            # Keep track of memory usage 
     592            m0 = self.app.memory_usage.memory() 
    539593        user = trans.get_user() 
    540594 
     
    573627            else: 
    574628                change_msg = change_msg + "<p>History: "+cur_names[i]+" does not appear to belong to you.</p>" 
     629        if self.app.memory_usage: 
     630            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     631            log.info( "End of root/history_rename, memory used increased by %s"  % m1 ) 
    575632        return trans.show_message( "<p>%s" % change_msg, refresh_frames=['history'] )  
    576633 
     
    578635    def history_add_to( self, trans, history_id=None, file_data=None, name="Data Added to History",info=None,ext="txt",dbkey="?",**kwd ): 
    579636        """Adds a POSTed file to a History""" 
     637        if trans.app.memory_usage: 
     638            # Keep track of memory usage 
     639            m0 = self.app.memory_usage.memory() 
    580640        try: 
    581641            history = trans.app.model.History.get( history_id ) 
     
    596656            data.flush() 
    597657            trans.log_event("Added dataset %d to history %d" %(data.id, trans.history.id)) 
     658            if self.app.memory_usage: 
     659                m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     660                log.info( "End of root/history_add_to, memory used increased by %s"  % m1 ) 
    598661            return trans.show_ok_message("Dataset "+str(data.hid)+" added to history "+str(history_id)+".") 
    599662        except: 
     
    603666    def dataset_make_primary( self, trans, id=None): 
    604667        """Copies a dataset and makes primary""" 
     668        if trans.app.memory_usage: 
     669            # Keep track of memory usage 
     670            m0 = self.app.memory_usage.memory() 
    605671        try: 
    606672            old_data = self.app.model.HistoryDatasetAssociation.get( id ) 
     
    611677            history.add_dataset(new_data) 
    612678            new_data.flush() 
     679            if self.app.memory_usage: 
     680                m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     681                log.info( "End of root/dataset_make_primary, memory used increased by %s"  % m1 ) 
    613682            return trans.show_message( "<p>Secondary dataset has been made primary.</p>", refresh_frames=['history'] )  
    614683        except: 
  • lib/galaxy/web/controllers/user.py

    r1600 r1605  
    7171    @web.expose 
    7272    def login( self, trans, email='', password='' ): 
     73        if trans.app.memory_usage: 
     74            # Keep track of memory usage 
     75            m0 = trans.app.memory_usage.memory() 
    7376        email_error = password_error = None 
    7477        # Attempt login 
     
    8689                trans.log_event( "User logged in" ) 
    8790                return trans.show_ok_message( "Now logged in as " + user.email, refresh_frames=['masthead', 'history'] ) 
     91        if trans.app.memory_usage: 
     92            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     93            log.info( "End of user/login, memory used increased by %s"  % m1 ) 
    8894        return trans.show_form(  
    8995            web.FormBuilder( web.url_for(), "Login", submit_text="Login" ) 
     
    9399    @web.expose 
    94100    def logout( self, trans ): 
     101        if trans.app.memory_usage: 
     102            # Keep track of memory usage 
     103            m0 = trans.app.memory_usage.memory() 
    95104        # Since logging an event requires a session, we'll log prior to ending the session 
    96105        trans.log_event( "User logged out" ) 
    97106        trans.handle_user_logout() 
     107        if trans.app.memory_usage: 
     108            m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     109            log.info( "End of user/logout, memory used increased by %s"  % m1 ) 
    98110        return trans.show_ok_message( "You are no longer logged in", refresh_frames=['masthead', 'history'] ) 
    99111             
    100112    @web.expose 
    101113    def create( self, trans, email='', password='', confirm='',subscribe=False ): 
     114        if trans.app.memory_usage: 
     115            # Keep track of memory usage 
     116            m0 = trans.app.memory_usage.memory() 
    102117        email_error = password_error = confirm_error = None 
    103118        if email: 
     
    121136                #subscribe user to email list 
    122137                if subscribe: 
    123                     mail = os.popen("%s -t" % self.app.config.sendmail_path, 'w') 
    124                     mail.write("To: %s\nFrom: %s\nSubject: Join Mailing List\n\nJoin Mailing list." % (self.app.config.mailing_join_addr,email) ) 
     138                    mail = os.popen("%s -t" % trans.app.config.sendmail_path, 'w') 
     139                    mail.write("To: %s\nFrom: %s\nSubject: Join Mailing List\n\nJoin Mailing list." % (trans.app.config.mailing_join_addr,email) ) 
    125140                    if mail.close(): 
    126141                        return trans.show_warn_message( "Now logged in as " + user.email+". However, subscribing to the mailing list has failed.", refresh_frames=['masthead', 'history'] ) 
     142                if trans.app.memory_usage: 
     143                    m1 = trans.app.memory_usage.memory( m0, pretty=True ) 
     144                    log.info( "End of user/create, memory used increased by %s"  % m1 ) 
    127145                return trans.show_ok_message( "Now logged in as " + user.email, refresh_frames=['masthead', 'history'] ) 
    128146        return trans.show_form(  
     
    146164                for i in range(15): 
    147165                    new_pass = new_pass + choice(chars) 
    148                 mail = os.popen("%s -t" % self.app.config.sendmail_path, 'w') 
     166                mail = os.popen("%s -t" % trans.app.config.sendmail_path, 'w') 
    149167                mail.write("To: %s\nFrom: no-reply@%s\nSubject: Galaxy Password Reset\n\nYour password has been reset to \"%s\" (no quotes)." % (email, trans.request.remote_addr, new_pass) ) 
    150168                if mail.close(): 
  • universe_wsgi.ini.sample

    r1591 r1605  
    1616paste.app_factory = galaxy.web.buildapp:app_factory 
    1717log_level = DEBUG 
     18 
     19# Log memory usage 
     20log_memory_usage = False 
    1821 
    1922# Should jobs be tracked through the database, rather than in memory