python Line Profiler装饰器,它适用于纯Python或Web框架,如Flask或Django
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Line Profiler装饰器,它适用于纯Python或Web框架,如Flask或Django相关的知识,希望对你有一定的参考价值。
try:
from line_profiler import LineProfiler
def do_profile(follow=[]):
def inner(func):
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
for f in follow:
profiler.add_function(f)
profiler.enable_by_count()
return func(*args, **kwargs)
finally:
profiler.print_stats()
return profiled_func
return inner
except ImportError:
def do_profile(follow=[]):
def inner(func):
def nothing(*args, **kwargs):
return func(*args, **kwargs)
return nothing
return inner
以上是关于python Line Profiler装饰器,它适用于纯Python或Web框架,如Flask或Django的主要内容,如果未能解决你的问题,请参考以下文章