Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Merge develop to master for a new pypi release 1.0.2 #172

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0ab95a8
Merge branch 'release/1.0.1' into develop
gak Sep 17, 2013
fbd8fae
Potential fix for 2to3 too long line
gak Sep 17, 2013
35d6465
Removed pypy from travis tests because it kept segfaulting
gak Sep 17, 2013
22dbcc5
add module to let you group objects arbitrarily
logicabrity Feb 19, 2014
6176256
add example of custom grouping
logicabrity Feb 19, 2014
2c4ca0e
fix oversight in docstring
logicabrity Feb 19, 2014
24085f1
make changes PEP-8 compliant
logicabrity Feb 19, 2014
4c74bb4
add a blank line to pycallgraph/grouper.py
logicabrity Feb 19, 2014
9a2a76b
add main to __all__ so that flake8 won't complain about unused import
logicabrity Feb 19, 2014
5c51c51
remove unused import (was copy and pasted from filter example)
logicabrity Feb 19, 2014
89e9689
Merge pull request #124 from sMAshdot/develop
gak Feb 19, 2014
f437d43
Ensure all files in docs are part of the sdist.
Oct 12, 2014
8181f6d
Merge pull request #131 from alunduil/add-docs-to-sdist
gak Oct 12, 2014
99bf650
Make .format() work with older Python versions
atodorov Nov 6, 2014
fad968c
more format fixes
atodorov Nov 6, 2014
ea6563e
Removed "json" output mode from the docs, because it looks like json …
RobBednark Nov 18, 2014
c92539b
Fix graphviz output format setting
vmarkovtsev Nov 24, 2014
199036c
Merge pull request #136 from vmarkovtsev/patch-1
gak Dec 14, 2014
98e3b9c
Merge pull request #134 from atodorov/fix_format
gak Dec 14, 2014
a8cdae3
Merge pull request #135 from RobBednark/rbednark-rm-json-from-docs
gak Dec 14, 2014
e201d73
Make Readme badges uniform and SVG using shields.io
DavidJFelix Dec 29, 2014
9a3d29a
Merge pull request #137 from DavidJFelix/patch-1
gak Jan 4, 2015
1d8f276
decorators from @ivannotes
luzfcb Mar 5, 2015
ac293eb
pep8 and add newline
luzfcb Mar 5, 2015
f751b95
pep8
luzfcb Mar 5, 2015
db347c1
renamed decorator from "pycall_profile" to "trace"
luzfcb May 28, 2015
ee33d76
test with python 3.5-dev nightly builds and pypy
luzfcb May 28, 2015
475fbd7
fix .travis.yml
luzfcb May 28, 2015
09ef7fa
fix .travis.yml
luzfcb May 28, 2015
0732a01
Merge pull request #140 from luzfcb/add-decorator
gak May 28, 2015
d23f9a4
[Bugfix] Allow spaces in tool path
rgom Jun 12, 2015
b0ca068
Merge pull request #144 from rgom/spaces_in_names_fix
gak Jun 12, 2015
f552d41
Update readme with a typo correction.
BorisVa Aug 20, 2015
dd354b3
Merge pull request #146 from BorisVa/patch-1
gak Aug 21, 2015
613ce31
Proper way of running system calls http://stackoverflow.com/a/3791476…
Aug 28, 2015
6c0f0e1
Merge pull request #147 from seperman/develop
gak Aug 28, 2015
015ec14
Update .travis.yaml
rbubley Mar 15, 2017
55ee009
Merge pull request #168 from rbubley/patch-1
gak Mar 15, 2017
f395ce9
Fix decorator implementation and import. Document use of decorators i…
abenassi Jul 13, 2017
924eab3
Merge branch 'develop'
abenassi Jul 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dist/

*.pyc
__pycache__
.idea

15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ language:
python:
- "2.7"
- "3.3"
- "3.4"
- "pypy"
# pytest does not support python 3.5
# https://bitbucket.org/pytest-dev/pytest/pull-request/296/astcall-signature-changed-on-35
# - "nightly"

matrix:
allow_failures:
- python:
- "pypy"
- python:
- "nigthly"

env:
global:
Expand All @@ -16,8 +27,8 @@ before_install:
- sudo apt-get install -qq graphviz

install:
- "pip install -r requirements/development.txt --use-mirrors"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then make 2to3; fi"
- "pip install -r requirements/development.txt"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]] || [[ $TRAVIS_PYTHON_VERSION == '3.4' ]] || [[ $TRAVIS_PYTHON_VERSION == 'nightly' ]]; then make 2to3; fi"

script:
- make tests
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ include LICENSE
include README.rst
include requirements
include test
include docs
recursive-include docs *
include examples/*.py
include man/pycallgraph.1
38 changes: 35 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ Python Call Graph

Welcome! Python Call Graph is a `Python <http://www.python.org>`_ module that creates `call graph <http://en.wikipedia.org/wiki/Call_graph>`_ visualizations for Python applications.

.. image:: https://travis-ci.org/gak/pycallgraph.svg
.. image:: https://img.shields.io/travis/gak/pycallgraph.svg
:target: https://travis-ci.org/gak/pycallgraph
.. image:: https://coveralls.io/repos/gak/pycallgraph/badge.svg?branch=develop
.. image:: https://img.shields.io/coveralls/gak/pycallgraph/develop.svg
:target: https://coveralls.io/r/gak/pycallgraph?branch=develop
.. image:: https://img.shields.io/pypi/v/pycallgraph.svg
:target: https://crate.io/packages/pycallgraph/
.. image:: https://img.shields.io/pypi/dm/pycallgraph.svg
:target: https://crate.io/packages/pycallgraph

Screenshots
===========
Expand All @@ -23,7 +27,7 @@ Click on the images below to see a larger version and the source code that gener
Project Status
==============

The latest version is **1.0.1** which was released on 2013-09-17, and is a backwards incompatbile from the previous release.
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 <https://github.com/gak/pycallgraph/#python-call-graph>`_, where you can `report issues <https://github.com/gak/pycallgraph/issues>`_, contribute to the project by `forking the project <https://help.github.com/articles/fork-a-repo>`_ then creating a `pull request <https://help.github.com/articles/using-pull-requests>`_, or just `browse the source code <https://github.com/gak/pycallgraph/>`_.

Expand Down Expand Up @@ -62,6 +66,34 @@ A simple use of the API is::
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
=============

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/command_line_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Description

pycallgraph is a program that creates call graph visualization from Python scripts.

*OUTPUT_MODE* can be one of graphviz, gephi and json. *python_file.py* is a python script that will be traced and afterwards, a call graph visualization will be generated.
*OUTPUT_MODE* can be one of graphviz or gephi. *python_file.py* is a python script that will be traced and afterwards, a call graph visualization will be generated.

General Arguments
-----------------

.. cmdoption:: <OUTPUT_MODE>

A choice of graphviz, gephi and json.
A choice of graphviz or gephi.

.. cmdoption:: -h, --help

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Intro

Python Call Graph was made to be a visual profiling tool for Python applications. It uses a debugging Python function called `sys.set_trace() <http://docs.python.org/dev/library/sys#sys.settrace>`_ which makes a callback every time your code enters or leaves function. This allows Python Call Graph to track the name of every function called, as well as which function called which, the time taken within each function, number of calls, etc.

It is able to generate different types of :ref:`outputs and visualizations <outputs>`. Initially Python Call Graph was only used to generate DOT files for `GraphViz <http://graphviz.org/>`_, and as of version 1.0.0, it can also generate JSON files, and GDF files for Gephi. Creating :ref:`custom outputs <custom_outputs>` is fairly easy by subclassing the :ref:`Output <output>` class.
It is able to generate different types of :ref:`outputs and visualizations <outputs>`. Initially Python Call Graph was only used to generate DOT files for `GraphViz <http://graphviz.org/>`_, and as of version 1.0.0, it can also generate GDF files for Gephi. Creating :ref:`custom outputs <custom_outputs>` is fairly easy by subclassing the :ref:`Output <output>` class.

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

Expand Down
3 changes: 3 additions & 0 deletions examples/graphviz/example_with_submodules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .example_with_submodules import main

__all__ = [main]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from submodule_one import SubmoduleOne
from submodule_two import SubmoduleTwo


def main():
s1 = SubmoduleOne()
s1.report()

s2 = SubmoduleTwo()
s2.report()

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions examples/graphviz/example_with_submodules/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def helper(something):
return something
6 changes: 6 additions & 0 deletions examples/graphviz/example_with_submodules/submodule_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SubmoduleOne(object):
def __init__(self):
self.one = 1

def report(self):
return self.one
9 changes: 9 additions & 0 deletions examples/graphviz/example_with_submodules/submodule_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from helpers import helper


class SubmoduleTwo(object):
def __init__(self):
self.two = 2

def report(self):
return helper(self.two)
71 changes: 71 additions & 0 deletions examples/graphviz/grouper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python
'''
This example demonstrates the use of grouping.
'''
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph import Grouper
from pycallgraph.output import GraphvizOutput
import example_with_submodules


def run(name, trace_grouper=None, config=None, comment=None):
if not config:
config = Config()

config.trace_filter = GlobbingFilter()

if trace_grouper is not None:
config.trace_grouper = trace_grouper

graphviz = GraphvizOutput()
graphviz.output_file = 'grouper-{}.png'.format(name)
if comment:
graphviz.graph_attributes['graph']['label'] = comment

with PyCallGraph(config=config, output=graphviz):
example_with_submodules.main()


def group_none():
run(
'without',
comment='Default grouping.'
)


def group_some():
trace_grouper = Grouper(groups=[
'example_with_submodules.submodule_one.*',
'example_with_submodules.submodule_two.*',
'example_with_submodules.helpers.*',
])

run(
'with',
trace_grouper=trace_grouper,
comment='Should assign groups to the two submodules.',
)


def group_methods():
trace_grouper = Grouper(groups=[
'example_with_submodules.*.report',
])

run(
'methods',
trace_grouper=trace_grouper,
comment='Should assign a group to the report methods.',
)


def main():
group_none()
group_some()
group_methods()


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions man/pycallgraph.1
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ pycallgraph [\fIOPTION\fP]... \fIOUTPUT_MODE\fP [\fIOUTPUT_OPTIONS\fP] \fIpython
.sp
pycallgraph is a program that creates call graph visualization from Python scripts.
.sp
\fIOUTPUT_MODE\fP can be one of graphviz, gephi and json. \fIpython_file.py\fP is a python script that will be traced and afterwards, a call graph visualization will be generated.
\fIOUTPUT_MODE\fP can be one of graphviz or gephi. \fIpython_file.py\fP is a python script that will be traced and afterwards, a call graph visualization will be generated.
.SH GENERAL ARGUMENTS
.INDENT 0.0
.TP
.B <OUTPUT_MODE>
A choice of graphviz, gephi and json.
A choice of graphviz or gephi.
.UNINDENT
.INDENT 0.0
.TP
Expand Down
5 changes: 5 additions & 0 deletions pycallgraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

from .pycallgraph import PyCallGraph
from .exceptions import PyCallGraphException
try:
from . import decorators
except Exception:
import decorators
from .config import Config
from .globbing_filter import GlobbingFilter
from .grouper import Grouper
from .util import Util
from .color import Color
from .color import ColorException
4 changes: 4 additions & 0 deletions pycallgraph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .output import outputters
from .globbing_filter import GlobbingFilter
from .grouper import Grouper


class Config(object):
Expand Down Expand Up @@ -31,6 +32,9 @@ def __init__(self, **kwargs):
include=['*'],
)

# Grouping
self.trace_grouper = Grouper()

self.did_init = True

# Update the defaults with anything from kwargs
Expand Down
20 changes: 20 additions & 0 deletions pycallgraph/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import functools

from .pycallgraph import PyCallGraph
from .output import GraphvizOutput


def trace(output=None, config=None):
def inner(func):
@functools.wraps(func)
def exec_func(*args, **kw_args):

graphviz = GraphvizOutput()
graphviz.output_file = output

with(PyCallGraph(output=graphviz, config=config)):
return func(*args, **kw_args)

return exec_func

return inner
26 changes: 26 additions & 0 deletions pycallgraph/grouper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from fnmatch import fnmatch


class Grouper(object):
'''Group module names.

By default, objects are grouped by their top-level module name. Additional
groups can be specified with the groups list and all objects will be
matched against it.
'''

def __init__(self, groups=None):
if groups is None:
groups = []

self.groups = groups

def __call__(self, full_name=None):
for pattern in self.groups:
if fnmatch(full_name, pattern):
if pattern[-2:] == ".*":
# a wilcard in the middle is probably meaningful, while at
# the end, it's only noise and can be removed
return pattern[:-2]
return pattern
return full_name.split('.', 1)[0]
Loading