Right now I am trying to capture statistics of every request in flask, I am able to capture the time taken for a request to complete. Is there a way to capture the time taken for each function inside a route.
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'
How do I calcualte that call_func() and another_func() took 5 seconds seach in the execution of that route?