Skip to content

Commit 19424c7

Browse files
Chapter 16: Source code profiling (16b)
1 parent 97446ad commit 19424c7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

flasky.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@ def test(coverage, test_names):
4949
COV.html_report(directory=covdir)
5050
print('HTML version: file://%s/index.html' % covdir)
5151
COV.erase()
52+
53+
54+
@app.cli.command()
55+
@click.option('--length', default=25,
56+
help='Number of functions to include in the profiler report.')
57+
@click.option('--profile-dir', default=None,
58+
help='Directory where profiler data files are saved.')
59+
def profile(length, profile_dir):
60+
"""Start the application under the code profiler."""
61+
from werkzeug.contrib.profiler import ProfilerMiddleware
62+
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length],
63+
profile_dir=profile_dir)
64+
app.run(debug=False)

0 commit comments

Comments
 (0)