From b28ff9cb683ff73edbf069cbefe0787c9abdd9bd Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Thu, 13 Mar 2025 12:34:32 +0100 Subject: [PATCH 1/4] Enhancement: profiler tab --- .../DataCollector/TingCacheDataCollector.php | 4 +- .../DataCollector/TingDriverDataCollector.php | 36 +- .../views/Collector/driverCollector.html.twig | 381 +++++++++++++----- .../Resources/views/Collector/prism.css.twig | 135 +------ .../Resources/views/Collector/prism.js.twig | 7 +- 5 files changed, 302 insertions(+), 261 deletions(-) diff --git a/src/TingBundle/DataCollector/TingCacheDataCollector.php b/src/TingBundle/DataCollector/TingCacheDataCollector.php index c78f2f5..4b398b2 100644 --- a/src/TingBundle/DataCollector/TingCacheDataCollector.php +++ b/src/TingBundle/DataCollector/TingCacheDataCollector.php @@ -57,7 +57,7 @@ public function __construct() public function collect(Request $request, Response $response, ?\Throwable $exception = null): void { if ($this->cacheLogger !== null) { - $this->data['cache']['operations'] = $this->cacheLogger->getOperations(); + $this->data['cache']['operations'] = $this->cloneVar($this->cacheLogger->getOperations()); $this->data['cache']['operationsCount'] = count($this->data['cache']['operations']); $this->data['cache']['time'] = $this->cacheLogger->getTotalTime(); $this->data['cache']['hits'] = $this->cacheLogger->getHits(); @@ -68,7 +68,7 @@ public function collect(Request $request, Response $response, ?\Throwable $excep public function lateCollect(): void { if ($this->cacheLogger !== null) { - $this->data['cache']['operations'] = $this->cacheLogger->getOperations(); + $this->data['cache']['operations'] = $this->cloneVar($this->cacheLogger->getOperations()); $this->data['cache']['operationsCount'] = count($this->data['cache']['operations']); $this->data['cache']['time'] = $this->cacheLogger->getTotalTime(); $this->data['cache']['hits'] = $this->cacheLogger->getHits(); diff --git a/src/TingBundle/DataCollector/TingDriverDataCollector.php b/src/TingBundle/DataCollector/TingDriverDataCollector.php index ae4f8f2..3763125 100644 --- a/src/TingBundle/DataCollector/TingDriverDataCollector.php +++ b/src/TingBundle/DataCollector/TingDriverDataCollector.php @@ -57,44 +57,24 @@ public function __construct() public function collect(Request $request, Response $response, ?\Throwable $exception = null): void { if ($this->driverLogger !== null) { - $this->data['driver']['queries'] = $this->driverLogger->getQueries(); - $this->data['driver']['execs'] = $this->driverLogger->getExecs(); + $this->data['driver']['queries'] = $this->cloneVar($this->driverLogger->getQueries()); + $this->data['driver']['execs'] = $this->cloneVar($this->driverLogger->getExecs()); $this->data['driver']['queryCount'] = count($this->data['driver']['queries']); $this->data['driver']['time'] = $this->driverLogger->getTotalTime(); - $this->data['driver']['connections'] = $this->driverLogger->getConnections(); - $this->data['driver']['connectionsHashToName'] = $this->driverLogger->getConnectionsHashToName(); - - // HttpKernel < 3.2 compatibility layer - // For >= 3.2 cloneVar is always present and MUST be used. - if (method_exists($this, 'cloneVar')) { - foreach ($this->data['driver']['queries'] as &$query) { - if (isset($query['params']) === true) { - $query['params'] = $this->cloneVar($query['params']); - } - } - } + $this->data['driver']['connections'] = $this->cloneVar($this->driverLogger->getConnections()); + $this->data['driver']['connectionsHashToName'] = $this->cloneVar($this->driverLogger->getConnectionsHashToName()); } } public function lateCollect(): void { if ($this->driverLogger !== null) { - $this->data['driver']['queries'] = $this->driverLogger->getQueries(); - $this->data['driver']['execs'] = $this->driverLogger->getExecs(); + $this->data['driver']['queries'] = $this->cloneVar($this->driverLogger->getQueries()); + $this->data['driver']['execs'] = $this->cloneVar($this->driverLogger->getExecs()); $this->data['driver']['queryCount'] = count($this->data['driver']['queries']); $this->data['driver']['time'] = $this->driverLogger->getTotalTime(); - $this->data['driver']['connections'] = $this->driverLogger->getConnections(); - $this->data['driver']['connectionsHashToName'] = $this->driverLogger->getConnectionsHashToName(); - - // HttpKernel < 3.2 compatibility layer - // For >= 3.2 cloneVar is always present and MUST be used. - if (method_exists($this, 'cloneVar')) { - foreach ($this->data['driver']['queries'] as &$query) { - if (isset($query['params']) === true) { - $query['params'] = $this->cloneVar($query['params']); - } - } - } + $this->data['driver']['connections'] = $this->cloneVar($this->driverLogger->getConnections()); + $this->data['driver']['connectionsHashToName'] = $this->cloneVar($this->driverLogger->getConnectionsHashToName()); } } diff --git a/src/TingBundle/Resources/views/Collector/driverCollector.html.twig b/src/TingBundle/Resources/views/Collector/driverCollector.html.twig index 0311091..4ad659d 100644 --- a/src/TingBundle/Resources/views/Collector/driverCollector.html.twig +++ b/src/TingBundle/Resources/views/Collector/driverCollector.html.twig @@ -2,132 +2,321 @@ {% block toolbar %} {% set icon %} - Database - {{ collector.querycount }} - {% if collector.querycount > 0 %} - in {{ '%0.2f'|format(collector.time) }} ms - {% endif %} + Database + + {{ collector.querycount }} + + {% if collector.querycount > 0 %} + + + {{ '%0.2f'|format(collector.time) }} ms + + + {% endif %} {% endset %} + {% set text %} -
- DB Queries - {{ collector.querycount }} -
-
- Query time - {{ '%0.2f'|format(collector.time) }} ms -
+
+ Queries + + {{ collector.querycount }} + +
+
+ Execution time + + {{ '%0.2f'|format(collector.time) }} ms + +
{% endset %} {% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} {% block menu %} - - - Ting Queries - - {{ collector.querycount }} - {{ '%0.0f'|format(collector.time) }} ms + + + + + Ting Queries + + {{ collector.querycount }} + {{ '%0.0f'|format(collector.time) }} ms + - {% endblock %} {% block panel %} - {#{% if 'explain' == page %} - {{ render(controller('TingBundle:Profiler:explain', { - 'token': token, - 'panel': 'db', - 'connectionName': app.request.query.get('connection'), - 'query': app.request.query.get('query') - })) }} - {% else %} - {{ block('queries') }} - {% endif %}#} {{ block('queries') }} {% endblock %} {% block queries %} -

Queries

- - {% if collector.queries is empty %} -

- No queries. -

- {% else %} -