From 1adaaa8116c2ac56df3502d32c550f0a807177eb Mon Sep 17 00:00:00 2001 From: "moldabayev.v" Date: Tue, 5 Jan 2021 16:47:43 +0600 Subject: [PATCH 1/3] Added profiling jobs --- src/Listeners/ProfileJob.php | 49 ++++++++++++++++++++++++++ src/Providers/PinbaServiceProvider.php | 16 +++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/Listeners/ProfileJob.php diff --git a/src/Listeners/ProfileJob.php b/src/Listeners/ProfileJob.php new file mode 100644 index 0000000..40d5a93 --- /dev/null +++ b/src/Listeners/ProfileJob.php @@ -0,0 +1,49 @@ +profiler = $profiler; + } + + public function handle($event) + { + if ($event instanceof JobProcessing) { + self::$timerId = $this->profiler->startTimer( + 'worker', + 'run', + $event->job->getName(), + 'messenger:consume' + ); + + return; + } + + if ($event instanceof JobProcessed) { + $this->profiler->stopTimer(self::$timerId); + $this->profiler->flush($event->job->resolveName()); + + return; + } + + if ($event instanceof JobFailed) { + $this->profiler->stopTimer(self::$timerId); + $this->profiler->flush($event->job->resolveName()); + + return; + } + } +} diff --git a/src/Providers/PinbaServiceProvider.php b/src/Providers/PinbaServiceProvider.php index 81d5230..e9eedc0 100644 --- a/src/Providers/PinbaServiceProvider.php +++ b/src/Providers/PinbaServiceProvider.php @@ -2,6 +2,7 @@ namespace Chocofamilyme\LaravelPinba\Providers; +use Chocofamilyme\LaravelPinba\Listeners\ProfileJob; use Chocofamilyme\LaravelPinba\Listeners\ProfileStartCommand; use Chocofamilyme\LaravelPinba\Middlewares\RightUrlMiddleware; use Chocofamilyme\LaravelPinba\Profiler\FileDestination; @@ -109,6 +110,21 @@ private function initListeners(): void \Illuminate\Console\Events\CommandStarting::class, ProfileStartCommand::class ); + + Event::listen( + \Illuminate\Queue\Events\JobProcessing::class, + ProfileJob::class + ); + + Event::listen( + \Illuminate\Queue\Events\JobProcessed::class, + ProfileJob::class + ); + + Event::listen( + \Illuminate\Queue\Events\JobFailed::class, + ProfileJob::class + ); } /** @psalm-suppress UndefinedDocblockClass */ From 252b8bb2f1decc7c01c910cea7e8a50f70678651 Mon Sep 17 00:00:00 2001 From: "moldabayev.v" Date: Tue, 5 Jan 2021 16:48:12 +0600 Subject: [PATCH 2/3] Added profiling jobs --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d7c4d..7eb4811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 2.2.0 +- Added profiling jobs + ## 2.1.0 - Added profiling of console commands From 6159740cca14602a6a62aef2bec999ba93b3a80a Mon Sep 17 00:00:00 2001 From: "moldabayev.v" Date: Tue, 5 Jan 2021 16:52:02 +0600 Subject: [PATCH 3/3] Added profiling jobs --- composer.json | 76 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/composer.json b/composer.json index e925e4a..c993b3e 100644 --- a/composer.json +++ b/composer.json @@ -1,37 +1,43 @@ { - "name": "chocofamilyme/laravel-pinba", - "description": "Integrates pinba with Laravel", - "keywords": ["laravel", "pinba", "profiler", "debug"], - "type": "library", - "license": "BSD-3-Clause", - "authors": [ - { - "name": "IT Chocolife.me", - "homepage": "https://chocolife.me" - } - ], - "require": { - "php": ">= 7.4.0", - "illuminate/log": "^8.0", - "illuminate/http": "^8.0", - "illuminate/routing": "^8.0" - }, - "require-dev": { - "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "^4.3" - }, - "autoload": { - "psr-4": { - "Chocofamilyme\\LaravelPinba\\": "src" - } - }, - "extra": { - "laravel": { - "providers": [ - "Chocofamilyme\\LaravelPinba\\Providers\\PinbaServiceProvider" - ] - } - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "chocofamilyme/laravel-pinba", + "description": "Integrates pinba with Laravel", + "keywords": [ + "laravel", + "pinba", + "profiler", + "debug" + ], + "type": "library", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "IT Chocolife.me", + "homepage": "https://chocolife.me" + } + ], + "require": { + "php": ">= 7.4.0", + "illuminate/log": "^8.0", + "illuminate/http": "^8.0", + "illuminate/queue": "^8.0", + "illuminate/routing": "^8.0" + }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^4.3" + }, + "autoload": { + "psr-4": { + "Chocofamilyme\\LaravelPinba\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Chocofamilyme\\LaravelPinba\\Providers\\PinbaServiceProvider" + ] + } + }, + "minimum-stability": "dev", + "prefer-stable": true }