简体   繁体   English

Python分析:在每行函数上花费的时间

[英]Python profiling: time spent on each line of function

I have been studying examples from the profile documentation and I have come to the workflow when I run 我一直在研究配置文件中的示例,我在运行时已经进入了工作流程

import cProfile as profile
import pstats

pr = profile.Profile()
pr.runcall(myFunc, args, kwargs)

st = pstats.Stats(pr)
st.print_stats() # and other methods like print_callees, print_callers, etc.

This gives me some general stats of the number of calls made and so on. 这给了我一些关于调用次数等的一般统计数据。 Mind you, it is rather cryptic: I heaviliy use numpy inside myFunc (like numpy.sum , * and the like) but I cannot find those calls in the stats object. 请注意,这是相当神秘的:我在myFunc使用numpy (比如numpy.sum*等),但我无法在stats对象中找到这些调用。 What I would like to see is the time spent on each line of the source code of function myFunc . 我想看到的是在函数myFunc的源代码的每一行上花费的时间。 How do I do that? 我怎么做?

在PyPI - line_profiler上有一个很好的包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM