【发布时间】:2020-07-18 12:26:47
【问题描述】:
现在我正在尝试捕获烧瓶中每个请求的统计信息,我能够捕获完成请求所花费的时间。有没有办法捕捉路线内每个功能所花费的时间。
MY Code capturing the time taken by a route
@app.teardown_request
def teardown_func(response):
print("tearing down reqest")
print("Request",request)
required_data = {
"path": request.full_path,
"url": request.url,
"json_data": request.get_json(),
"start": request.start_time,
"stop": dt.utcnow(),
"total_elapsed_time": (dt.utcnow() - request.start_time).total_seconds()
}
print("request data",required_data)
return response
def call_func():
sleep(5)
print("FunctionCalled")
def another_func():
sleep(5)
print("FunctionCalled2")
@app.route('/',methods=['GET','POST'])
def hello2():
time.sleep(10)
call_func()
another_func()
return 'Hello World'
我如何计算 call_func() 和 another_func() 在执行该路由时分别花费了 5 秒?
【问题讨论】:
标签: python python-2.7 flask logging