• Stars
    star
    156
  • Rank 231,891 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Profile python programs and view them with kcachegrind

Overview

Script to help visualize profiling data collected with the cProfile Python module with the kcachegrind (screenshots) graphical calltree analyser.

This is a rebranding of the venerable http://www.gnome.org/~johan/lsprofcalltree.py script by David Allouche et Al. It aims at making it easier to distribute (e.g. through PyPI) and behave more like the scripts of the debian kcachegrind-converters package. The final goal is to make it part of the official upstream kdesdk package.

Installation

On Debian ≥ 11, or derivatives such as Ubuntu ≥ 20.04, sudo apt install kcachegrind pyprof2calltree.

Command line usage

Upon installation you should have a pyprof2calltree script in your path:

$ pyprof2calltree --help
usage: pyprof2calltree [-h] [-o output_file_path] [-i input_file_path] [-k]
                       [-r scriptfile [args ...]]

optional arguments:
  -h, --help            show this help message and exit
  -o output_file_path, --outfile output_file_path
                        Save calltree stats to <outfile>
  -i input_file_path, --infile input_file_path
                        Read Python stats from <infile>
  -k, --kcachegrind     Run the kcachegrind tool on the converted data
  -r scriptfile [args ...], --run-script scriptfile [args ...]
                        Name of the Python script to run to collect profiling
                        data
  -s {s,ms,us,ns}, --scale {s,ms,us,ns}
                        Time scale

Python shell usage

pyprof2calltree is also best used from an interactive Python shell such as the default shell. For instance let us profile XML parsing:

>>> from xml.etree import ElementTree
>>> from cProfile import Profile
>>> xml_content = '<a>\n' + '\t<b/><c><d>text</d></c>\n' * 100 + '</a>'
>>> profiler = Profile()
>>> profiler.runctx(
...     "ElementTree.fromstring(xml_content)",
...     locals(), globals())

>>> from pyprof2calltree import convert, visualize
>>> visualize(profiler.getstats())                            # run kcachegrind
>>> convert(profiler.getstats(), 'profiling_results.kgrind')  # save for later

or with the ipython:

In [1]: %doctest_mode
Exception reporting mode: Plain
Doctest mode is: ON

>>> from xml.etree import ElementTree
>>> xml_content = '<a>\n' + '\t<b/><c><d>text</d></c>\n' * 100 + '</a>'
>>> %prun -D out.stats ElementTree.fromstring(xml_content)

*** Profile stats marshalled to file 'out.stats'

>>> from pyprof2calltree import convert, visualize
>>> visualize('out.stats')
>>> convert('out.stats', 'out.kgrind')

>>> results = %prun -r ElementTree.fromstring(xml_content)
>>> visualize(results)

Change log

  • 1.4.4 - 2018-10-19: Numerous small improvements, drop support for EOL python versions
  • 1.4.3 - 2017-07-28: Windows support (fixed is_installed check - #21)
  • 1.4.2 - 2017-07-19: No feature or bug fixes, just license clarification (#20)
  • 1.4.1 - 2017-05-20: No feature or bug fixes, just test distribution (#17)
  • 1.4.0 - 2016-09-03: Support multiple functions with the same name, tick unit from millis to nanos, tests added (#15)
  • 1.3.2 - 2014-07-05: Bugfix: correct source file paths (#12)
  • 1.3.1 - 2013-11-27: Bugfix for broken output writing on Python 3 (#8)
  • 1.3.0 - 2013-11-19: qcachegrind support
  • 1.2.0 - 2013-11-09: Python 3 support
  • 1.1.1 - 2013-09-25: Miscellaneous bugfixes
  • 1.1.0 - 2008-12-21: integrate fix in conversion by David Glick
  • 1.0.3 - 2008-10-16: fix typos in 1.0 release
  • 1.0 - 2008-10-16: initial release under the pyprof2calltree name

More Repositories

1

pyfiglet

An implementation of figlet written in Python
Python
1,283
star
2

goupx

Fix golang compiled binaries on x86_64 so that they can be packed with UPX
Go
334
star
3

docker-show-context

Show where time is wasted during the context upload of `docker build`
Go
323
star
4

go2ll-talk

Live coding a basic Go compiler with LLVM in 20 minutes
Go
265
star
5

goimports-update-ignore

Generate .goimportsignore and make goimports fast
Go
64
star
6

go-ffmpeg-video-encoding

Basic bindings for ffmpeg video encoding
Go
22
star
7

perf

Linux Perf subsystem bindings for Go
Go
21
star
8

go2ll

Extremely experimental toy go compiler
Go
19
star
9

waitsilence

an executable which blocks until it receives nothing on stdin for a specified time
Go
18
star
10

sharedextents

Show proportion of physical extents shared between two files
Go
12
star
11

zerocopy

go zerocopy.Reader interface and implementation
Go
11
star
12

go-clz4

fast cgo implementation of lz4
C
10
star
13

fienode

Discover identical CoW copies, analogous to an inode
Go
10
star
14

cartographer

Quickly find non-determinism bugs caused by loops over maps
Go
9
star
15

sha1-visualizer

Visualize SHA1 bit differences
JavaScript
7
star
16

usv

Go
7
star
17

iptables-block-dns

Block distractions by dropping DNS packets
Shell
5
star
18

git-minecraft-smudge

(defunct) Abusing git's filter mechanism for fun and profit.
Go
4
star
19

httpcache

{non,}Transparent MITM http{,s} proxy
Go
4
star
20

pp2g

Crude python to go translator
Python
3
star
21

binview

A fun pointless visualization of arbitrary binary files
Python
3
star
22

__autoversion__

Python
3
star
23

git-alot

Track the status of many git repositories
Python
3
star
24

go-hexcolor

golang Hex string color model
Go
2
star
25

jump

Jump to AWS machines
Go
2
star
26

gooda

C
2
star
27

minty

Python
2
star
28

wscat

cat. For websockets.
Go
2
star
29

bumphunter.pw

Simple implementation of the BumpHunter algorithm
Python
1
star
30

static-fusermount

Makefile
1
star
31

pwa

Python
1
star
32

barrier

Signalling primitive for golang
Go
1
star
33

inf

Infinity
Python
1
star
34

go-memhelper

Helper functions for avoiding OOM with many goroutines doing memory-heavy things
Go
1
star
35

ptrace-read

Go
1
star
36

httpservecache

Golang HTTP server caching middleware using groupcache
Go
1
star
37

fastwalk

Go
1
star
38

runlocal

communicate commands to be run from remote to local over x-forwarding
Go
1
star
39

https-redirect

Redirect traffic from port 80 to 443
Go
1
star
40

keyboard

Keyboard offers a universal keyboard shortcut binding interface for various backends.
Go
1
star
41

go-ping

Go
1
star