Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Stopwatch Laravel Package

symfony/stopwatch

Symfony Stopwatch is a lightweight profiling utility to measure execution time and memory usage in PHP. Start/stop named events, record laps, and group timings into sections (phases) to benchmark code paths and understand performance bottlenecks.

View on GitHub
Deep Wiki
Context7

Provides a way to profile code

Frequently asked questions about Stopwatch
How do I integrate Symfony Stopwatch into a Laravel application?
Install via Composer (`composer require symfony/stopwatch`), then bind it to Laravel’s service container in a provider. Use `Stopwatch::start()` and `Stopwatch::stop()` around code blocks to measure execution time. For example, wrap Eloquent queries or queue jobs to profile their performance.
Does Symfony Stopwatch work with Laravel’s queue system (e.g., Horizon)?
Yes. Use Laravel’s `JobProcessed` event to start/stop Stopwatch around job execution. This lets you profile background tasks, delayed jobs, and CLI-driven queue workers without modifying job classes directly. Pair with Laravel’s event listeners for seamless integration.
Can I use Stopwatch to profile database queries in Laravel?
Absolutely. Wrap Eloquent queries or raw PDO statements with `Stopwatch::start('query_name')` and `Stopwatch::stop('query_name')`. For reusable profiling, create a trait or macro to auto-instrument queries. Stopwatch’s lightweight design makes it ideal for microbenchmarking slow queries in development or staging.
Will Symfony Stopwatch work with Laravel 10 and PHP 8.4+?
Yes, Stopwatch v8.x supports PHP 8.4+, aligning with Laravel 10’s requirements. For older Laravel versions (e.g., 9.x), use Stopwatch v7.x. Always check the [Symfony compatibility table](https://symfony.com/releases) to ensure version alignment with your Laravel setup.
How do I log Stopwatch data to Laravel’s Telescope or a database?
Stopwatch events are in-memory only, but you can log them via Laravel’s logging system. Convert events to arrays with `$event->toArray()` and pass them to `Log::info()` or store them in Telescope’s `logs` table. For historical analysis, pair with a database table or use Laravel’s `Log::channel('single')` for structured storage.
Is Symfony Stopwatch suitable for production profiling?
Stopwatch has minimal overhead (~microseconds per event), but frequent profiling in production may impact performance. Disable it in production via config or environment checks. Use it sparingly for critical paths (e.g., API endpoints) or pair it with feature flags to toggle profiling dynamically.
Can I auto-instrument common Laravel operations (e.g., routes, middleware) with Stopwatch?
Yes. Create middleware to profile HTTP requests or use Laravel’s `registerMacro` to add Stopwatch methods to Eloquent models. For example, add a `profile()` macro to queries or wrap middleware in a `ProfileMiddleware` trait. This reduces manual instrumentation effort while keeping profiling targeted.
How does Stopwatch compare to Blackfire or New Relic for Laravel?
Stopwatch is lightweight and manual (requires explicit `start()`/`stop()` calls), while Blackfire/New Relic offer automated full-stack profiling. Use Stopwatch for granular, low-overhead benchmarks (e.g., CLI tasks, queue jobs) and pair it with Blackfire for deep HTTP request analysis. Stopwatch is ideal for developers who need control over what’s profiled.
Does Stopwatch support memory usage tracking in Laravel?
Yes. Stopwatch tracks both execution time and memory usage by default. Access memory metrics via `$event->getMemory()` (in bytes) or `$event->getMemoryDelta()` (memory consumed during the event). Log these values alongside timing data for comprehensive performance analysis in Laravel applications.
How can I visualize Stopwatch data in Laravel Debugbar?
Extend Laravel Debugbar’s collector to display Stopwatch events. Create a custom collector that fetches the latest Stopwatch data and renders it in Debugbar’s toolbar or panel. This provides a real-time UI for profiling without leaving your browser, similar to how Blackfire integrates with Debugbar.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi