Skip to content

pycallgraph is a Python module that creates call graphs for Python programs.

License

Notifications You must be signed in to change notification settings

abenassi/pycallgraph

This branch is 40 commits ahead of gak/pycallgraph:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

924eab3 · Jul 13, 2017
Jul 13, 2017
Feb 19, 2014
Nov 18, 2014
Jul 13, 2017
Aug 18, 2013
Sep 15, 2013
May 28, 2015
Sep 15, 2013
Mar 5, 2015
Mar 15, 2017
Jul 27, 2013
Oct 12, 2014
Sep 17, 2013
Jul 13, 2017
May 28, 2015
Aug 17, 2013

Repository files navigation

Python Call Graph

Welcome! Python Call Graph is a Python module that creates call graph visualizations for Python applications.

Screenshots

Click on the images below to see a larger version and the source code that generated them.

http://pycallgraph.slowchop.com/en/develop/_images/basic_thumb.png http://pycallgraph.slowchop.com/en/develop/_images/regexp_grouped_thumb.png http://pycallgraph.slowchop.com/en/develop/_images/regexp_ungrouped_thumb.png

Project Status

The latest version is 1.0.1 which was released on 2013-09-17, and is a backwards incompatible from the previous release.

The project lives on GitHub, where you can report issues, contribute to the project by forking the project then creating a pull request, or just browse the source code.

The documentation needs some work stiil. Feel free to contribute :)

Features

  • Support for Python 2.7+ and Python 3.3+.
  • Static visualizations of the call graph using various tools such as Graphviz and Gephi.
  • Execute pycallgraph from the command line or import it in your code.
  • Customisable colors. You can programatically set the colors based on number of calls, time taken, memory usage, etc.
  • Modules can be visually grouped together.
  • Easily extendable to create your own output formats.

Quick Start

Installation is easy as:

pip install pycallgraph

You can either use the command-line interface for a quick visualization of your Python script, or the pycallgraph module for more fine-grained settings.

The following examples specify graphviz as the outputter, so it's required to be installed. They will generate a file called pycallgraph.png.

The command-line method of running pycallgraph is:

$ pycallgraph graphviz -- ./mypythonscript.py

A simple use of the API is:

from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput

with PyCallGraph(output=GraphvizOutput()):
    code_to_profile()

Use decorators for an even more simple use of the API:

from pycallgraph.decorators import trace

@trace("path/to/output.png")
def main():
    code_to_profile()

main()

Or decorate a specific function inside your code you want to profile:

from pycallgraph.decorators import trace

@trace("path/to/output.png")
def function_1():
    do_stuff

def function_2():
    do_stuff

def code_to_profile():
    function_1()
    function_2()

code_to_profile()

Documentation

Feel free to browse the documentation of pycallgraph for the usage guide and API reference.

About

pycallgraph is a Python module that creates call graphs for Python programs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.8%
  • Makefile 1.2%