~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-29 06:25:15 UTC
  • Revision ID: mbp@sourcefrog.net-20050329062515-34c2ff87de4698a2
new --profile option

Show diffs side-by-side

added added

removed removed

Lines of Context:
604
604
    'all':                    None,
605
605
    'help':                   None,
606
606
    'message':                unicode,
 
607
    'profile':                None,
607
608
    'revision':               int,
608
609
    'show-ids':               None,
609
610
    'timezone':               str,
793
794
    except KeyError:
794
795
        bailout("unknown command " + `cmd`)
795
796
 
796
 
    # TODO: special --profile option to turn on the Python profiler
 
797
    # global option
 
798
    if 'profile' in opts:
 
799
        profile = True
 
800
        del opts['profile']
 
801
    else:
 
802
        profile = False
797
803
 
798
804
    # check options are reasonable
799
805
    allowed = cmd_options.get(cmd, [])
802
808
            bailout("option %r is not allowed for command %r"
803
809
                    % (oname, cmd))
804
810
 
 
811
    # mix arguments and options into one dictionary
805
812
    cmdargs = _match_args(cmd, args)
806
813
    for k, v in opts.items():
807
814
        cmdargs[k.replace('-', '_')] = v
808
815
 
809
 
    ret = cmd_handler(**cmdargs) or 0
 
816
    if profile:
 
817
        import hotshot
 
818
        prof = hotshot.Profile('.bzr.profile')
 
819
        ret = prof.runcall(cmd_handler, **cmdargs) or 0
 
820
        prof.close()
 
821
 
 
822
        import hotshot.stats
 
823
        stats = hotshot.stats.load('.bzr.profile')
 
824
        #stats.strip_dirs()
 
825
        stats.sort_stats('cumulative', 'calls')
 
826
        stats.print_stats(20)
 
827
    else:
 
828
        return cmd_handler(**cmdargs) or 0
810
829
 
811
830
 
812
831