Skip to content

campos-ddc/cprofile_graph

Repository files navigation

Travis Build Status PyPI version

About cprofile_graph

cprofile_graph is used to generate visual graphs for Python profiling.

Installation

  • First you need to install Graphviz, use sudo apt-get install graphviz graphviz-dev in Ubuntu or see this link for other platforms.
  • Use pip to install cprofile_graph.
pip install cprofile_graph

Usage

  • As a context manager:
from cprofile_graph import profile_ctx
with profile_ctx("myprofile.png"):
    foo()
  • As a function wrapper:
@profile_decorator
def foo():
    1 + 1

@profile_decorator("myprofile.png")
def foo():
    1 + 1
  • As a function:
from cprofile_graph import profile_code
profile_code("foo()", "myprofile.png")
  • As a script:
cprofile_graph myscript.py -o myprofile.png
cprofile_graph -c "foo()" -o myprofile.png

Example

This is the kind of output you will get from cprofile_graph, hot colors indicate most used functions:

Sample

Requirements

  • gprof2dot: Convert cProfile stats into dot files.
  • Graphviz: Convert dot files into visual graphs.
  • pygraphviz: Call Graphviz from within Python.

About

Generate visual graphs for Python profiling

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages