问题 如何使用带有nosetest的cProfile --with-profile?


nosetest --with-profile --profile-stats-file输出

runsnake无法读取输出,因为nosetest使用hotshot,如果我想生成一个可以使用runsnake读取的文件,我需要将其转换为:

st = hotshot.stats.load('output')

st.dump_stats( 'output_new')

我可以直接使用cProfile运行测试以使用runsnake进行读取吗?


1423
2017-09-02 13:51


起源

看起来很奇怪鼻试会选择热门 - John Salvatier
也许这会很方便: github.com/msherry/nose-cprof ? (我自己也没试过) - uhz


答案:


根据@squid的答案,您可以使用 鼻子 插件叫 nose-cprof 用cProfile替换鼻子默认探查器,hotshot。

要安装它:

pip install nose-cprof

然后像这样打电话给鼻子:

nosetests --with-cprofile

它应该生成一个cProfile输出文件,然后您可以使用类似的工具进行分析 runsnakerun


9
2018-02-22 20:25



我没有运气让插件工作:pip install看起来很好,但是当运行--with-cprofile时,找不到标志。我转而使用--with-profile。 - Priyeshj


@ cihanpesend的回答对我来说不太有用(cProfile找不到'nosetests'),但我确实在Linux上取得了成功:

python -m cProfile -o profile.out `which nosetests` .

结果输出在runsnake中正常工作。

(据推测,在Windows上你可以替换它 which nosetests 使用硬编码路径到您的nosetests顶级python脚本。)

一世 认为 你认为nosetests的hotshot profiler的输出与runsnake不兼容是正确的。当然,对于我来说,这两个人并不是一起打得很好。


3
2017-07-18 14:31





我没有关于nosetest的信息,除了它是python项目。所以;

python -m cProfile -o outputfile nosetest

然后,

runsnake outputfile

RunSnakeRun对于可视化分析器非常有用。

注意:要运行 runsnake,你必须安装wx和numpy。

更新:来自omikron的评论; runsnakerun不支持python3配置文件输出。 (我没试过)


2
2018-06-03 14:56



应当指出的是 runsnakerun 在分析Python 3代码时不起作用,似乎不再维护。相反,我建议使用 pyprof2calltree 同 kcachegrind。 - omikron


或者你可以试试nose-cprof插件:https://github.com/msherry/nose-cprof

它用cProfile取代了hotshot


1
2017-10-22 17:09