Add blackfire service for profiling

This commit is contained in:
Kacper Donat 2020-03-15 17:30:08 +01:00
parent 50a79470e7
commit 1a0515742e
4 changed files with 47 additions and 26 deletions

View File

@ -1,4 +1,4 @@
version: '2'
version: '3.4'
services:
nginx:
@ -11,9 +11,15 @@ services:
php:
build: docker/php
mem_limit: 2g
env_file:
- ./docker/php/.env
volumes:
- ./:/var/www:cached
- ./docker/php/log.conf:/usr/local/etc/php-fpm.d/zz-log.conf
blackfire:
image: blackfire/blackfire
ports: ["8707"]
environment:
- BLACKFIRE_SERVER_ID
- BLACKFIRE_SERVER_TOKEN

View File

@ -7,19 +7,30 @@ RUN apt-get update && \
RUN docker-php-ext-install zip
# XDebug
RUN pecl install xdebug-2.9.0 && docker-php-ext-enable xdebug
RUN echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
echo "xdebug.remote_host = ${XDEBUG_REMOTE_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;
RUN echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini;
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
# Blackfire
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
#Composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& mv composer.phar /usr/local/bin/composer \
&& chmod +x /usr/local/bin/composer
# Timezone
RUN ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime
RUN echo "date.timezone = Europe/Warsaw" >> /usr/local/etc/php/conf.d/datetime.ini;
WORKDIR /var/www

View File

@ -12,4 +12,10 @@ function encapsulate($value)
default:
return [ $value ];
}
}
}
function setup($value, $callback)
{
$callback($value);
return $value;
}

View File

@ -21,6 +21,7 @@ use Carbon\Carbon;
use JMS\Serializer\Tests\Fixtures\Discriminator\Car;
use Tightenco\Collect\Support\Collection;
use Kadet\Functional\Transforms as t;
use function App\Functions\setup;
class ZtmGdanskDepartureRepository implements DepartureRepository
{
@ -162,25 +163,22 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
return $real;
}
$departure = clone $real;
$departure->setDisplay($real->getDisplay());
$departure->setTrack($scheduled->getTrack());
$departure->setTrip($scheduled->getTrip());
return $departure;
return setup(clone $real, function (Departure $departure) use ($scheduled, $real) {
$departure->setDisplay($real->getDisplay());
$departure->setTrack($scheduled->getTrack());
$departure->setTrip($scheduled->getTrip());
});
}
private function convertScheduledStopToDeparture(ScheduledStop $stop): Departure
{
$converted = new Departure();
$converted->setDisplay($stop->getTrack()->getDestination()->getName());
$converted->setLine($stop->getTrack()->getLine());
$converted->setTrack($stop->getTrack());
$converted->setTrip($stop->getTrip());
$converted->setScheduled($stop->getDeparture());
$converted->setStop($stop->getStop());
return $converted;
return setup(new Departure(), function (Departure $converted) use ($stop) {
$converted->setDisplay($stop->getTrack()->getDestination()->getName());
$converted->setLine($stop->getTrack()->getLine());
$converted->setTrack($stop->getTrack());
$converted->setTrip($stop->getTrip());
$converted->setScheduled($stop->getDeparture());
$converted->setStop($stop->getStop());
});
}
}