Commit 5da621f1 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #133 in ZP/z-push from...

Merge pull request #133 in ZP/z-push from feature/ZP-781-nicer-format-for-memory-usage-and to develop

* commit '673e1981':
  ZP-781 Use comma as decimal and dot as thousand separators, add 's' as unit for time usage.
  ZP-781 Nicer format for memory usage.

(cherry picked from commit 109eb8f7)

Conflicts:
	src/lib/utils/utils.php
parent ff1ec4cd
......@@ -176,13 +176,16 @@ class ZLog {
static public function WriteEnd() {
if (LOGLEVEL_DEBUG <= LOGLEVEL || (LOGLEVEL_DEBUG <= LOGUSERLEVEL && self::$userLog)) {
if (version_compare(phpversion(), '5.4.0') < 0) {
$time_used = number_format(time() - $_SERVER["REQUEST_TIME"], 4);
$time_used = number_format(time() - $_SERVER["REQUEST_TIME"], 2, ',', '.');
}
else {
$time_used = number_format(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 4);
$time_used = number_format(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 2, ',', '.');
}
$peakUsage = memory_get_peak_usage(false);
$truePeakUsage = memory_get_peak_usage(true);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Memory usage information: %s/%s - Execution time: %s - HTTP responde code: %s", memory_get_peak_usage(false), memory_get_peak_usage(true), $time_used, http_response_code()));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Memory usage information: %s/%s (%s B/%s B) - Execution time: %ss - HTTP responde code: %s",
Utils::FormatBytes($peakUsage), Utils::FormatBytes($truePeakUsage), $peakUsage, $truePeakUsage, $time_used, http_response_code()));
ZLog::Write(LOGLEVEL_DEBUG, "-------- End");
}
}
......@@ -298,4 +301,4 @@ function zarafa_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
error_reporting(E_ALL);
set_error_handler("zarafa_error_handler");
?>
\ No newline at end of file
?>
......@@ -929,6 +929,24 @@ class Utils {
}
return substr($email, 0, $pos);
}
/**
* Format bytes to a more human readable value.
* @param int $bytes
* @param int $precision
*
* @access public
* @return void|string
*/
public static function FormatBytes($bytes, $precision = 2) {
if ($bytes <= 0) return '0 B';
$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB');
$base = log ($bytes, 1024);
$fBase = floor($base);
$pow = pow(1024, $base - $fBase);
return sprintf ("%.{$precision}f %s", $pow, $units[$fBase]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment