Skip to content

Commit 530f778

Browse files
committed
Adds profiler
1 parent 14170af commit 530f778

File tree

10 files changed

+1905
-2342
lines changed

10 files changed

+1905
-2342
lines changed

app/Http/Controllers/CallAction.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Modules\Ray\RayCommon as RayCommonActions;
88
use App\Modules\Ray\RayLaravel as RayLaravelActions;
99
use App\Modules\Sentry\Common as SentryActions;
10+
use App\Modules\Profiler\Common as ProfilerActions;
1011
use App\Modules\Smtp\Common as SmtpActions;
1112
use App\Modules\VarDump\Common as VarDumpActions;
1213
use App\Modules\Inspector\Common as InspectorActions;
@@ -23,12 +24,14 @@ class CallAction extends Controller
2324
VarDumpActions,
2425
InspectorActions,
2526
InspectorActions,
27+
ProfilerActions,
2628
WithFaker;
2729

2830
private array $setUpMap = [
29-
'ray_logs:' => 'setUpRayLogger',
30-
'monolog:' => 'setUpSocketMonolog',
31+
// 'ray_logs:' => 'setUpRayLogger',
32+
'profiler:' => 'setupProfiler',
3133
'sentry:' => 'setupSentryLogger',
34+
'monolog:' => 'setUpSocketMonolog',
3235
'var_dump:' => 'setUpVarDumper',
3336
'inspector:' => 'setUpInspector',
3437
];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Middleware;
6+
7+
use Illuminate\Contracts\Foundation\Application;
8+
use Illuminate\Http\Request;
9+
use SpiralPackages\Profiler\Profiler;
10+
11+
class ProfilerMiddleware
12+
{
13+
public function __construct(
14+
private Application $app,
15+
) {
16+
}
17+
18+
public function handle(Request $request, \Closure $next)
19+
{
20+
$profiler = $this->app->make(Profiler::class, [
21+
'appName' => 'Simple app',
22+
]);
23+
24+
$profiler->start();
25+
26+
27+
try {
28+
return $next($request);
29+
} finally {
30+
$profiler->end([
31+
'uri' => (string)$request->getUri(),
32+
]);
33+
}
34+
}
35+
}

app/Modules/Profiler/Common.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Modules\Profiler;
5+
6+
trait Common
7+
{
8+
public function setupProfiler()
9+
{
10+
ray()->disable();
11+
logger()->setDefaultDriver('null');
12+
}
13+
14+
/** @test */
15+
function profilerReport()
16+
{
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Providers;
6+
7+
use Illuminate\Support\ServiceProvider;
8+
use SpiralPackages\Profiler\Driver\DriverInterface;
9+
use SpiralPackages\Profiler\DriverFactory;
10+
use SpiralPackages\Profiler\Storage\StorageInterface;
11+
use SpiralPackages\Profiler\Storage\WebStorage;
12+
use Symfony\Component\HttpClient\NativeHttpClient;
13+
14+
class ProfilerServiceProvider extends ServiceProvider
15+
{
16+
public function register()
17+
{
18+
$this->app->bind(StorageInterface::class, function () {
19+
return new WebStorage(
20+
new NativeHttpClient(),
21+
config('services.profiler.endpoint'),
22+
);
23+
});
24+
25+
$this->app->bind(DriverInterface::class, function () {
26+
return DriverFactory::detect();
27+
});
28+
}
29+
}

composer.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@
55
"keywords": ["framework", "laravel"],
66
"license": "MIT",
77
"require": {
8-
"php": "^7.3|^8.0",
9-
"blackfire/php-sdk": "^1.31",
8+
"php": "^8.0",
109
"fruitcake/laravel-cors": "^2.0",
1110
"guzzlehttp/guzzle": "^7.0.1",
1211
"inspector-apm/inspector-laravel": "^4.7",
13-
"laravel/framework": "^8.54",
12+
"laravel/framework": "^9.0",
1413
"laravel/tinker": "^2.5",
1514
"sentry/sentry-laravel": "^2.8",
16-
"spatie/laravel-ray": "^1.24"
15+
"spatie/laravel-ray": "^1.24",
16+
"spiral-packages/profiler": "^1.0"
1717
},
1818
"require-dev": {
19-
"facade/ignition": "^2.5",
2019
"fakerphp/faker": "^1.9.1",
21-
"laravel/sail": "^1.0.1",
2220
"mockery/mockery": "^1.4.2",
23-
"nunomaduro/collision": "^5.0",
2421
"phpunit/phpunit": "^9.3.3"
2522
},
2623
"autoload": {

0 commit comments

Comments
 (0)