From 82111631032df718ae359446b2e385677e9cc922 Mon Sep 17 00:00:00 2001 From: avl Date: Fri, 29 Aug 2008 04:42:47 +0200 Subject: [PATCH] SQL Profiler --- ipf/orm/connection/profiler.php | 89 +++++++++++++++++++++++++++++++++ ipf/orm/exception/profiler.php | 3 ++ ipf/template/tag/sql.php | 28 +++++++++++ 3 files changed, 120 insertions(+) create mode 100644 ipf/orm/connection/profiler.php create mode 100644 ipf/orm/exception/profiler.php create mode 100644 ipf/template/tag/sql.php diff --git a/ipf/orm/connection/profiler.php b/ipf/orm/connection/profiler.php new file mode 100644 index 0000000..3c0a340 --- /dev/null +++ b/ipf/orm/connection/profiler.php @@ -0,0 +1,89 @@ +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 diff --git a/ipf/orm/exception/profiler.php b/ipf/orm/exception/profiler.php new file mode 100644 index 0000000..5fa9ad5 --- /dev/null +++ b/ipf/orm/exception/profiler.php @@ -0,0 +1,3 @@ +sqlProfiler; + if ($profiler!==null){ + echo '

Sql Debug

set debug to false in settings project for disable sql profiler
'; + $time = 0; + foreach ($profiler as $event) { + $time += $event->getElapsedSecs(); + $name = $event->getName(); + if ($name=='fetch' || $name=='prepare' || $name=='connect') + continue; + echo "
\n" . $name . " " . sprintf("%f", $event->getElapsedSecs()) . "
\n"; + echo $event->getQuery() . "
\n"; + $params = $event->getParams(); + if( ! empty($params)) { + var_dump($params); + print "
\n"; + } + } + echo "
\nTotal time: " . $time . " (without prepare and fetch event)
\n"; + echo '
'; + } + } +} -- 2.49.0