Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What tools should I use to profile Python code on window 7

I want to profile python code on Widnows 7. I would like to use something a little more user friendly than the raw dump of cProfile. In that search I found the GUI RunSnakeRun, but I cannot find a way to download RunSnakeRun on Windows. Is it possible to use RunSnakeRun on windows or what other tools could I use?

Edit: I have installed RunSnakeRun now. That's progress, thanks guys. How do you run it without a linux command line?

Edit 2: I am using this tutorial http://sullivanmatas.wordpress.com/2013/02/03/profiling-python-scripts-with-runsnakerun/ but I hang up at the last line with "python: can't open file 'runsnake.py': [Errno 2] No such file or directory "

like image 811
lemiant Avatar asked Jul 22 '13 17:07

lemiant


People also ask

How do I use Python profiling?

Python includes a built-in module called cProfile which is used to measure the execution time of a program. The cProfiler module provides all information about how long the program is executing and how many times the function gets called in a program.

What is profile file in Python?

Introduction to the profilers cProfile and profile provide deterministic profiling of Python programs. A profile is a set of statistics that describes how often and for how long various parts of the program executed. These statistics can be formatted into reports via the pstats module.

What program runs Python?

One of the best (and only) full-featured, dedicated IDEs for Python is PyCharm. Available in both paid (Professional) and free open-source (Community) editions, PyCharm installs quickly and easily on Windows, Mac OS X, and Linux platforms. Out of the box, PyCharm supports Python development directly.


3 Answers

The standard solution is to use cProfile (which is in the standard library) and then open the profiles in RunSnakeRun: http://www.vrplumber.com/programming/runsnakerun/

cProfile, however only profiles at the per-functions level. If you want line by line profiling try line profiler: https://github.com/rkern/line_profiler

like image 92
lemiant Avatar answered Oct 21 '22 06:10

lemiant


I installed runsnake following these installation instructions.

The step python runsnake.py profile.pfl failed because the installation step (easy_install SquareMap RunSnakeRun) did not create a file runsnake.py.

For me (on Ubuntu), the installation step created an executable at /usr/local/bin/runsnake. I figured this out by reading the console output from the installation step. It may be in a different place on Windows, but it should be printed in the output of easy_install. To read a profile file, I can execute /usr/local/bin/runsnake profile.pfl.

like image 45
dinosaur Avatar answered Oct 21 '22 05:10

dinosaur


There's also py-spy, written in Rust, safe to use even in production, without modifying any code.

Works on Windows, to install run pip install py-spy.

From there you can run py-spy record -o profile.svg -- python myprogram.py which produces nice flame graphs.

like image 38
mjarosie Avatar answered Oct 21 '22 06:10

mjarosie