简体   繁体   English

Python cProfile:如何从分析数据中过滤出特定的调用?

[英]Python cProfile: how to filter out specific calls from the profiling data?

I've started profiling a script which has many sleep(n) statements. 我已经开始分析一个包含许多sleep(n)语句的脚本。 All in all, I get over 99% of the run time spent sleeping. 总而言之,我花了超过99%的睡眠时间。 Nevertheless, it occasionally runs into performance problems during the time that it does real work but the relevant, interesting profiling data becomes very difficult to identify when eg using kcachegrind. 尽管如此,它在实际工作期间偶尔遇到性能问题但是相关的,有趣的分析数据在例如使用kcachegrind时变得非常难以识别。

Is there a way I can blacklist certain calls/functions from being profiled? 有没有办法可以将某些调用/函数列入黑名单? Alternatively, how can I filter out such call with post-processing of the profiling data file? 或者,如何通过对分析数据文件进行后处理来过滤掉这样的调用?

I'm using the profilestats decorator ( http://pypi.python.org/pypi/profilestats ). 我正在使用profilestats装饰器( http://pypi.python.org/pypi/profilestats )。

Thanks 谢谢

You need more than just excluding samples during sleep(). 您需要的不仅仅是在睡眠期间排除样本()。 You need the remaining samples to tell you something useful. 你需要剩下的样品来告诉你一些有用的东西。 That would be stack sampling, on wall-clock time, summarizing percent at the line-of-code level. 这将是堆栈采样,在挂钟时间,总结代码行级别的百分比。 Zoom is a good tool for this kind of sampling, and I would hope it's not too hard to ignore samples that contain a particular function. Zoom是这种采样的好工具,我希望忽略包含特定功能的样本并不太难。

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

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