From 93ac4b09d9f0b2deec4ea0fa56d8fe4b5bc08437 Mon Sep 17 00:00:00 2001 From: mattpiwik Date: Mon, 8 Dec 2008 14:08:24 +0000 Subject: - cleaning the API/ code - deleting class Api_Apiable concept not used anymore git-svn-id: http://dev.piwik.org/svn/trunk@826 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- core/Timer.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'core/Timer.php') diff --git a/core/Timer.php b/core/Timer.php index 8e71b41ba5..783dcff6ea 100644 --- a/core/Timer.php +++ b/core/Timer.php @@ -15,36 +15,48 @@ */ class Piwik_Timer { - private $m_Start; + private $timerStart; + private $memoryStart; public function __construct() { - $this->m_Start = 0.0; $this->init(); } - private function getMicrotime() - { - list($micro_seconds, $seconds) = explode(" ", microtime()); - return ((float)$micro_seconds + (float)$seconds); - } - public function init() { - $this->m_Start = $this->getMicrotime(); + $this->timerStart = $this->getMicrotime(); + $this->memoryStart = $this->getMemoryUsage(); } public function getTime($decimals = 2) { - return number_format($this->getMicrotime() - $this->m_Start, $decimals, '.', ''); + return number_format($this->getMicrotime() - $this->timerStart, $decimals, '.', ''); } + public function getTimeMs($decimals = 2) { - return number_format(1000*($this->getMicrotime() - $this->m_Start), $decimals, '.', ''); + return number_format(1000*($this->getMicrotime() - $this->timerStart), $decimals, '.', ''); } + public function getMemoryLeak() + { + return "Memory delta: ".Piwik::getPrettySizeFromBytes($this->getMemoryUsage() - $this->memoryStart); + } + public function __toString() { return "Time elapsed: ". $this->getTime() ."s"; } + + private function getMicrotime() + { + list($micro_seconds, $seconds) = explode(" ", microtime()); + return ((float)$micro_seconds + (float)$seconds); + } + + private function getMemoryUsage() + { + return memory_get_usage(); + } } -- cgit v1.2.3