views:

689

answers:

5

I'm looking for a utility similar to gprof that will generate a call graph for PHP code. I'd prefer something that can produce graphical output, or at least text output that can be interpreted by GraphViz or similar, but I'll settle for plain text output.

Does anyone know of any tool that can do this?

+4  A: 
bjarkef
Thanks very much - doxygen seems to be doing exactly what I need.
ithcy
+2  A: 

Not sure there exists anything that can analyse source-code written in PHP to generate that... But there is a possiblity, when you are running the code.

You might want to take a look at the Xdebug extension : it brings profiling to PHP, and and generate callgrind-like files, that can be read with KCacheGrind on Linux.

And this one is able to generate some kind of callgraphs.


It can also be integrated with PHPUNit, to generate code-coverage when running unit-tests
Some time ago, PHPUnit was able to generate some callgraphs with graphviz ; I don't find that option anymore, though :-(


EDIT : it's the first time I hear about it, but there is a project called phpCallGraph that might be able to help you, too... and it seems there is work going on, if I look at it's changelog

Pascal MARTIN
Thank you - I have tried using Xdebug in the past and unfortunately I cannot get it to work correctly on my target platform, which is an embedded MIPS linux device with some peculiar Apache restrictions (TLS only, one listener process, etc.)
ithcy
Ho... Maybe not so easy, then ^^ You absolutly have no access to a "standard Linux" machine ? Maybe using virtualization ?
Pascal MARTIN
well, the PHP runs on the platform I mentioned, so the debugger has to run there as well. I will try again someday :) phpCallGraph looks promising though - will check it out. Thanks!
ithcy
You're welcome :-) (could you just add one comment here, when you have tested it, to say how good/bad you think it is ? )
Pascal MARTIN
I will try to remember :)
ithcy
A: 

Thie XML/SWF charts and graphs are a great solution. Nice looking output using Flash

http://www.maani.us/xml_charts/

Richard Testani
Sorry, this is not at all what I am looking for. I am looking for a tool that analyzes source code and generates relationship graphs (call graphs) between classes, subroutines, etc.
ithcy
+1  A: 

As noted already, Doxygen can generate gall graphs.

Xdebug can generate function traces. These differ from doxygen's graphs in that they are generated from runtime code, whereas doxygen is generated statically. I don't know of any tools that can turn the function traces into a visual representation, although it shouldn't be that hard to do.

There is also the bytekit extension, which primary function is to show the bytecode that php source code will generate. It can show this in a graph, that is essentially a gallgraph.

troelskn
+1  A: 

If you need something interactive, check out the new nWire for PHP. It is an Eclipse plugin which works with either PDT 2.1 and Zend Studio 7.0.

zvikico
ah, very cool, thanks.
ithcy