如何使用cProfile和nosetest with profile?

2024-09-20 23:04:25 发布

您现在位置:Python中文网/ 问答频道 /正文

nosetest --with-profile --profile-stats-file output

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

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

st.dump_stats('output_new')

我可以用cProfile直接用runsnake运行这个测试吗?在


Tags: 文件newoutputstatswithloadprofiledump
3条回答

@cihanpesend的回答对我来说不太管用(cProfile找不到“nosetests”),但我确实在Linux上成功地使用了:

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

结果输出在runsnake中运行良好。在

(大概在Windows上,您可以将which nosetests替换为noestests顶级python脚本的硬编码路径。)

我认为nosetests的hotshot profiler的输出与runsnake不兼容。当然,这两个也不太适合我。在

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

python -m cProfile -o outputfile nosetest

然后

^{pr2}$

RunSnakeRun对于可视化profiler非常有用。在

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

从pythomin的输出不能更新。(我没试过)

根据@squid的答案,您可以使用一个名为^{}nose插件,用cProfile替换nose默认的profiler hotshot。在

要安装它:

pip install nose-cprof

然后这样叫鼻子:

^{pr2}$

它应该生成一个cProfile输出文件,然后您可以使用runsnakerun等工具对其进行分析。在

相关问题 更多 >

    热门问题