Skip to content
vmprof - a statistical program profiler
C Python Makefile Shell M4 C++
Branch: master
Clone or download

Latest commit

mattip Merge pull request #209 from timpalpant/debug-fprintf
Guard fprintf behind DEBUG since they are not guaranteed to be signal safe
Latest commit f0dc85b Mar 5, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs fix documentation and default for period Mar 4, 2020
jitlog fix for pep479, python3.7+ Mar 4, 2020
src Merge pull request #209 from timpalpant/debug-fprintf Mar 4, 2020
travis xcode 6.4 is deprecated Mar 4, 2020
vmprof fix documentation and default for period Mar 4, 2020
vmshare finally fix this spurious warnings which has been there forever Oct 30, 2017
.gitignore Remove configure outputs. Apr 15, 2017
.travis.yml
BUGS mention threads in docs Feb 19, 2016
LICENSE add some licensing info Jan 12, 2016
MANIFEST.in include <link.h> also on linux Apr 4, 2017
README-develop.md mention threads in docs Feb 19, 2016
README.md extend readme (dev section), arm is now able to compile vmprof (teste… Mar 6, 2018
appveyor.yml also fix appveyor Mar 4, 2020
dev_requirements.txt add colorama dependency, fix up the pretty printer to ouput the trace… Jan 10, 2017
example.py fix example Apr 22, 2015
pytest.ini pytest.ini file added Dec 6, 2016
setup.cfg Add new line at the end of file Feb 19, 2016
setup.py bah, apparently on travis you get a machine() value of i686 May 30, 2019
test_requirements.txt fix compiler warning, run and update travis on bionic Mar 4, 2020
tox.ini Fix tox.ini Jul 27, 2016
vmprofdemo.py Fix Python 3 syntax in vmprofdemo.py Apr 11, 2016

README.md

VMProf Python package

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

Head over to https://vmprof.readthedocs.org for more info!

Installation

pip install vmprof
python -m vmprof <your program> <your program args>

Our build system ships wheels to PyPI (Linux, Mac OS X). If you build from source you need to install CPython development headers and libunwind headers (on Linux only). On Windows this means you need Microsoft Visual C++ Compiler for your Python version.

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

You need to install python development packages. In case of e.g. Debian or Ubuntu the package you need is python3-dev and libunwind-dev. 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. It can read profile files and produce a formatted output.

Here is an example of how to use vmprofshow:

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

pypy vmprof/test/cpuburn.py # you can find cpuburn.py in the vmprof-python repo

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
You can’t perform that action at this time.