Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xdebug profiler documentation #257

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.