def profiled_thread(func):
"""decorator to profile a thread or function. Profiling output will be written to
'agent_profile_<process_id>.<thread_id_>.<thread_name>.log'"""
def wrapper(*args, **kwargs):
profile = Profile()
profile.enable()
try:
func(*args, **kwargs)
finally:
profile.disable()
try:
thread = current_thread()
profile.dump_stats('profile_%s.%s.%s.log' % (getpid(), thread.name, thread.ident))
except:
logger.exception('Failed to dump stats')
return wrapper
评论列表
文章目录