Skip to content

Commit

Permalink
Merge pull request #257 from City-of-Helsinki/UHF-X_xdebug_profiler_d…
Browse files Browse the repository at this point in the history
…ocumentation

Xdebug profiler documentation
  • Loading branch information
khalima authored Oct 9, 2024
2 parents 5ab362d + 11926be commit 7f7aaa4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
3 changes: 1 addition & 2 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- [Local environment](/documentation/local.md)
- [Profiling code with Blackfire.io](/documentation/blackfire.md)
- [Profiling code with Xdebug profiler](/documentation/xdebug-profiler.md)

## Infrastructure

Expand All @@ -33,5 +34,3 @@

- [Testing and CI](/documentation/testing.md)
- [PHPstan](/documentation/phpstan.md)


53 changes: 53 additions & 0 deletions documentation/xdebug-profiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Profiling code with Xdebug PHP Profiler

Create a modified xdebug.ini to your project's root:
```ini
zend_extension=/usr/lib/php83/modules/xdebug.so
xdebug.mode=profile
xdebug.output_dir=/app/xdebug
xdebug.profiler_enable=1
xdebug.profiler_output_name=cachegrind.out.%p
xdebug.use_compression=false
```

Create a `Dockerfile.profile` file in your project's root:
```bash
ARG DRUPAL_IMAGE
FROM ${DRUPAL_IMAGE}

COPY xdebug.ini /etc/php83/conf.d/50_xdebug.ini

RUN mkdir -p /app/xdebug
```

Modify your `compose.yaml` file:

```diff
diff --git a/compose.yaml b/compose.yaml
index 99f55b27..27580975 100644
--- a/compose.yaml
+++ b/compose.yaml
@@ -1,7 +1,12 @@
services:
app:
container_name: "${COMPOSE_PROJECT_NAME}-app"
- image: "${DRUPAL_IMAGE}"
+ # image: "${DRUPAL_IMAGE}"
+ build:
+ context: .
+ dockerfile: Dockerfile.profile
+ args:
+ DRUPAL_IMAGE: "${DRUPAL_IMAGE}"
hostname: "${COMPOSE_PROJECT_NAME}"
volumes:
- .:/app:delegated
```

Build the image with the dockerfile and start up the project
```bash
docker compose up --wait --remove-orphans --build`
```

Load the page you want to profile and check that the log files start to appear in project's `xdebug` folder.
Use [qcachegrind](https://formulae.brew.sh/formula/qcachegrind) (for Mac) or [kcachegrind](https://kcachegrind.github.io/) (for Linux) to open the log files in a GUI.

0 comments on commit 7f7aaa4

Please sign in to comment.