wangymd
import cProfile
import pstats

from flask import Flask,jsonify, request

@app.route("/test", methods=[\'GET\', \'POST\'])
def test():
    pr = cProfile.Profile()
    pr.enable() # enable():开始收集性能分析数据

    #业务逻辑
  if request.method == \'POST\':
  x = jsonify(do(**dict(request.form)))
  else:
  x = jsonify(do(**dict(request.args)))
    pr.disable() # disable():停止收集性能分析数据
stats = \'profiling.dump\' pr.dump_stats(stats) 
ps
= pstats.Stats(pr).strip_dirs()
ps.sort_stats(
\'cumtime\').print_stats(100) # cumtime:之前所有子函数消费时间的累计和
ps.sort_stats(
\'tottime\').print_stats(100) # tottime:函数内部消耗的总时间。(可以帮助优化)

return x
app
= Flask(__name__)

if __name__ == \'__main__\': app.run(host=\'0.0.0.0\', port=7316, debug = True)

 

分类:

技术点:

相关文章:

  • 2021-10-14
  • 2021-09-09
  • 2021-09-09
  • 2021-12-15
  • 2021-11-02
  • 2021-09-19
  • 2021-11-07
  • 2021-11-01
猜你喜欢
  • 2021-11-07
  • 2021-05-18
  • 2021-09-29
  • 2021-09-19
  • 2021-12-08
  • 2021-10-08
相关资源
相似解决方案