[Pkg-bazaar-commits] ./bzr/unstable r137: new --profile option
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:44:09 UTC 2009
------------------------------------------------------------
revno: 137
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-29 16:25:15 +1000
message:
new --profile option
modified:
NEWS
bzrlib/commands.py
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2005-03-29 06:02:14 +0000
+++ b/NEWS 2005-03-29 06:25:15 +0000
@@ -18,7 +18,9 @@
'deleted' lists files deleted in the current working tree.
* Performance improvements.
-
+
+ * New global --profile option.
+
bzr-0.0.1 2005-03-26
ENHANCEMENTS:
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-03-29 06:10:25 +0000
+++ b/bzrlib/commands.py 2005-03-29 06:25:15 +0000
@@ -604,6 +604,7 @@
'all': None,
'help': None,
'message': unicode,
+ 'profile': None,
'revision': int,
'show-ids': None,
'timezone': str,
@@ -793,7 +794,12 @@
except KeyError:
bailout("unknown command " + `cmd`)
- # TODO: special --profile option to turn on the Python profiler
+ # global option
+ if 'profile' in opts:
+ profile = True
+ del opts['profile']
+ else:
+ profile = False
# check options are reasonable
allowed = cmd_options.get(cmd, [])
@@ -802,11 +808,24 @@
bailout("option %r is not allowed for command %r"
% (oname, cmd))
+ # mix arguments and options into one dictionary
cmdargs = _match_args(cmd, args)
for k, v in opts.items():
cmdargs[k.replace('-', '_')] = v
- ret = cmd_handler(**cmdargs) or 0
+ if profile:
+ import hotshot
+ prof = hotshot.Profile('.bzr.profile')
+ ret = prof.runcall(cmd_handler, **cmdargs) or 0
+ prof.close()
+
+ import hotshot.stats
+ stats = hotshot.stats.load('.bzr.profile')
+ #stats.strip_dirs()
+ stats.sort_stats('cumulative', 'calls')
+ stats.print_stats(20)
+ else:
+ return cmd_handler(**cmdargs) or 0
More information about the Pkg-bazaar-commits
mailing list