当我使用 cProfiler 时,我得到以下行:
ncalls tottime percall cumtime percall filename:lineno(function)
39 12.486 0.320 12.486 0.320 {method 'acquire' of 'thread.lock' objects}
我understood那yappi是要走的路。
所以我在写:
yappi.get_func_stats().print_all()
而且我有太多行要阅读。
如何只检索耗时最多的 10 个?
相当于:
p.sort_stats('time').print_stats(10)
我基本上想知道什么消耗的时间最多。
我确实使用 ThreadPoolExecutor
在我的代码中运行线程
最佳答案
如果你想限制你必须修改print_all
方法的结果,你只能修改排序
用于排序统计
import sys
from yappi import get_func_stats, COLUMNS_FUNCSTATS, COLUMNS_THREADSTATS
# Stats sorted by total time
stats = get_func_stats.sort(
sort_type='totaltime', sort_order='desc')
# returns all stats with sorting applied
print_all(stats, sys.stdout, limit=10)
修改打印
import os
def print_all(stats, out, limit=None):
if stats.empty():
return
sizes = [36, 5, 8, 8, 8]
columns = dict(zip(range(len(COLUMNS_FUNCSTATS)), zip(COLUMNS_FUNCSTATS, sizes)))
show_stats = stats
if limit:
show_stats = stats[:limit]
out.write(os.linesep)
# write out the headers for the func_stats
# write out stats with exclusions applied.
# for stat in show_stats:
# stat._print(out, columns)
关于python - 使用 Yappi 进行分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228201/