gak / pycallgraph Goto Github PK
View Code? Open in Web Editor NEWpycallgraph is a Python module that creates call graphs for Python programs.
License: GNU General Public License v2.0
pycallgraph is a Python module that creates call graphs for Python programs.
License: GNU General Public License v2.0
The callgraphs I generated looked wrong.
It turns out that the tracer function needs to return a tracer to be used in each local scope!
(See http://www.python.org/doc/2.3.4/lib/debugger-hooks.html#debugger-hooks)
I added a line to tracer, to return itself. That seemed to work:
{{{
def tracer(frame, event, arg):
................
if event == 'return':
if pr: print 'return'
if call_stack:
call_stack.pop(-1)
return tracer #new
}}}
It would be good to be able to see the order in which functions were called. This could get out of hand quite quickly, so maybe track only the first calls.
If you replace all sys.settrace(tracer) calls with sys.setprofile(tracer) and ignore the first return event in the tracer. Running a script will be dramatically faster.
(setprofile only logs call and return events, where settrace will also call the tracer function for each line that is interpreted)
You might also want to react on c_call and c_return events (logging extension modules)
It would be useful to be able to use pycallgraph from the command line:
{{{
$ pycallgraph --include='genshi*' --output=test.png test.py
}}}
execfile()
is the love you want:
{{{
import sys
import pycallgraph
pycallgraph.start_trace(filter=pycallgraph.GlobbingFilter(include=['genshi*']))
execfile(sys.argv[1])
pycallgraph.make_dot_graph('test.png')
}}}
It seems calls to start_trace(reset=False) loses edges from main for all but the first start_trace, i.e. the first one after a reset_trace(). It seems maybe there is something that needs "resetting" even when not resetting?
Simple example:
pycallgraph.start_trace(reset=False)
#pycallgraph.stop_trace()
pycallgraph.start_trace(reset=False)
...test code here...
pycallgraph.stop_trace()
That works normally, now uncomment the stop_trace() command, and rerun... main disappears.
On front page (http://pycallgraph.slowchop.com/) in section Usage you have
pycallgraph.make_call_graph('test.png')
and
pycallgraph.make_call_graph('test.jpg', format='jpg', tool='neato')
But this functions do not exist in pycallgraph-0.3.0. It take me several minutes before I realized that the function is named make_dot_graph.
Miroslav Suchy
The callgraphs I generated looked wrong.
It turns out that the tracer function needs to return a tracer to be used in each local scope!
(See http://www.python.org/doc/2.3.4/lib/debugger-hooks.html#debugger-hooks)
I added a line to tracer, to return itself. That seemed to work:
{{{
def tracer(frame, event, arg):
................
if event == 'return':
if pr: print 'return'
if call_stack:
call_stack.pop(-1)
return tracer #new
}}}
Especially with code that takes a long time to execute (especially after the settrace call...) I would like to collect all calls for later offline investigation. I would suggest a save_graph and a load_graph? I can then save_graph (instead of save_dot, e.g.), then at a later time, load_graph, followed by save_dot (or make_dot_graph). That is the first step, the second is to allow filtering of this already-collected graph, so I can run the trace once, then generate graphs for various modules independently.
This might get clunky if one just adds bits and pieces, a slight redesign might be sensible?
Is there any performance reasons to have filters where they currently are? If we add "offline filters", there'd be two different places to filter. I might propose removing the online filters? (Or keeping them for legacy/support, though, how many users does pycallgraph currently have?)
It would be good to be able to see the order in which functions were called. This could get out of hand quite quickly, so maybe track only the first calls.
It would be great to be able to get the edges of the callgraph so that they can be processed with other tools. I've added the following function:
{{{
def get_calltree(stop=True):
"""Compiles the edges for the graph."""
edges = list()
if stop:
stop_trace()
for fr_key, fr_val in call_dict.items():
if fr_key == '':
continue
for to_key, to_val in fr_val.items():
edges.append((fr_key, to_key))
return edges
}}}
It would be great to have this functionality on pycallgraph, maybe expanded so that the node names include the call count and other statistics.
When calling methods on objects that were defined in a superclass, the child class is used for the node's class_name rather than the class where the method was defined.
Example:
{{{
class A(object):
def init(self):
pass
class B(A):
def init(self):
A(self)
}}}
Will result in two nodes, both with class B rather than one of each. I've attached a patch to fix this
Especially with code that takes a long time to execute (especially after the settrace call...) I would like to collect all calls for later offline investigation. I would suggest a save_graph and a load_graph? I can then save_graph (instead of save_dot, e.g.), then at a later time, load_graph, followed by save_dot (or make_dot_graph). That is the first step, the second is to allow filtering of this already-collected graph, so I can run the trace once, then generate graphs for various modules independently.
This might get clunky if one just adds bits and pieces, a slight redesign might be sensible?
Is there any performance reasons to have filters where they currently are? If we add "offline filters", there'd be two different places to filter. I might propose removing the online filters? (Or keeping them for legacy/support, though, how many users does pycallgraph currently have?)
I was amazed at how simple it was to install and use pycallgraph. Just one suggestion.
It would be very helpful if you could specify sys.argv to the called script on the command line. That way I wouldn't have to make a new script file for every set of options. If you put the output filename before the scriptfile you could feed the rest of the command line to the called script. For example:
{{{
pycallgraph-dot.py test1.png myscript.py --spam=42 ham.txt eggs.txt
}}}
e.g.
{{{
make_dot_graph(ignore_stdlib=True, 'test.png')
}}}
or
{{{
pycallgraph-dot.py --ignore-stdlib test.py test.png
}}}
i have tried to run the basic example but i get the following error:
'The command "dot -Tpng -obasic.png /tmp/tmp_Imspl" failed with error code 32512.'
i work on osx 10.4.10
Especially with code that takes a long time to execute (especially after the settrace call...) I would like to collect all calls for later offline investigation. I would suggest a save_graph and a load_graph? I can then save_graph (instead of save_dot, e.g.), then at a later time, load_graph, followed by save_dot (or make_dot_graph). That is the first step, the second is to allow filtering of this already-collected graph, so I can run the trace once, then generate graphs for various modules independently.
This might get clunky if one just adds bits and pieces, a slight redesign might be sensible?
Is there any performance reasons to have filters where they currently are? If we add "offline filters", there'd be two different places to filter. I might propose removing the online filters? (Or keeping them for legacy/support, though, how many users does pycallgraph currently have?)
Hi! I'm attaching a patch to expand user and variables in the filename argument of make_dot_graph. Hope it helps.
Cheers.
e.g.
{{{
make_dot_graph(ignore_stdlib=True, 'test.png')
}}}
or
{{{
pycallgraph-dot.py --ignore-stdlib test.py test.png
}}}
On front page (http://pycallgraph.slowchop.com/) in section Usage you have
pycallgraph.make_call_graph('test.png')
and
pycallgraph.make_call_graph('test.jpg', format='jpg', tool='neato')
But this functions do not exist in pycallgraph-0.3.0. It take me several minutes before I realized that the function is named make_dot_graph.
Miroslav Suchy
{{{
05:02:26 that timing shit is cool :)
05:02:33 however, i have one slight problem
05:03:06 the top-level function gets all the accumulated time of its children, which is fair enough
05:03:24 but it'd be nice to be able to exclude them from the colouring...somehow
05:03:38 have u tried the exclude filtering?
05:03:43 yeah
05:03:53 but that breaks the graph up so much it ends up at around 30K horizontal pixels
05:03:56 too many subgraphs
05:03:58 hmm
05:04:07 tricky :
05:04:16 --exclude-colouring
05:04:35 yeah that would wfm
05:04:54 or.. --excluding-timing
05:04:57 yeah!
05:05:01 that would be better i think
05:05:09 ill ticket it
05:05:12 oarsome
}}}
i have tried to run the basic example but i get the following error:
'The command "dot -Tpng -obasic.png /tmp/tmp_Imspl" failed with error code 32512.'
i work on osx 10.4.10
Hi
Attached is a pycallgraph-dot manpage I create for the Debian package. Let me you know any comments you might have.
Cheers!
It would be good to be able to see the order in which functions were called. This could get out of hand quite quickly, so maybe track only the first calls.
It would be great to be able to get the edges of the callgraph so that they can be processed with other tools. I've added the following function:
{{{
def get_calltree(stop=True):
"""Compiles the edges for the graph."""
edges = list()
if stop:
stop_trace()
for fr_key, fr_val in call_dict.items():
if fr_key == '':
continue
for to_key, to_val in fr_val.items():
edges.append((fr_key, to_key))
return edges
}}}
It would be great to have this functionality on pycallgraph, maybe expanded so that the node names include the call count and other statistics.
It would be useful to be able to use pycallgraph from the command line:
{{{
$ pycallgraph --include='genshi*' --output=test.png test.py
}}}
execfile()
is the love you want:
{{{
import sys
import pycallgraph
pycallgraph.start_trace(filter=pycallgraph.GlobbingFilter(include=['genshi*']))
execfile(sys.argv[1])
pycallgraph.make_dot_graph('test.png')
}}}
It seems calls to start_trace(reset=False) loses edges from main for all but the first start_trace, i.e. the first one after a reset_trace(). It seems maybe there is something that needs "resetting" even when not resetting?
Simple example:
pycallgraph.start_trace(reset=False)
#pycallgraph.stop_trace()
pycallgraph.start_trace(reset=False)
...test code here...
pycallgraph.stop_trace()
That works normally, now uncomment the stop_trace() command, and rerun... main disappears.
It would be good to be able to see the order in which functions were called. This could get out of hand quite quickly, so maybe track only the first calls.
Hi folks,
I think you may ease the graphviz code generation using gvgen : http://software.inl.fr/trac/wiki/GvGen
this way you could add legend support etc..
When calling methods on objects that were defined in a superclass, the child class is used for the node's class_name rather than the class where the method was defined.
Example:
{{{
class A(object):
def init(self):
pass
class B(A):
def init(self):
A(self)
}}}
Will result in two nodes, both with class B rather than one of each. I've attached a patch to fix this
Hi! I'm attaching a patch to expand user and variables in the filename argument of make_dot_graph. Hope it helps.
Cheers.
It seems calls to start_trace(reset=False) loses edges from main for all but the first start_trace, i.e. the first one after a reset_trace(). It seems maybe there is something that needs "resetting" even when not resetting?
Simple example:
pycallgraph.start_trace(reset=False)
#pycallgraph.stop_trace()
pycallgraph.start_trace(reset=False)
...test code here...
pycallgraph.stop_trace()
That works normally, now uncomment the stop_trace() command, and rerun... main disappears.
The callgraphs I generated looked wrong.
It turns out that the tracer function needs to return a tracer to be used in each local scope!
(See http://www.python.org/doc/2.3.4/lib/debugger-hooks.html#debugger-hooks)
I added a line to tracer, to return itself. That seemed to work:
{{{
def tracer(frame, event, arg):
................
if event == 'return':
if pr: print 'return'
if call_stack:
call_stack.pop(-1)
return tracer #new
}}}
{{{
05:02:26 that timing shit is cool :)
05:02:33 however, i have one slight problem
05:03:06 the top-level function gets all the accumulated time of its children, which is fair enough
05:03:24 but it'd be nice to be able to exclude them from the colouring...somehow
05:03:38 have u tried the exclude filtering?
05:03:43 yeah
05:03:53 but that breaks the graph up so much it ends up at around 30K horizontal pixels
05:03:56 too many subgraphs
05:03:58 hmm
05:04:07 tricky :
05:04:16 --exclude-colouring
05:04:35 yeah that would wfm
05:04:54 or.. --excluding-timing
05:04:57 yeah!
05:05:01 that would be better i think
05:05:09 ill ticket it
05:05:12 oarsome
}}}
Hi! I'm attaching a patch to expand user and variables in the filename argument of make_dot_graph. Hope it helps.
Cheers.
I was amazed at how simple it was to install and use pycallgraph. Just one suggestion.
It would be very helpful if you could specify sys.argv to the called script on the command line. That way I wouldn't have to make a new script file for every set of options. If you put the output filename before the scriptfile you could feed the rest of the command line to the called script. For example:
{{{
pycallgraph-dot.py test1.png myscript.py --spam=42 ham.txt eggs.txt
}}}
Using the module on windows with python 2.5 I get the following error:
Der Befehl "dot" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
{{{
Traceback (most recent call last):
File "simple-coordinate-converter_graph.py", line 132, in
pycallgraph.make_dot_graph('D:\development\python\scripts\coordinate-convert
er\test.png')
File "C:\python\lib\site-packages\pycallgraph.py", line 378, in make_dot_graph
'code %(ret)i.' % locals())
pycallgraph.PyCallGraphException: The command "dot -Tpng -oD:\myscript est.png c:\dokume1\USERNAME\lokale1\temp\tmpu4jgj
j" failed with error code 1.
}}}
Drücken Sie eine beliebige Taste . . .
On front page (http://pycallgraph.slowchop.com/) in section Usage you have
pycallgraph.make_call_graph('test.png')
and
pycallgraph.make_call_graph('test.jpg', format='jpg', tool='neato')
But this functions do not exist in pycallgraph-0.3.0. It take me several minutes before I realized that the function is named make_dot_graph.
Miroslav Suchy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.