我从我的 cProfile 输出中获得了大约 300 个条目,每次使用它时都必须向上滚动很长时间。
有没有办法让 cProfile 只打印前 10 行之类的东西?
最佳答案
您可以按“累积”排序并使用 print_stats(4) 显示前 N 行。如果不对某些内容进行排序,观看前 N 行可能没有用。
来自 Python profiler official docs
import pstats
p = pstats.Stats('restats')
p.sort_stats('cumulative').print_stats(10)
关于python - 如何让 cProfile 只打印重要的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47564771/