Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added web profiler data collection for query logging.
To enable, set your `atlas.yaml` config for `atlas.orm.atlas.log_queries` to `true`. Then look in the full-screen profiler for the new Atlas menu tab. Also fixed a configuration bug on `atlas.orm.atlas.transaction_class`.
- Loading branch information
Paul M. Jones
committed
Aug 8, 2018
1 parent
ca085b3
commit 282dad6
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace Atlas\Symfony\DataCollector; | ||
|
||
use Atlas\Orm\Atlas; | ||
use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Exception; | ||
|
||
class AtlasCollector extends DataCollector | ||
{ | ||
protected $atlas; | ||
|
||
public function __construct(Atlas $atlas) | ||
{ | ||
$this->atlas = $atlas; | ||
} | ||
|
||
public function collect( | ||
Request $request, | ||
Response $response, | ||
Exception $exception = null | ||
) { | ||
$this->data = $this->atlas->getQueries(); | ||
} | ||
|
||
public function reset() | ||
{ | ||
$this->data = []; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'atlas.collector'; | ||
} | ||
|
||
public function getQueries() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function getCount() | ||
{ | ||
return count($this->data); | ||
} | ||
|
||
public function getDuration() | ||
{ | ||
return array_reduce($this->data, function ($time, $query) { | ||
return $time + $query['duration']; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% block menu %} | ||
<span class="label"> | ||
<span class="icon"> | ||
<svg | ||
version="1.1" | ||
id="Layer_1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlns:xlink="http://www.w3.org/1999/xlink" | ||
x="0px" | ||
y="0px" | ||
width="24px" | ||
height="24px" | ||
viewBox="0 0 24 24" | ||
enable-background="new 0 0 24 24" | ||
xml:space="preserve"> | ||
<image | ||
id="image0" | ||
width="24" | ||
height="24" | ||
x="0" | ||
y="0" | ||
xlink:href="data:image/png;base64, | ||
iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAAAmJLR0QA/4ePzL8AAAAHdElNRQfi | ||
CAgLHxiw/wouAAABjXpUWHRSYXcgcHJvZmlsZSB0eXBlIGljYwAAOI21U1FuBCEI/fcUPQICgh5n | ||
UCfp/S9Q1HEzu+k27UdfYnYFhMeDCZ+1ho+BxDnAACJLVFCQCjwtIE26smJCVkaElFNJBwJoO919 | ||
+Ol+mp8MQCVIFFJS4JggAVe48Hr/CadXHYziNjTCtpn1ZAa9ZFFrLLWxWWeWbi2appJfk4XfVLzh | ||
EJakJHRxuRhLCt4YKOpSJsqlEJKqKwTbni8Gcag21VrXUrc9iN4dBtshTw8q3xKxD2Axiu0qgOCM | ||
JMtmEs/tqPLmgRd+k+ip5wfMhS1jmlJd/uLjB3qNecJfxf6/RDo6ysqPRExy+pSK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3LbI+2N7VX7oqwdWJXzWxhbH5uY+a50IjqjEP4iiEiEPTp1 | ||
uivOJlMU8qWcX4wajadCsfxn/gT2rF0brV9pXwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOC0wOC0w | ||
OFQxMTozMToyNC0wNzowMHLVNgMAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTgtMDgtMDhUMTE6MzE6 | ||
MjQtMDc6MDADiI6/AAAAKHRFWHRpY2M6Y29weXJpZ2h0AENvcHlyaWdodCBBcHBsZSBJbmMuLCAy | ||
MDE1Uf15/AAAABp0RVh0aWNjOmRlc2NyaXB0aW9uAERpc3BsYXkgUDOPebu8AAAAG3RFWHRpY2M6 | ||
bWFudWZhY3R1cmVyAERpc3BsYXkgUDMy4RxJAAAAFHRFWHRpY2M6bW9kZWwARGlzcGxheSBQM95n | ||
/9EAAAAASUVORK5CYII=" | ||
/> | ||
</svg> | ||
</span> | ||
<strong>Atlas</strong> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block panel %} | ||
|
||
<h2>Atlas</h2> | ||
|
||
<h3>Queries</h3> | ||
|
||
<p>{{ collector.count }} queries, {{ collector.duration|number_format(5) }} seconds. | ||
|
||
<table> | ||
<tr> | ||
<th></th> | ||
<th>Connection</th> | ||
<th>Duration</th> | ||
<th>Statement</th> | ||
<th>Values</th> | ||
</tr> | ||
{% for query in collector.queries %} | ||
<tr> | ||
<td>{{ loop.index }}</td> | ||
<td>{{ query.connection }}</td> | ||
<td>{{ query.duration|number_format(5) }}</td> | ||
<td>{{ query.statement|trim }}<br /> | ||
<a onclick="javascript:document.getElementById('atlas-trace-{{ loop.index }}').style.display='block';">Trace</a> | ||
<pre style="display: none;" id="atlas-trace-{{ loop.index }}">{{ query.trace|trim }}"</pre> | ||
</td> | ||
<td> | ||
<dl> | ||
{% for key, val in query.values %} | ||
<dt>{{ key }} => </dt> | ||
<dd>{{ val }}</dd> | ||
{% else %} | ||
-- | ||
{% endfor %} | ||
</dl> | ||
</td> | ||
</tr> | ||
{% else %} | ||
<tr> | ||
<td colspan="4">No queries.</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
{% endblock %} |