~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-10-04 02:30:26 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: mbp@sourcefrog.net-20051004023026-3f4b561c627084f7
- clean up profile code and change default sort order

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
# Those objects can specify the expected type of the argument, which
39
39
# would help with validation and shell completion.
40
40
 
 
41
# TODO: "--profile=cum", to change sort order.  Is there any value in leaving
 
42
# the profile output behind so it can be interactively examined?
 
43
 
41
44
 
42
45
 
43
46
import sys
532
535
def apply_profiled(the_callable, *args, **kwargs):
533
536
    import hotshot
534
537
    import tempfile
 
538
    import hotshot.stats
535
539
    pffileno, pfname = tempfile.mkstemp()
536
540
    try:
537
541
        prof = hotshot.Profile(pfname)
539
543
            ret = prof.runcall(the_callable, *args, **kwargs) or 0
540
544
        finally:
541
545
            prof.close()
542
 
 
543
 
        import hotshot.stats
544
546
        stats = hotshot.stats.load(pfname)
545
 
        #stats.strip_dirs()
546
 
        stats.sort_stats('time')
 
547
        stats.strip_dirs()
 
548
        stats.sort_stats('cum')   # 'time'
547
549
        ## XXX: Might like to write to stderr or the trace file instead but
548
550
        ## print_stats seems hardcoded to stdout
549
551
        stats.print_stats(20)
550
 
 
551
552
        return ret
552
553
    finally:
553
554
        os.close(pffileno)