'the server, e.g. apps/storage.html. The path may optionally end '
'with #n where n is the number of times to render the page before '
'printing it, e.g. apps/storage.html#50, to use for profiling.')
+ parser.add_option('-s', '--stat',
+ help='Print profile stats at the end of the run using the given '
+ 'profiling option (like "tottime"). -t is ignored if this is set.')
parser.add_option('-t', '--time', action='store_true',
help='Print the time taken rendering rather than the result.')
path = opts.render
extra_iterations = 0
- if opts.time:
+ if opts.stat:
+ import cProfile, pstats, StringIO
+ pr = cProfile.Profile()
+ pr.enable()
+ elif opts.time:
start_time = time.time()
response = LocalRenderer.Render(path)
for _ in range(extra_iterations):
LocalRenderer.Render(path)
- if opts.time:
+ if opts.stat:
+ pr.disable()
+ s = StringIO.StringIO()
+ pstats.Stats(pr, stream=s).sort_stats(opts.stat).print_stats()
+ print(s.getvalue())
+ elif opts.time:
print('Took %s seconds' % (time.time() - start_time))
else:
print(response.content.ToString())