async/amp-sql-profiler-bundle
Install the Bundle
composer require --dev async/amp-sql-profiler-bundle
Ensure dev environment only (remove 'test' from bundles.php if auto-added).
Replace Amp\Sql\Pool with ProfiledPool
In config/services_dev.yaml:
Amp\Postgres\PostgresConnectionPool: ~ # Replace with your DB driver (e.g., Amp\Mysql\MysqlConnectionPool)
ScriptFUSION\AmpSqlProfilerBundle\ProfiledPool:
arguments:
- '@Amp\Postgres\PostgresConnectionPool'
Verify Profiler Integration
Restart your Symfony dev server (symfony serve --no-tls-verify). Check the Profiler toolbar (top-right) for SQL queries.
Dependency Injection
Replace all Amp\Sql\Pool instances in your services with the ProfiledPool alias (via services_dev.yaml). Example:
services:
App\Service\QueryService:
arguments:
- '@ScriptFUSION\AmpSqlProfilerBundle\ProfiledPool' # Profiled alias
Query Analysis
/_profiler/[request_id]/sql to inspect individual queries, backtraces, and execution stats.Transaction Handling The profiler groups queries within transactions. Use this to validate:
$pool = $container->get(ProfiledPool::class);
$pool->beginTransaction();
// Queries here will be grouped under the transaction in the profiler.
ProfiledPool alias from services.yaml.ProfiledPool to log additional metadata (e.g., custom tags) via the collect() method:
$pool->collect('custom_tag', 'value');
Circular Dependency
ProfiledPoolFactory fails with circular reference errors.Pool (e.g., Amp\Postgres\PostgresConnectionPool) in services_dev.yaml as shown in the README.Unsupported Features
SAVEPOINT) are unsupported. Restructure logic if needed.Profiler Overhead
# config/packages/dev/amp_sql_profiler.yaml
scriptfusion_amp_sql_profiler:
enabled: false
Missing Queries?
Ensure all Amp\Sql\Pool instances are replaced with ProfiledPool. Use Symfony’s debug:container to verify:
php bin/console debug:container | grep ProfiledPool
Backtrace Clarity
The profiler includes backtraces. For cleaner output, ensure your code uses descriptive method names (e.g., fetchUserOrders() instead of query()).
Custom Data Collectors
Override ScriptFUSION\AmpSqlProfilerBundle\Profiler\Collector\SqlCollector to add custom query metadata:
class CustomSqlCollector extends SqlCollector {
public function collect(QueryEvent $event) {
$event->setData(['custom_field' => 'value']);
parent::collect($event);
}
}
Register it in services_dev.yaml:
ScriptFUSION\AmpSqlProfilerBundle\Profiler\Collector\SqlCollector:
class: App\Profiler\CustomSqlCollector
Query Filtering
Filter queries by type or tags in the profiler view by extending the collector’s getQueries() method.
Non-Dev Environments Use environment variables to toggle profiling dynamically:
# config/packages/amp_sql_profiler.yaml
scriptfusion_amp_sql_profiler:
enabled: '%env(bool:AMP_SQL_PROFILER_ENABLED)%'
How can I help you explore Laravel packages today?