3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Db\Adapter\Profiler
;
12 use Zend\Db\Adapter\StatementContainerInterface
;
13 use Zend\Db\Adapter\Exception
;
15 class Profiler
implements ProfilerInterface
20 protected $profiles = array();
25 protected $currentIndex = 0;
28 * @param string|StatementContainerInterface $target
29 * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
32 public function profilerStart($target)
34 $profileInformation = array(
37 'start' => microtime(true),
41 if ($target instanceof StatementContainerInterface
) {
42 $profileInformation['sql'] = $target->getSql();
43 $profileInformation['parameters'] = clone $target->getParameterContainer();
44 } elseif (is_string($target)) {
45 $profileInformation['sql'] = $target;
47 throw new Exception\
InvalidArgumentException(__FUNCTION__
. ' takes either a StatementContainer or a string');
50 $this->profiles
[$this->currentIndex
] = $profileInformation;
58 public function profilerFinish()
60 if (!isset($this->profiles
[$this->currentIndex
])) {
61 throw new Exception\
RuntimeException('A profile must be started before ' . __FUNCTION__
. ' can be called.');
63 $current = &$this->profiles
[$this->currentIndex
];
64 $current['end'] = microtime(true);
65 $current['elapse'] = $current['end'] - $current['start'];
66 $this->currentIndex++
;
73 public function getLastProfile()
75 return end($this->profiles
);
81 public function getProfiles()
83 return $this->profiles
;