(string)$query, 'time' => $time, ); } /** * * get current sql query count * * @return integer */ public static function getSqlCount() { return self::$_sqlCount; } /** * * will return the memory usage in KB * * @return string */ public static function getMemoryUsage() { self::setMemoryEnd(); return number_format((self::$_memoryEnd - self::$_memoryStart) / 1024, 2); } /** * * will return the loading time in seconds with 3 decimals * * @return string */ public static function getLoadingSpeed() { self::setTimeEnd(); return number_format((self::$_timeEnd - self::$_timeStart), 3); } /** * * will return the sql queries executed * if min time is > 0, return queries with running time that is greater * than the input value * * @param float $minTime * * @return array */ public static function getSqlQueries($minTime = null) { $queries = array(); if ($minTime > 0) { foreach (self::$_sqlQueries as $query) { if ($query['time'] >= $minTime) { $queries[] = $query; } } return $queries; } return self::$_sqlQueries; } /** * * will return the number of sql queries executed * * @return integer */ public static function getCountSqlQueries() { return count(self::$_sqlQueries); } /** * * returns cpu usage * * @return float */ public static function getCpuUsage() { self::setCpuUsageEnd(); $time = (self::$_cpuTimeUsageEnd - self::$_cpuTimeUsageStart) * 1000000; if ($time > 0) { $usec = self::$_cpuUsageEnd - self::$_cpuUsageStart; return sprintf("%01.2f", ($usec / $time) * 100); } return 0; } /** * * sets a loading time variable * * @return integer */ protected static function _getCurrentTime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } /** * * sets a memory load variable * * @return integer */ protected static function _getMemory() { return memory_get_usage(); } /** * * get cpu usage * * @return float|null */ protected static function _getCpuUsage() { if (function_exists('getrusage')) { $data = getrusage(); return $data["ru_utime.tv_sec"] * 1e6 + $data["ru_utime.tv_usec"]; } return 0; } }