-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from chocofamilyme/job.profiling
Job.profiling
- Loading branch information
Showing
4 changed files
with
109 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Changelog | ||
|
||
## 2.2.0 | ||
- Added profiling jobs | ||
|
||
## 2.1.0 | ||
- Added profiling of console commands | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chocofamilyme\LaravelPinba\Listeners; | ||
|
||
use Chocofamilyme\LaravelPinba\Profiler\ProfilerInterface; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
use Illuminate\Queue\Events\JobProcessed; | ||
use Illuminate\Queue\Events\JobFailed; | ||
|
||
final class ProfileJob | ||
{ | ||
private ProfilerInterface $profiler; | ||
private static int $timerId; | ||
|
||
public function __construct(ProfilerInterface $profiler) | ||
{ | ||
$this->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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters