Made of Everything You're Not

If you're a stalker I'd prefer if you didn't kill me. Thanks.
  • Home
  • Projects
  • Portfolio
  • Resume
« How to Kill a Project in 1 Decision
Corrupt OST Files in Outlook 2003 »

Using Xdebug Profiler on Vista

One of the coolest features of Xdebug is the Profiler. By enabling the Profiler you can generate what are essentially full traces about your php scripts that are invaluable in fine tuning your code and isolating problem areas effectively.

Xdebug

Xdebug

According to the official page on the xdebug Profiler:

Xdebug’s built-in profiler allows you to find bottlenecks in your script and visualize those with an external tool such as KCacheGrind or WinCacheGrind. Xdebug’s Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost.

There’s some serious information in these little files too. By importing the debug files into a tool called WinCacheGrind you can view the files in a format that won’t make you stick a knife in your eyes.

Here’s a small example of the exported data:

version: 0.9.6
cmd: C:ProjectFilescat_v2index.php
part: 1
 
events: Time
 
fl=php:internal
fn=php::define
3 7
 
fl=php:internal
fn=php::get_include_path
4 6
 
fl=php:internal
fn=php::set_include_path
4 5

To get started first make sure you have Xdebug 2.0 installed. To check, execute the below in a dos prompt:

php -v

You should see something like the below:

PHP 5.2.6 (cli) (built: May  2 2008 18:02:07)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans

If not, you’ll need to download and install Xdebug.

If you do have Xdebug, modify your php.ini to include the below after the Xdebug init call:

xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "C:/path/to/profiler/storage"

Once you’ve configured php you might need to restart your server depending on how php is implemented. Either way, to generate a profile output just execute a script; the output should be written to the directory you set in the xdebug.profiler_output_dir.

All that’s left is to open the profile output in WinCacheGrind.

WinCacheGrind

WinCacheGrind

Notes:
The profilers seems to only record data if the script is executed from the command line.
Download WinCacheGrind

Bookmark and Share

Related Posts

Stand Alone ExpressionEngine Authentication
Importing Legacy Users Into ExpressionEngine
CartThrob 2.0 Beta Fun
ExpressionEngine and the Mystery of M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr
Custom Routes With Zend Framework

Tags: php, WinCacheGrind, xdebug

This entry was written by Eric Lamb and posted on Wednesday, February 25th, 2009 at 12:00 pm and is filed under Code, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Click here to cancel reply.

  • Subscribe: Entries | Comments
  • About Me

    Email Email
    Twitter Twitter
    310.739.3322
  • Categories

    • Brain Dump
    • Business
    • Code
    • IT
    • Programming
    • Rant
    • Servers
  • Archives

    • October 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008

Copyright © 2008 - 2012 Eric Lamb - All rights reserved