Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP call graph utility? [closed]

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?

like image 304
glomad Avatar asked Aug 05 '09 20:08

glomad


4 Answers

I would definitely try Doxygen. It has support for PHP, and the call graphs and caller graphs it creates have been very useful in exploring "foreign code" for me previously.

Example of doxygen call graph

like image 158
Bjarke Freund-Hansen Avatar answered Oct 23 '22 04:10

Bjarke Freund-Hansen


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

like image 4
Pascal MARTIN Avatar answered Oct 23 '22 04:10

Pascal MARTIN


As noted already, Doxygen can generate call 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 callgraph.

like image 3
troelskn Avatar answered Oct 23 '22 03:10

troelskn


This is an old topic - but in case anyone finds it useful....

  • kKCachegrind will produce callgraphs shown the actual execution threads.

  • PHPCallGraph is a fairly simple around graphviz which perfroms static analysis

  • There's also my own effort which is similar to PHPCallGraph but adds information about loops/conditional structures and provides a method for adding callbacks to nodes. Some example scripts are bundled with the toolkit - but you can also embed it in your own scripts.

like image 3
symcbean Avatar answered Oct 23 '22 02:10

symcbean