472,131 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,131 software developers and data experts.

Using graphviz to visualize trace.py output, anybody?

Hi,

has anybody thought of / already used graphviz to convert the output of
trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does
not successfully create a dot file, and 2. I don't really want a UML
representation but a compact representation of program execution.

Maybe there is some other tool that I am not aware of which can create
this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9

Regards,
Svenn

Oct 30 '05 #1
9 2871
Hi!

Under Windows, I call graphwiz from Python via COM, with win32all (PyWin).
Sorry, I don't know the Mac.

@-salutations

Michel Claveau

Oct 30 '05 #2
I was more thinking of converting the output of trace.py to the dot
language in order to get a graphical view of the execution of my
program.

Oct 31 '05 #3
In article <11*********************@g43g2000cwa.googlegroups. com>, sv*******@bjerkem.de wrote:
Hi,

has anybody thought of / already used graphviz to convert the output of
trace.py into a graph? I looked at PyUMLGraph, but 1. PyUMLGraph does
not successfully create a dot file, and 2. I don't really want a UML
representation but a compact representation of program execution.

Maybe there is some other tool that I am not aware of which can create
this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9

Regards,
Svenn


Take a look at:
http://dkbza.org/pydot.html

It's a python interface which can produce dot format files (based on its internal
graph API) and run graphviz for you.

I'm not sure which trace.py you're referring to, but I assume it dumps some output file.
You have a couple of obvious ways to get what you want:

1) modify trace.py to create a pydot graph structure then write to file
2) make a script that parses the trace.py output to create a pydot graph structure then write to file

Dave
Oct 31 '05 #4
I am referring to the trace.py which comes with python2.3 which is
installed on Panther by default. (I found it with 'locate trace.py'
after reading about its existence here)

I was thinking in the direction of your suggestion 2) but before I
reinvent the wheel, I would like to know if someone has already
invented it. As it doesn't seem like anybody has, I will have to go do
it myself. If somebody happen to finish before me I would be happy to
get a notice.

--
Svenn

Oct 31 '05 #5
sv*******@bjerkem.de wrote:
Hi,

has anybody thought of / already used graphviz to convert the output of
trace.py into a graph?


Thanks for the pointer to trace.py. I hadn't seen that before.

Are you thinking about a call-graph or sequence diagram, based on
the output from trace.py --trace? I suspect it might be easiest to
do that by modifying trace.py, so that it gives clearer hints about
when it performs a call, and when it returns from a call. (Could
it do that? Does trace.py have a clue about that?)

E.g. from running trace.py --trace trace.py in Python 2.3 I get:

....
--- modulename: trace, funcname: ?
....
trace.py(104): PRAGMA_NOCOVER = "#pragma NO COVER"
trace.py(107): rx_blank = re.compile(r'^\s*(#.*)?$')
--- modulename: sre, funcname: compile
sre.py(179): return _compile(pattern, flags)
--- modulename: sre, funcname: _compile
sre.py(218): cachekey = (type(key[0]),) + key
sre.py(219): p = _cache.get(cachekey)
sre.py(220): if p is not None:
sre.py(221): return p
trace.py(109): class Ignore:
--- modulename: trace, funcname: Ignore
trace.py(109): class Ignore:
....

That should cause something like:

trace.GLOBAL
|->sre.compile
| |->sre._compile
|->trace.Ignore

Finding the relevant nodes in the graph seems trivial. It's
the ' --- modulename:...' rows. Figuring out the origin of
the edges to these nodes seems error-prone. How do you know
that the above isn't really...

trace.GLOBAL
|->sre.compile
|->sre._compile
|->trace.Ignore

....for instance? Looking at the output, we can see that it's
not, and we know that sre won't call trace in _compile, but I'm
not sure how to write a parser that would detect all such cases.
I imagine that loops, callbacks etc might turn out to be tricky.

Both calls and returns can look very different in Python, the
program flow can move back and forth a lot, both modules and
callables might have a different name than the one that appears
in the source code where it's called (e.g. re => sre above) etc.

I wrote somthing like this to analyze COBOL source code about a
year ago, and that was trivial, but Python is so dynamic and
varied compared to COBOL where I only had to look for "CALL
something" if my memory serves me right.

Perhaps you should make a simple parser that does the very easy
part, essentially something like:

? -> sre.compile;
? -> sre._compile;
? -> trace.Ignore;

Then you can massage the resulting dot-files manually until they
give you the output you want. You should really do this with non-
trivial code of the kind you would like to analyze, and make sure
that you are able to create meaningful graphs.

For instance, you probably want to show something other than just
the output of...

trace.__main__ -> sre.compile;
sre.compile -> sre._compile;
trace.__main__ -> trace.Ignore;

....since this wouldn't give you any meaningful image of the sequence.
Or perhaps you just want collaboration diagrams?

Actually, even if you end up doing manual work with every dot-file,
it might turn out to be less work that other ways of doing graphs,
at least if you can get typical edges right in your program and just
fix occational ambiguities. I'm not so sure that it's so easy to
get any pretty graphs at all from this approach though. I guess it
requires some experimentation.

Nov 1 '05 #6
> Maybe there is some other tool that I am not aware of which can create
this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9


kcachegrind

http://kcachegrind.sourceforge.net/cgi-bin/show.cgi

--
Toby Dickenson
Nov 1 '05 #7
I was originally thinking of piping the output of trace.py into a text
file and then have python massage that text file into a dot file for
graphviz to visualize.

Some formatting is possible with graphviz, but I would expect the graph
to be very dependent on how the program under test runs so I have
little idea what to expect.

I think a counter would be needed to show the progress of the execution
of the program as some parts of code are visited at intervalls.

--
Svenn

Nov 1 '05 #8
This looks like something, but I have to introspect myself to accept
fink on my mac. Thanks for the pointer.
--
Svenn

Nov 1 '05 #9

sv*******@bjerkem.de wrote:
I was originally thinking of piping the output of trace.py into a text
file and then have python massage that text file into a dot file for
graphviz to visualize.

Some formatting is possible with graphviz, but I would expect the graph
to be very dependent on how the program under test runs so I have
little idea what to expect.


To mangle graphs and their drawing via graphviz on multilple platforms,
you might also want to try networkx combined with pygraphviz
(available from networkx.lanl.gov)

Cheers, Pieter

Nov 5 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Richard | last post: by
3 posts views Thread by Bruno Paquette | last post: by
2 posts views Thread by deepukutty | last post: by
4 posts views Thread by Christoph Wienands | last post: by
4 posts views Thread by kyosohma | last post: by
reply views Thread by =?Utf-8?B?YWtz?= | last post: by
2 posts views Thread by Peter Olcott | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.