Flask - 性能分析(Profiling,profiler,profile)


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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM