Changeset 513


Ignore:
Timestamp:
10/05/08 21:06:06 (5 years ago)
Author:
dgynn
Message:

cleanup temp files and handle concurrent requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/oforgeplugin/share/cgi-bin/trac-profile.wsgi

    r512 r513  
    55#   http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac 
    66#   http://trac.edgewall.org/wiki/TracModWSGI 
     7import os 
    78import sys 
    89sys.stdout = sys.stderr 
    910 
    10 # disable postgres DB connection pooling 
    11 import trac.db.postgres_backend 
    12 trac.db.postgres_backend.PostgreSQLConnection.poolable = False 
    13  
    14 #from trac.web.main import dispatch_request as application 
     11import hotshot, hotshot.stats 
     12from cgi import parse_qs 
    1513 
    1614# TODO: change this to a proper middleware wrapper 
    1715from trac.web.main import dispatch_request 
    1816def application(environ, start_response): 
    19     for k, v in sorted(environ.iteritems()): 
    20         print 'ENV Vars: %s = %s' % (k, v) 
    21     import hotshot, hotshot.stats 
    22     prof = hotshot.Profile("/tmp/wsgi.prof") 
    23     prof.runcall(dispatch_request,environ, start_response) 
     17    tempfilename = "/tmp/wsgi.prof-%s" % environ['UNIQUE_ID'] 
     18    prof = hotshot.Profile(tempfilename) 
     19    response = prof.runcall(dispatch_request,environ, start_response) 
    2420    prof.close() 
    25     stats = hotshot.stats.load("/tmp/wsgi.prof") 
    26     #stats.strip_dirs() 
    27     from cgi import parse_qs 
     21    stats = hotshot.stats.load(tempfilename) 
     22    os.remove(tempfilename) 
     23 
    2824    args=parse_qs(environ['QUERY_STRING']) 
    2925    arg_sort=args.get('PROFILE_SORT',['time'])[0] 
    3026    arg_count=args.get('PROFILE_COUNT',[20])[0] 
     27 
     28    print 'Timings for %s'%environ['REQUEST_URI'] 
     29#    for k, v in sorted(environ.iteritems()): 
     30#        print 'ENV: %s = %s' % (k, v) 
    3131    stats.sort_stats(arg_sort) 
    3232    stats.print_stats(arg_count) 
     33 
     34    return response 
Note: See TracChangeset for help on using the changeset viewer.