Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cProfile with nosetest --with-profile?

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

The output can't read by runsnake, because nosetest uses hotshot, if I want to generate a file that can be read with runsnake, I need to convert it so:

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

st.dump_stats('output_new')

Could I run the test with cProfile directly for read with runsnake?

like image 791
Virako Avatar asked Sep 02 '12 13:09

Virako


2 Answers

Evolving on the answer of @squid, you can use a nose plugin called nose-cprof to replace the nose default profiler, hotshot, with cProfile.

To install it:

pip install nose-cprof

Then call nose like this:

nosetests --with-cprofile

It should generate a cProfile output file, that you can then analyze with tools like runsnakerun.

like image 181
Douglas De Rizzo Meneghetti Avatar answered Sep 30 '22 19:09

Douglas De Rizzo Meneghetti


@cihanpesend's answer didn't quite work for me (cProfile couldn't find 'nosetests'), but I did have success on Linux using:

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

The resulting output works fine in runsnake.

(Presumably on Windows you could replace which nosetests with the hard-coded path to your nosetests top-level python script.)

I think you are right that the output from nosetests' hotshot profiler is not compatible with runsnake. Certainly the two don't play nice together out of the box for me either.

like image 34
Jonathan Hartley Avatar answered Sep 30 '22 19:09

Jonathan Hartley