Processing cachegrind files on Windows
Recently I wanted to get some impression of the performance of a certain web page generated by some PHP code written by myself, on top of the Symfony framework and the Apostrophe Now CMS. This was the picture I had in mind:
This way I could find out if too much time was spent in certain parts of the code.
First I enabled Xdebug (which was already installed on my server) from within the .htaccess in the web directory of my project. I added these lines:
php_value xdebug.profiler_enable_trigger 1 php_value xdebug.profiler_output_dir /project_dir/data/profiler
I created the given profiler output directory and gave it write permissions for the user that runs the webserver.
Then I typed the URL of the page I wanted to profile inside the browser and added ?XDEBUG_PROFILE to the URL. After pressing Enter, I found a cachegrind.out.xxxx file was generated in the profiler output directory I had provided.
Now, which tool to use (on my Windows computer) to process this file and get a visual representation of my code’s performance?
After some Googling, I found KCachegrind for Windows (called QCachegrind, compiled by Lailin Chen). This seemed to be the best application available. And after downloading the ZIP-file and it’s contents to the Program Files directory, I executed kcachegrind.exe and opened the generated cachegrind file (I had to type in the exact name of the file, since it didn’t match the file filter in the File open dialog of KCachegrind).
When the file was processed, I selected the {main} function and clicked on Call Graph. Who would have guessed: it generated exactly the picture I had in mind!