10 defined(
'JPATH_PLATFORM') or die;
32 protected $prefix =
'';
38 protected $buffer = null;
44 protected $marks = null;
50 protected $previousTime = 0.0;
56 protected $previousMem = 0.0;
62 protected static $instances = array();
71 public function __construct($prefix =
'')
73 $this->start = microtime(1);
74 $this->prefix = $prefix;
75 $this->marks = array();
76 $this->buffer = array();
89 public static function getInstance($prefix =
'')
91 if (empty(self::$instances[$prefix]))
93 self::$instances[$prefix] =
new JProfiler($prefix);
96 return self::$instances[$prefix];
111 public function mark($label)
113 $current = microtime(1) - $this->start;
114 $currentMem = memory_get_usage() / 1048576;
117 'prefix' => $this->prefix,
118 'time' => ($current > $this->previousTime ?
'+' :
'-') . (($current - $this->previousTime) * 1000),
119 'totalTime' => ($current * 1000),
120 'memory' => ($currentMem > $this->previousMem ?
'+' :
'-') . ($currentMem - $this->previousMem),
121 'totalMemory' => $currentMem,
127 '%s %.3f seconds (%.3f); %0.2f MB (%0.3f) - %s',
129 $m->totalTime / 1000,
135 $this->buffer[] = $mark;
137 $this->previousTime = $current;
138 $this->previousMem = $currentMem;
151 public static function getmicrotime()
153 list ($usec, $sec) = explode(
' ', microtime());
155 return ((
float) $usec + (
float) $sec);
167 public function getMemory()
169 return memory_get_usage();
182 public function getMarks()
197 public function getBuffer()
199 return $this->buffer;