Skip to content

criemen/vmprof-python

 
 

Repository files navigation

VMprof Python client

Build Status on TravisCI Build Status on TeamCity Read The Docs Build Status on AppVeyor

See https://vmprof.readthedocs.org for up to date info

Basic usage

###Linux

sudo apt-get install python-dev
pip install vmprof
python -m vmprof <your program> <your program args>

###Windows Install Microsoft Visual C++ Compiler for Python 2.7

pip install vmprof

Development

Setting up development can be done using the following commands:

$ virtualenv -p /usr/bin/python3 vmprof3
$ source vmprof3/bin/activate
$ python setup.py develop

Now it is time to write a test and implement your feature. If you want your changes to affect vmprof.com, head over to https://github.com/vmprof/vmprof-server and follow the setup instructions.

Consult our section for development at https://vmprof.readthedocs.org for more information.

vmprofshow

vmprofshow is a command line tool that comes with VMProf which can read profile files and produce a formatted output.

Here is an example of how to use vmprofshow:

Clone the vmprof repo first to use a minimalistic cpuburn.py:

git clone https://github.com/vmprof/vmprof-python
cd vmprof-python
pip install .

Run that smallish program which burns CPU cycles (with vmprof enabled):

pypy vmprof/test/cpuburn.py

This will produce a profile file vmprof_cpuburn.dat.

Now display the profile:

vmprofshow vmprof_cpuburn.dat

You will see a (colored) output:

oberstet@thinkpad-t430s:~/scm/vmprof-python$ vmprofshow vmprof_cpuburn.dat
100.0%  <module>  100.0%  tests/cpuburn.py:1
100.0% .. test  100.0%  tests/cpuburn.py:35
100.0% .... burn  100.0%  tests/cpuburn.py:26
 99.2% ...... _iterate  99.2%  tests/cpuburn.py:19
 97.7% ........ _iterate  98.5%  tests/cpuburn.py:19
 22.9% .......... _next_rand  23.5%  tests/cpuburn.py:14
 22.9% ............ JIT code  100.0%  0x7fa7dba57a10
 74.7% .......... JIT code  76.4%  0x7fa7dba57a10
  0.1% .......... JIT code  0.1%  0x7fa7dba583b0
  0.5% ........ _next_rand  0.5%  tests/cpuburn.py:14
  0.0% ........ JIT code  0.0%  0x7fa7dba583b0

Line profiling

vmprof supports line profiling mode, which enables collecting and showing the statistics for separate lines inside functions.

To enable collection of lines statistics add --lines argument to vmprof:

python -m vmprof --lines -o <output-file> <your program> <your program args>

Or pass lines=True argument to vmprof.enable function, when calling vmprof from code.

To see line statistics for all functions add the --lines argument to vmprofshow:

vmprofshow --lines <output-file>

To see line statistics for a specific function use the --filter argument with the function name:

vmprofshow --lines --filter <function-name> <output-file>

You will see the result:

macbook-pro-4:vmprof-python traff$ vmprofshow --lines --filter _next_rand vmprof_cpuburn.dat
Total hits: 1170 s
File: tests/cpuburn.py
Function: _next_rand at line 14

Line #     Hits   % Hits  Line Contents
=======================================
    14       38      3.2      def _next_rand(self):
    15                            # http://rosettacode.org/wiki/Linear_congruential_generator
    16      835     71.4          self._rand = (1103515245 * self._rand + 12345) & 0x7fffffff
    17      297     25.4          return self._rand

About

vmprof - a statistical program profiler

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 66.6%
  • Python 23.3%
  • Makefile 4.4%
  • Shell 2.7%
  • M4 2.0%
  • C++ 1.0%