~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/services/profile/profile.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-03 15:22:48 UTC
  • mfrom: (8758.4.18 garbo-lockfile)
  • Revision ID: launchpad@pqm.canonical.com-20111003152248-cv30fo2i8p0mu5mb
[r=lifeless][bug=553254] Regularly prune LoginToken rows

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
    # still running.
210
210
    assert _profilers.profiler is None
211
211
    actions = get_desired_profile_actions(event.request)
 
212
    _profilers.actions = actions
 
213
    _profilers.profiling = True
212
214
    if config.profiling.profile_all_requests:
213
215
        actions['callgrind'] = ''
214
 
    if config.profiling.memory_profile_log:
215
 
        actions['memory_profile_start'] = (memory(), resident())
216
216
    if actions:
217
217
        if 'sql' in actions:
218
218
            condition = actions['sql']
222
222
        if 'show' in actions or available_profilers.intersection(actions):
223
223
            _profilers.profiler = Profiler()
224
224
            _profilers.profiler.start()
225
 
        _profilers.profiling = True
226
 
        _profilers.actions = actions
 
225
    if config.profiling.memory_profile_log:
 
226
        _profilers.memory_profile_start = (memory(), resident())
227
227
 
228
228
template = PageTemplateFile(
229
229
    os.path.join(os.path.dirname(__file__), 'profile.pt'))
352
352
        template_context['multiple_profiles'] = prof_stats.count > 1
353
353
        # Try to free some more memory.
354
354
        del prof_stats
355
 
    # Dump memory profiling info.
356
 
    if 'memory_profile_start' in actions:
357
 
        log = file(config.profiling.memory_profile_log, 'a')
358
 
        vss_start, rss_start = actions.pop('memory_profile_start')
359
 
        vss_end, rss_end = memory(), resident()
360
 
        if oopsid is None:
361
 
            oopsid = '-'
362
 
        log.write('%s %s %s %f %d %d %d %d\n' % (
363
 
            timestamp, pageid, oopsid, da.get_request_duration(),
364
 
            vss_start, rss_start, vss_end, rss_end))
365
 
        log.close()
366
355
    trace = None
367
356
    if 'sql' in actions:
368
357
        trace = da.stop_sql_logging() or ()
494
483
        new_html = ''.join(
495
484
            (e_start, added_html, e_close_body, e_end))
496
485
        request.response.setResult(new_html)
 
486
    # Dump memory profiling info.
 
487
    if _profilers.memory_profile_start is not None:
 
488
        log = file(config.profiling.memory_profile_log, 'a')
 
489
        vss_start, rss_start = _profilers.memory_profile_start
 
490
        _profilers.memory_profile_start = None
 
491
        vss_end, rss_end = memory(), resident()
 
492
        if oopsid is None:
 
493
            oopsid = '-'
 
494
        log.write('%s %s %s %f %d %d %d %d\n' % (
 
495
            timestamp, pageid, oopsid, da.get_request_duration(),
 
496
            vss_start, rss_start, vss_end, rss_end))
 
497
        log.close()
497
498
 
498
499
 
499
500
def get_desired_profile_actions(request):