Changeset 1605:f2e583f7cab9
- 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
| r1591 |
r1605 |
|
| 39 | 39 | self.heartbeat = None |
|---|
| 40 | 40 | self.memdump = None |
|---|
| | 41 | self.memory_usage = None |
|---|
| 41 | 42 | # Start the heartbeat process if configured and available |
|---|
| 42 | 43 | if self.config.use_heartbeat: |
|---|
| … | … | |
| 50 | 51 | if memdump.Memdump: |
|---|
| 51 | 52 | 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 |
|---|
| 52 | 57 | def shutdown( self ): |
|---|
| 53 | 58 | self.job_manager.shutdown() |
|---|
| r1604 |
r1605 |
|
| 56 | 56 | self.pbs_dataset_path = kwargs.get('pbs_dataset_path', "" ) |
|---|
| 57 | 57 | 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 ) ) |
|---|
| 60 | 61 | self.ucsc_display_sites = kwargs.get( 'ucsc_display_sites', "main,test,archaea" ).lower().split(",") |
|---|
| 61 | 62 | self.gbrowse_display_sites = kwargs.get( 'gbrowse_display_sites', "wormbase,flybase,elegans" ).lower().split(",") |
|---|
| r1574 |
r1605 |
|
| 485 | 485 | elif egg_name == "threadframe": |
|---|
| 486 | 486 | try: |
|---|
| 487 | | if self.config.get( "app:main", "use_heartbeat" ) == "True": |
|---|
| | 487 | if self.config.get( "app:main", "use_heartbeat" ): |
|---|
| 488 | 488 | return True |
|---|
| 489 | 489 | else: |
|---|
| … | … | |
| 493 | 493 | elif egg_name == "guppy": |
|---|
| 494 | 494 | try: |
|---|
| 495 | | if self.config.get( "app:main", "use_memdump" ) == "True": |
|---|
| | 495 | if self.config.get( "app:main", "use_memdump" ): |
|---|
| 496 | 496 | return True |
|---|
| 497 | 497 | else: |
|---|
| r1600 |
r1605 |
|
| 66 | 66 | |
|---|
| 67 | 67 | 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() |
|---|
| 68 | 71 | out_data = {} |
|---|
| 69 | 72 | # Collect any input datasets from the incoming parameters |
|---|
| … | … | |
| 199 | 202 | job.add_output_dataset( name, dataset ) |
|---|
| 200 | 203 | 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 ) ) |
|---|
| 201 | 207 | # Some tools are not really executable, but jobs are still created for them ( for record keeping ). |
|---|
| 202 | 208 | # Examples include tools that redirect to other applications ( epigraph ). These special tools must |
|---|
| r1603 |
r1605 |
|
| 16 | 16 | |
|---|
| 17 | 17 | 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() |
|---|
| 18 | 21 | data_file = incoming['file_data'] |
|---|
| 19 | 22 | file_type = incoming['file_type'] |
|---|
| … | … | |
| 94 | 97 | log.info( 'job id %d ended ok, file size: %s' % ( job.id, file_size_str ) ) |
|---|
| 95 | 98 | 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 ) ) |
|---|
| 96 | 102 | return dict( output=hda ) |
|---|
| 97 | 103 | |
|---|
| r1600 |
r1605 |
|
| 117 | 117 | Sets the mime-type according to the extension |
|---|
| 118 | 118 | """ |
|---|
| | 119 | if trans.app.memory_usage: |
|---|
| | 120 | # Keep track of memory usage |
|---|
| | 121 | m0 = self.app.memory_usage.memory() |
|---|
| 119 | 122 | if hid is not None: |
|---|
| 120 | 123 | try: |
|---|
| … | … | |
| 147 | 150 | trans.response.headers["Content-Disposition"] = "attachment; filename=GalaxyHistoryItem-%s-[%s]%s" % (data.hid, fname, toext) |
|---|
| 148 | 151 | 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 ) |
|---|
| 149 | 155 | try: |
|---|
| 150 | 156 | return open( data.file_name ) |
|---|
| … | … | |
| 322 | 328 | def history_delete( self, trans, id=None, **kwd): |
|---|
| 323 | 329 | """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() |
|---|
| 324 | 333 | history_names = [] |
|---|
| 325 | 334 | if id: |
|---|
| … | … | |
| 349 | 358 | else: |
|---|
| 350 | 359 | 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 ) |
|---|
| 351 | 363 | return trans.show_message( "History deleted: %s" % ",".join(history_names), |
|---|
| 352 | 364 | refresh_frames=['history']) |
|---|
| … | … | |
| 355 | 367 | def history_undelete( self, trans, id=[], **kwd): |
|---|
| 356 | 368 | """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() |
|---|
| 357 | 372 | history_names = [] |
|---|
| 358 | 373 | errors = [] |
|---|
| … | … | |
| 386 | 401 | else: |
|---|
| 387 | 402 | 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 ) |
|---|
| 388 | 406 | return self.history_available( trans, id=','.join( id ), show_deleted=True, ok_msg = ok_msg, error_msg = " ".join( errors ) ) |
|---|
| 389 | 407 | |
|---|
| … | … | |
| 391 | 409 | def clear_history( self, trans ): |
|---|
| 392 | 410 | """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() |
|---|
| 393 | 414 | history = trans.get_history() |
|---|
| 394 | 415 | for dataset in history.datasets: |
|---|
| … | … | |
| 397 | 418 | self.app.model.flush() |
|---|
| 398 | 419 | 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 ) |
|---|
| 399 | 423 | trans.response.send_redirect( url_for("/index" ) ) |
|---|
| 400 | 424 | |
|---|
| … | … | |
| 402 | 426 | @web.require_login( "share histories with other users" ) |
|---|
| 403 | 427 | 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() |
|---|
| 404 | 431 | send_to_err = "" |
|---|
| 405 | 432 | if not id: |
|---|
| … | … | |
| 428 | 455 | self.app.model.flush() |
|---|
| 429 | 456 | 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 ) |
|---|
| 430 | 460 | return trans.fill_template( "/history/share.mako", histories=histories, email=email, send_to_err=send_to_err) |
|---|
| 431 | 461 | |
|---|
| … | … | |
| 436 | 466 | List all available histories |
|---|
| 437 | 467 | """ |
|---|
| | 468 | if trans.app.memory_usage: |
|---|
| | 469 | # Keep track of memory usage |
|---|
| | 470 | m0 = self.app.memory_usage.memory() |
|---|
| 438 | 471 | if as_xml: |
|---|
| 439 | 472 | trans.response.set_content_type('text/xml') |
|---|
| … | … | |
| 442 | 475 | id = id.split( "," ) |
|---|
| 443 | 476 | trans.log_event( "History id %s available" % str( id ) ) |
|---|
| 444 | | |
|---|
| 445 | 477 | 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 ) |
|---|
| 447 | 481 | if do_operation in history_operations: |
|---|
| 448 | 482 | return history_operations[do_operation]( trans, id=id, show_deleted=show_deleted, ok_msg=ok_msg, error_msg=error_msg, **kwd ) |
|---|
| 449 | | |
|---|
| 450 | 483 | return trans.fill_template( "/history/list.mako", ids=id, |
|---|
| 451 | 484 | user=trans.get_user(), |
|---|
| … | … | |
| 458 | 491 | @web.expose |
|---|
| 459 | 492 | 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() |
|---|
| 460 | 496 | msg = "" |
|---|
| 461 | 497 | user = trans.get_user() |
|---|
| … | … | |
| 498 | 534 | trans.set_history( new_history ) |
|---|
| 499 | 535 | 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 ) |
|---|
| 500 | 539 | return trans.show_ok_message( """ |
|---|
| 501 | 540 | History "%s" has been imported. Click <a href="%s">here</a> |
|---|
| … | … | |
| 512 | 551 | return trans.response.send_redirect( web.url_for( action='history_available' ) ) |
|---|
| 513 | 552 | else: |
|---|
| | 553 | if trans.app.memory_usage: |
|---|
| | 554 | # Keep track of memory usage |
|---|
| | 555 | m0 = self.app.memory_usage.memory() |
|---|
| 514 | 556 | new_history = trans.app.model.History.get( id ) |
|---|
| 515 | 557 | if new_history: |
|---|
| … | … | |
| 523 | 565 | trans.set_history( new_history ) |
|---|
| 524 | 566 | 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 ) |
|---|
| 525 | 570 | return trans.show_message( "History switched to: %s" % new_history.name, |
|---|
| 526 | 571 | refresh_frames=['history']) |
|---|
| … | … | |
| 530 | 575 | @web.expose |
|---|
| 531 | 576 | def history_new( self, trans ): |
|---|
| | 577 | if trans.app.memory_usage: |
|---|
| | 578 | # Keep track of memory usage |
|---|
| | 579 | m0 = self.app.memory_usage.memory() |
|---|
| 532 | 580 | trans.new_history() |
|---|
| 533 | 581 | 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 ) |
|---|
| 534 | 585 | return trans.show_message( "New history created", refresh_frames = ['history'] ) |
|---|
| 535 | 586 | |
|---|
| … | … | |
| 537 | 588 | @web.require_login( "renames histories" ) |
|---|
| 538 | 589 | 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() |
|---|
| 539 | 593 | user = trans.get_user() |
|---|
| 540 | 594 | |
|---|
| … | … | |
| 573 | 627 | else: |
|---|
| 574 | 628 | 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 ) |
|---|
| 575 | 632 | return trans.show_message( "<p>%s" % change_msg, refresh_frames=['history'] ) |
|---|
| 576 | 633 | |
|---|
| … | … | |
| 578 | 635 | def history_add_to( self, trans, history_id=None, file_data=None, name="Data Added to History",info=None,ext="txt",dbkey="?",**kwd ): |
|---|
| 579 | 636 | """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() |
|---|
| 580 | 640 | try: |
|---|
| 581 | 641 | history = trans.app.model.History.get( history_id ) |
|---|
| … | … | |
| 596 | 656 | data.flush() |
|---|
| 597 | 657 | 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 ) |
|---|
| 598 | 661 | return trans.show_ok_message("Dataset "+str(data.hid)+" added to history "+str(history_id)+".") |
|---|
| 599 | 662 | except: |
|---|
| … | … | |
| 603 | 666 | def dataset_make_primary( self, trans, id=None): |
|---|
| 604 | 667 | """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() |
|---|
| 605 | 671 | try: |
|---|
| 606 | 672 | old_data = self.app.model.HistoryDatasetAssociation.get( id ) |
|---|
| … | … | |
| 611 | 677 | history.add_dataset(new_data) |
|---|
| 612 | 678 | 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 ) |
|---|
| 613 | 682 | return trans.show_message( "<p>Secondary dataset has been made primary.</p>", refresh_frames=['history'] ) |
|---|
| 614 | 683 | except: |
|---|
| r1600 |
r1605 |
|
| 71 | 71 | @web.expose |
|---|
| 72 | 72 | 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() |
|---|
| 73 | 76 | email_error = password_error = None |
|---|
| 74 | 77 | # Attempt login |
|---|
| … | … | |
| 86 | 89 | trans.log_event( "User logged in" ) |
|---|
| 87 | 90 | 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 ) |
|---|
| 88 | 94 | return trans.show_form( |
|---|
| 89 | 95 | web.FormBuilder( web.url_for(), "Login", submit_text="Login" ) |
|---|
| … | … | |
| 93 | 99 | @web.expose |
|---|
| 94 | 100 | def logout( self, trans ): |
|---|
| | 101 | if trans.app.memory_usage: |
|---|
| | 102 | # Keep track of memory usage |
|---|
| | 103 | m0 = trans.app.memory_usage.memory() |
|---|
| 95 | 104 | # Since logging an event requires a session, we'll log prior to ending the session |
|---|
| 96 | 105 | trans.log_event( "User logged out" ) |
|---|
| 97 | 106 | 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 ) |
|---|
| 98 | 110 | return trans.show_ok_message( "You are no longer logged in", refresh_frames=['masthead', 'history'] ) |
|---|
| 99 | 111 | |
|---|
| 100 | 112 | @web.expose |
|---|
| 101 | 113 | 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() |
|---|
| 102 | 117 | email_error = password_error = confirm_error = None |
|---|
| 103 | 118 | if email: |
|---|
| … | … | |
| 121 | 136 | #subscribe user to email list |
|---|
| 122 | 137 | 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) ) |
|---|
| 125 | 140 | if mail.close(): |
|---|
| 126 | 141 | 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 ) |
|---|
| 127 | 145 | return trans.show_ok_message( "Now logged in as " + user.email, refresh_frames=['masthead', 'history'] ) |
|---|
| 128 | 146 | return trans.show_form( |
|---|
| … | … | |
| 146 | 164 | for i in range(15): |
|---|
| 147 | 165 | 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') |
|---|
| 149 | 167 | 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) ) |
|---|
| 150 | 168 | if mail.close(): |
|---|
| r1591 |
r1605 |
|
| 16 | 16 | paste.app_factory = galaxy.web.buildapp:app_factory |
|---|
| 17 | 17 | log_level = DEBUG |
|---|
| | 18 | |
|---|
| | 19 | # Log memory usage |
|---|
| | 20 | log_memory_usage = False |
|---|
| 18 | 21 | |
|---|
| 19 | 22 | # Should jobs be tracked through the database, rather than in memory |
|---|