--- /dev/null
+<?php
+
+class IPF_ORM_Connection_Profiler implements IPF_ORM_Overloadable, IteratorAggregate, Countable
+{
+ private $listeners = array('query',
+ 'prepare',
+ 'commit',
+ 'rollback',
+ 'connect',
+ 'begintransaction',
+ 'exec',
+ 'execute');
+
+ private $events = array();
+ public function __construct() {
+ }
+
+ public function setFilterQueryType() {
+ }
+
+ public function __call($m, $a)
+ {
+ if ( ! ($a[0] instanceof IPF_ORM_Event)) {
+ throw new IPF_ORM_Exception_Profiler("Couldn't listen event. Event should be an instance of Doctrine_Event.");
+ }
+
+
+ if (substr($m, 0, 3) === 'pre') {
+ // pre-event listener found
+ $a[0]->start();
+
+ if ( ! in_array($a[0], $this->events, true)) {
+ $this->events[] = $a[0];
+ }
+ } else {
+ // after-event listener found
+ $a[0]->end();
+ }
+ /**
+ * If filtering by query type is enabled, only keep the query if
+ * it was one of the allowed types.
+ */
+ /*
+ if ( !is_null($this->filterTypes)) {
+ if ( ! ($a[0]->getQueryType() & $this->_filterTypes)) {
+
+ }
+ }
+ */
+ }
+
+ public function get($key)
+ {
+ if (isset($this->events[$key])) {
+ return $this->events[$key];
+ }
+ return null;
+ }
+
+ public function getAll()
+ {
+ return $this->events;
+ }
+
+ public function getIterator()
+ {
+ return new ArrayIterator($this->events);
+ }
+
+ public function count()
+ {
+ return count($this->events);
+ }
+
+ public function pop()
+ {
+ return array_pop($this->events);
+ }
+
+ public function lastEvent()
+ {
+ if (empty($this->events)) {
+ return false;
+ }
+
+ end($this->events);
+ return current($this->events);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class IPF_Template_Tag_Sql extends IPF_Template_Tag
+{
+ function start()
+ {
+ $profiler = IPF_Project::getInstance()->sqlProfiler;
+ if ($profiler!==null){
+ echo '<div style="padding:10px; margin:10px; background:#eee; border:1px dashed #888;"><h3>Sql Debug</h3><div style="color:#888">set <i>debug</i> to false in settings project for disable sql profiler</div>';
+ $time = 0;
+ foreach ($profiler as $event) {
+ $time += $event->getElapsedSecs();
+ $name = $event->getName();
+ if ($name=='fetch' || $name=='prepare' || $name=='connect')
+ continue;
+ echo "<br>\n<b>" . $name . "</b> " . sprintf("%f", $event->getElapsedSecs()) . "<br>\n";
+ echo $event->getQuery() . "<br>\n";
+ $params = $event->getParams();
+ if( ! empty($params)) {
+ var_dump($params);
+ print "<br>\n";
+ }
+ }
+ echo "<br>\n<b>Total time:</b> " . $time . " (without prepare and fetch event)<br>\n";
+ echo '</div>';
+ }
+ }
+}