[Zope3-checkins] CVS: Zope3/utilities - runurl.py:1.3
Jim Fulton
jim@zope.com
Thu, 15 May 2003 15:01:38 -0400
Update of /cvs-repository/Zope3/utilities
In directory cvs.zope.org:/tmp/cvs-serv18236
Modified Files:
runurl.py
Log Message:
Added support for using the hotshot profiler. We may eventually make
this the default, as it appears to give less biased results.
=== Zope3/utilities/runurl.py 1.2 => 1.3 ===
--- Zope3/utilities/runurl.py:1.2 Tue May 13 17:11:11 2003
+++ Zope3/utilities/runurl.py Thu May 15 15:01:37 2003
@@ -47,6 +47,11 @@
Run the profiler saving the profile data to the given file name
+ --hotshot file
+
+ Run the hotshot profiler saving the profile data to the given
+ file name
+
-w
--warmup
@@ -78,13 +83,13 @@
args,
'b:r:p:d:c:hi:w',
['basic=', 'run=', 'profile=', 'database=', 'config=', 'help',
- 'input=', 'warmup'])
+ 'input=', 'warmup', 'hotshot='])
except getopt.GetoptError:
print __doc__ % {'script': script}
raise
- basic = run = warm = profilef = database = config = None
+ basic = run = warm = profilef = database = config = hotshotf = None
stdin = ''
for name, value in options:
if name in ('-b', '--basic'):
@@ -93,6 +98,8 @@
run = int(value)
elif name in ('-p', '--profile'):
profilef = value
+ elif name in ('--hotshot', ):
+ hotshotf = value
elif name in ('-d', '--database'):
database = value
elif name in ('-c', '--config'):
@@ -121,10 +128,25 @@
if warm:
_mainrun(app, path, basic, 1, stdin, env)
- if profilef:
- import profile
- profile.run("_mainrun(app, path, basic, run, stdin, env)",
- profilef)
+ if profilef or hotshotf:
+ cmd = "_mainrun(app, path, basic, run, stdin, env)"
+ if profilef:
+ import profile
+ profile.run(cmd, profilef)
+ if hotshotf:
+ import hotshot
+ p = hotshot.Profile(hotshotf)
+ p.runctx(cmd, globals(), locals())
+ p.close()
+ del p
+
+ print 'Writing', hotshotf
+ from hotshot.stats import StatsLoader
+ p = StatsLoader(hotshotf).load()
+ import marshal
+ marshal.dump(p.stats, open(hotshotf, 'w'))
+ print 'Wrote', hotshotf
+
else:
_mainrun(app, path, basic, run, stdin, env)