2. Webgrind
“Webgrind is a Xdebug profiling web frontend in PHP.
It implements a subset of the features of kcachegrind
and installs in seconds and works on all platforms. For
quick'n'dirty optimizations it does the job.”
https://github.com/jokkedk/webgrind
3. Introduction
Webgrind - why?
● Characterise to optimise
● No point in optimising code without characterising
● Look inside libraries
● Find the slow bits
● Understand the platforms you work on
4. Install xdebug
You probably don’t need to.
php 5
sudo apt-get install php5-xdebug
php 7
sudo apt-get install php-xdebug
7. Enable xdebug per thing
Pop it in your .ini or .htaccess like...
xdebug.profiler_enable=1
...great for a quick debug/profile of system
characterisation.
8. Just copy the files to
Easiest bit :)
● Download from github
● Put them in a folder under your web root
● Change the config.php if the xdebug isn’t outputting to
/tmp
9. Use cases?
● How can I make this bat-shit fast?
● Why is this server / system slower than the other one?
● What’s holding this up?
● How does the performance differ between library X
and Y?
10. Just hit it up in your browser
Just go to wherever you put the files, ie
http://localhost/webgrind or
http://dev.stuff.com/webgrind
11. Looking at results
Loads of info, have a tinker…
● Tweak the settings, to remove some noise
● Change the sorts
● Browse the call graph
● Compare costs
12.
13.
14.
15.
16. Practical example
● API experiences large slow-down with growth in data
size
● Characterised with Webgrind
18. Tricks and tips - running
● Sometimes it can take a couple of minutes to generate
the report
● Sometimes it can crash your system if it’s doing big
stuff
● You can see the files being created to gauge size /
complexity, ie “ls -lha /tmp/cachegrind*”
● If it’s taking crazy-long, set the “show” value lower
19. Tricks and tips - analysing
● Call graphs are colour coded
● If you don’t like svg call graphs, you can set
“graphImageType” to “png” in webgrind/config.php
20. Other options
● Do it in your IDE, via xdebug remote profiler
○ PHP Storm
○ Eclipse
○ NotePad++
● Use KCachegrind / Callgrind, a Linux (KDE) profiling
App
21. Read more
● Webgrind website (just github)
https://github.com/jokkedk/webgrind
● Google your platform for WAMP, MAMP or NGINX
info