makinacorpus/profiling
A lightweight profiling package for Laravel and PHP applications. Add simple instrumentation to measure execution time, memory usage, and custom checkpoints, making it easier to find bottlenecks and optimize performance.
composer require makinacorpus/profiling
src/ directory. You’ll likely find a small set of classes such as Profiler or Timer that wrap hrtime(). There is no Laravel service provider or facade, so you instantiate manually.use MakinaCorpus\Profiling\Profiler;
$profiler = new Profiler();
$profiler->start('query');
$users = User::where('active', true)->get();
$profiler->stop('query');
// In local/debug only:
dump($profiler->getDuration('query')); // nanoseconds or seconds, check source
Confirm the exact API (method names, units) from the source before relying on it.AppServiceProvider so the same profiler instance is reused across a request:
$this->app->singleton(Profiler::class, fn () => new Profiler());
function profile(string $label, callable $callback) {
$p = app(Profiler::class);
$p->start($label);
try {
return $callback();
} finally {
$p->stop($label);
}
}
$result = profile('expensive', fn () => SomeService::compute());
public function handle($request, Closure $next) {
if (! app()->environment('local')) {
return $next($request);
}
$p = app(Profiler::class);
$p->start('request');
$response = $next($request);
$p->stop('request');
Log::debug('Request duration', ['duration' => $p->getDuration('request')]);
return $response;
}
$p = new Profiler();
$p->start('import');
$this->importLargeFile();
$p->stop('import');
$this->info('Import took ' . $p->getDuration('import') . ' ns');
$p = new Profiler();
$p->start('serialize');
$payload = $model->toArray();
$p->stop('serialize');
$this->assertLessThan(5_000_000, $p->getDuration('serialize')); // 5 ms in ns
Benchmark helper (Benchmark::measure()) or Telescope/Debugbar provide richer context with zero extra dependencies.hrtime() – PHP 7.3+. Confirm your minimum PHP version.app()->environment('local') or a config flag. Do not leave active in production.dump()/Log::debug() on results; because there is no reporter, you’ll build your own output formatting.symfony/stopwatch (well-maintained, PSR-friendly), Laravel’s Benchmark, or spatie/laravel-ray for richer local debugging.How can I help you explore Laravel packages today?