1. 疑问
@app.cli.command()
@click.option('--length', default=25,
help='Number of functions to include in the profiler report.')
@click.option('--profile-dir', default=None,
help='Directory where profiler data files are saved.')
def profile(length, profile_dir):
"""Start the application under the code profiler."""
from werkzeug.contrib.profiler import ProfilerMiddleware
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[length],
profile_dir=profile_dir)
app.run(debug=False)
flask web狗书的 git reset --hard 16b
flask profile --profile-dir="./profile",生成了后缀为*.prof的文件,我怎么查看这些文件呢?
我发起了一个issue:https://github.com/miguelgrinberg/flasky/issues/365
2. 解决
import sys
from pstats import Stats
my_stat = Stats('file.name', stream=sys.stdout)
my_stat.print_stats()