A quick overview of how to get started visualizing your Drupal (or PHP in general, or whatever language) code. Helpful for learning complicated systems, finding performance bottlenecks, and feeling cool.
2. OUTLINE
Why? / The Benefit
How to get setup
Limitations and ass-umptions
Discuss other available tools
3. WHY? / THE BENEFIT
Get a bird’s eye view of important Drupal Subsystems like Views,
Theme, Entity API, Forms API, etc… before you get buried in
never-ending callstacks.
See which parts of a system take the longest so you can focus
your limited time where it will have the most impact.
Quickly refresh memory about an area you haven’t been in for a
while.
Use to analyze system for understanding, bug fixing, etc… Easier
for multiple people to think about something together.
4. HOW TO GET SETUP
Tools you’ll need:
Xdebug
PHPStorm setup: https://www.jetbrains.com/phpstorm/help/configuring-xdebug.html
Netbeans setup: http://wiki.netbeans.org/HowToConfigureXDebug
Need one extra config setting in your php.ini to output a profiler/cachegrind file
http://www.xdebug.org/docs/profiler
This is the dumped data used to create the visualizations
CacheGrind (different versions for Mac, Win, Linux)
Find the version for your platform, also here: http://www.xdebug.org/docs/profiler
For Mac: https://langui.sh/2011/06/16/how-to-install-qcachegrind-kcachegrind-on-
mac-osx-snow-leopard/
5. VISUALIZE THE CALL STACK
On localhost, with the correct xdebug.profiler_enable settings,
load a page.
This generates a cachegrind.out.nnn file in your /tmp directory.
Open qcachegrind and load the cachegrind.out.nnn file
BOOM BABY!
Let’s look at it live.
6. LIMITATIONS
The visualization doesn’t portray time/sequence.
Good article, “How Profilers Lie.”
http://yosefk.com/blog/how-profilers-lie-the-cases-of-gprof-and-
kcachegrind.html
7. OTHER AVAILABLE TOOLS
Kazanir mentioned blackfire: http://blackfire.io/
XHProf – not familiar with how this is different from what you get
with xdebug.
NewRelic has a little overlap as far as finding bottlenecks –
awesome tool I wouldn’t want to live without.