Profile function usage
This documentation needs review. See "Help improve this page" in the sidebar.
Step 1: Configure the Xdebug in profiler mode
Add the blow settings to your php.ini or if you have xdebug specific .ini file then add the below settings in that file.
This setting is only valid for Xdebug V3.*.
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.start_with_request=yes
# Supported values for xdebug.mode are develop, debug, profile, trace etc.
# @See https://xdebug.org/docs/all_settings#mode
xdebug.mode=profile
xdebug.output_dir=/tmp
xdebug.trace_output_name=cachegrind.out.%R
xdebug.trace_format=1
xdebug.profiler_output_name=cachegrind.out.%R
xdebug.profiler_append=0
xdebug.use_compression=0Step 2: Bind mount the /tmp folder to web container (ddev specific)
This step is ddev specific. You need to do the similar step if you are using something else.
The xdebug profiler will generate the profiler reports in /tmp folder. We need to bind mount this /tmp folder to both web container and webgrind container so that webgrind can see the profilers files generated by xdebug in web container.
- Create a file under
.ddev/docker-compose.mount.yml - Add the below code to this file and save it.
services:
web:
# Bind mount the /tmp folder to 'web' service /tmp folder. The same /tmp
# folder is also bind mount to 'webgrind' service. This is a way to share
# profiler generated files between 'web' and 'webgrind' service. @See webgrind
# service for similar bind in .ddev/docker-compose.webgrind.yml. Xdebug
# profiler files are generated in /tmp folder. @See
# for .ddev/php/xdebug_client_port.ini for xdebug profiler config.
volumes:
- type: bind
source: /tmp
target: /tmp
consistency: cachedStep 3: Run the webgrind to interpret the profiler report (ddev specific)
Run the webgrind so that you can see the profiler report generated by xdebug profiler and see the function/method call counts and their time consumption. You can run
- Create a file under
.ddev/docker-compose.webgrind.yml - Add the below code to this file and save it.
services:
webgrind:
platform: linux/x86_64
image: jokkedk/webgrind
container_name: "ddev-${DDEV_SITENAME}-webgrind"
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: ${DDEV_APPROOT}
expose:
- 9999
environment:
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=9998:80
- HTTPS_EXPOSE=9999:80
volumes:
# Bind mount the /tmp folder to 'webgrind' service /tmp folder. The same
# /tmp folder is also bind mount to 'web' service. This is a way to share
# profiler generated files between 'webgrind' and 'web' service. @See web
# service for similar bind in .ddev/docker-compose.mount.yaml file. Xdebug
# profiler files are generated in /tmp folder. @See
# for .ddev/php/xdebug_client_port.ini for xdebug profiler config.
- type: bind
source: /tmp
target: /tmp
consistency: cachedStep 3: Restart the ddev and enable xdebug (ddev specific)
- Now restart the ddev with
ddev restart. - Enable the xdebug with
ddev xdebug on.
Steps 4: Generate the xdebug profiler reports and see in webgrind
- If you have configured everything correctly. Now if you visit any page your profiler reports will be generated under
/tmpfolder with namecachegrind.out.<route>format. - Now you can check these profiler reports inside the webgrind by accessing the
webgrindservice. For ddev it will be accessible athttp://<projectname>.ddev.site:9998orhttps://<projectname>.ddev.site:9999 - Now you can select the report from the dropdown in webrind and see the function/method calls and their time consumptions.

Webgrind Screenshot
Known issue:
The sorting functionality of table in webgrind will not work. This is because of jquery verison being used by webgrind. This github issue should solve this problem. https://github.com/jokkedk/webgrind/pull/187
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.