mlsamuelson.com

  • strict warning: Non-static method view::load_views() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 674.
  • strict warning: Non-static method view::db_objects() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/includes/view.inc on line 1159.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/filter.handlers.inc on line 570.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/filter.handlers.inc on line 570.
  • strict warning: Declaration of views_handler_filter_many_to_one::init() should be compatible with views_handler_filter::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/includes/filter.handlers.inc on line 1562.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/includes/argument.handlers.inc on line 694.
  • strict warning: Declaration of views_plugin_display::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/plugins.inc on line 1861.
  • strict warning: Declaration of views_plugin_display::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/plugins.inc on line 1861.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/mlsamuel/public_html/sites/all/modules/views/includes/plugins.inc on line 3100.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/plugins.inc on line 3673.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/includes/plugins.inc on line 3673.
  • strict warning: Declaration of views_handler_field_comment::init() should be compatible with views_handler_field::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/modules/comment.views.inc on line 480.
  • strict warning: Declaration of views_handler_field_username_comment::init() should be compatible with views_handler_field::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/modules/comment.views.inc on line 527.
  • strict warning: Declaration of views_handler_field_node_new_comments::pre_render() should be compatible with views_handler_field::pre_render($values) in /home/mlsamuel/public_html/sites/all/modules/views/modules/comment.views.inc on line 803.
  • strict warning: Declaration of views_handler_filter_node_status::operator_form() should be compatible with views_handler_filter::operator_form(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/modules/node.views.inc on line 1112.
  • strict warning: Declaration of views_handler_filter_search::exposed_validate() should be compatible with views_handler::exposed_validate(&$form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/modules/search.views.inc on line 230.
  • strict warning: Declaration of views_handler_field_file::init() should be compatible with views_handler_field::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/modules/system.views.inc on line 225.
  • strict warning: Declaration of views_handler_filter_term_node_tid::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/modules/taxonomy.views.inc on line 933.
  • strict warning: Declaration of views_handler_field_upload_description::init() should be compatible with views_handler_field::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/modules/upload.views.inc on line 269.
  • strict warning: Declaration of views_handler_field_user::init() should be compatible with views_handler_field::init(&$view, $options) in /home/mlsamuel/public_html/sites/all/modules/views/modules/user.views.inc on line 414.
  • strict warning: Declaration of views_handler_filter_user_name::value_submit() should be compatible with views_handler_filter_in_operator::value_submit($form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/modules/user.views.inc on line 746.
  • strict warning: Declaration of views_handler_filter_user_name::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/mlsamuel/public_html/sites/all/modules/views/modules/user.views.inc on line 746.
  • strict warning: Declaration of views_handler_field_content::options() should be compatible with views_object::options() in /home/mlsamuel/public_html/sites/all/modules/cck/includes/content.views.inc on line 378.
  • strict warning: Non-static method view::load() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 716.
  • strict warning: Non-static method view::load() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 716.
  • strict warning: Non-static method view::load() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 716.
  • strict warning: Non-static method view::load() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 716.
  • strict warning: Non-static method view::load() should not be called statically in /home/mlsamuel/public_html/sites/all/modules/views/views.module on line 716.

Install Webgrind to profile Drupal and other PHP applications on OS X

Screenshot of Webgrind

A coworker recently clued me in on Webgrind, a platform independent, browser-based PHP profiling application. I was impressed with it, and thought I'd contribute to the installation and usage instructions that are floating around the web with my specific setup.

Assumes you're using MAMP on OS X, but you can probably adapt.


  1. Install XDebug: I like the instructions at http://technosophos.com since they come with info on how to use XDebug for, well, debugging. (Note my comment on that post).
  2. Install Webgrind: Download, unpack and copy the webgrind directory to your web root.
  3. Add the following lines to the end of your php.ini (/Applications/MAMP/conf/php5/php.ini if you use PHP 5 in MAMP):
    xdebug.profiler_enable = 1
    xdebug.profiler_output_dir = /path/to/htdocs/webgrind/tmp
    xdebug.profiler_output_name = cachegrind.out.%t.%p

    Be sure to edit the path to match the location of your web root. Additionally, create the tmp directory under your webgrind directory.
  4. Edit Webgrind's config.php to use your /path/to/htdocs/webgrind/tmp:
    static $storageDir = '/path/to/htdocs/webgrind/tmp';
    static $profilerDir = '/path/to/htdocs/webgrind/tmp';
  5. Restart Apache for your php.ini settings to take effect.

(For another take on installation, see http://anantgarg.com/2009/03/10/php-xdebug-webgrind-installation/)

Once it's up and running, make some localhost requests. Then visit http://localhost/webgrind (or wherever you've installed Webgrind).

Select the profile file you'd like to use.
Webgrind's select file UI



If you're using a CMS such as Drupal, I recommend setting the "Show" percentage to 100% (the default is 90%), as it's likely the code you're wanting to profile is your own, which tends to drop off into the last 10% when you're dealing with CMS profiling.

When the profiler finishes processing the profile data you selected, you'll get a report similar to that depicted below.
Detail view of Webgrind report



Worth noting is the blue, lavender (here it's just a sliver), green and orange bar. These colors represent the distribution of built-in PHP functions (blue), include/require functions (lavender), class methods (green) and procedural functions (orange). Down the left side of the list of functions profiled, the color of the dots maps to these categories.

Now, click the arrow next to a function and you'll get a listing of function invocations, where each call occurred and their costs. This listing corresponds to the invocation count column.

Note also the Total Self Cost and Total Inclusive Cost columns. The former indicates the processing time for only the code in the function, while the latter also includes processing for calls to other functions made from that code.

The paragraph icons service as a nice added feature. Clicking them opens a new tab or browser window with the contents of the file that function is defined in.

When you're done using Webgrind, either update your php.ini to set

xdebug.profiler_enable = 0

Or if you'd rather, leave the profiler enabled. It'll only create profile files for localhost requests. These can eat up drive space and slow Webgrind though, so I prefer to turn it off when not I'm not using Webgrind.

In summary, there are other, heavier-weight, and more fully featured web profiling applications out there (such as kcachegrind) but for ease of use, platform independence, and a succinct but effective feature set, Webgrind is a great addition to any PHP dev's toolbox.

No comments

Add your comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Find Me Around

User login