Skip to content

Commit 1a3ca55

Browse files
piggitoandypost
authored andcommitted
Add template for blackfire profiling
1 parent 6b8a853 commit 1a3ca55

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ networks:
117117
* `make front` - Builds frontend tasks.
118118
* `make lint` - Runs frontend linters.
119119
* `make storybook` - Runs storybook in current theme.
120+
* `make blackfire` - Adds and enables blackfire.io php extension, needs [configuration](https://blackfire.io/docs/configuration/php) in docker-composer override.yml.
120121

121122
#### Additional goals
122123

docker/docker-compose.override.yml.default

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ services:
66
php:
77
environment:
88
COMPOSER_MEMORY_LIMIT: "-1"
9+
# BLACKFIRE_CLIENT_ID: x
10+
# BLACKFIRE_CLIENT_TOKEN: x
911
volumes:
1012
- "./90-mail.ini:/etc/php7/conf.d/90-mail.ini:z"
1113
# depends_on:
@@ -14,6 +16,19 @@ services:
1416
# Uncomment next line if you need PHP XDebug.
1517
# command: php-fpm7 -F -d zend_extension=xdebug.so
1618

19+
# Get access keys from https://blackfire.io/my/profiles
20+
# Then download extension using "make blackfire"
21+
22+
# blackfire:
23+
# image: blackfire/blackfire
24+
# container_name: "${COMPOSE_PROJECT_NAME}_blackfire"
25+
# environment:
26+
# BLACKFIRE_SERVER_ID: x
27+
# BLACKFIRE_SERVER_TOKEN: x
28+
# BLACKFIRE_LOG_LEVEL: 1
29+
# networks:
30+
# - front
31+
1732
# adminer:
1833
# image: dockette/adminer:mysql-php7
1934
# container_name: "${COMPOSE_PROJECT_NAME}_adminer"

scripts/makefile/blackfire.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env sh
2+
3+
# installs backfire/io probe extension
4+
5+
# use `php -i | grep "additional .ini"` to get it
6+
PHP_INI_DIR=/etc/php7/conf.d
7+
8+
set -e
9+
10+
env_vars='BLACKFIRE_CLIENT_ID BLACKFIRE_CLIENT_TOKEN'
11+
12+
for var in $env_vars; do
13+
eval "val=\${$var}"
14+
if [ -z "${val}" -o "${val}" = 'x' ]; then
15+
echo "Configure ${var} in docker-compose.override.yml"
16+
echo "Visit https://blackfire.io/my/settings/credentials to get credentials"; exit 1
17+
fi
18+
done
19+
20+
version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
21+
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/amd64/$version \
22+
&& mkdir -p /tmp/blackfire \
23+
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
24+
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
25+
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/blackfire.ini \
26+
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

scripts/makefile/tests.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,12 @@ sniffers: | clang compval phpcs newlineeof
187187
## Run all tests & validations (including sniffers)
188188
tests: | sniffers cinsp drupalrectorval upgradestatusval behat watchdogval statusreportval
189189

190+
blackfire:
191+
ifneq ("$(wildcard scripts/makefile/blackfire.sh)","")
192+
$(call php-0, /bin/sh ./scripts/makefile/blackfire.sh)
193+
$(call php-0, kill -USR2 1)
194+
@echo "Blackfire extension enabled"
195+
else
196+
@echo "scripts/makefile/blackfire.sh file does not exist"
197+
@exit 1
198+
endif

0 commit comments

Comments
 (0)