You are here

function _perfmon_format_bytes in Performance monitor 7

Same name and namespace in other branches
  1. 8 perfmon.module \_perfmon_format_bytes()

Format bytes.

1 call to _perfmon_format_bytes()
perfmon_get_mysql_performance_variables in ./perfmon.inc
Describes mysql performance variables.

File

./perfmon.inc, line 383
Stand-alone perfmon test system.

Code

function _perfmon_format_bytes($bytes, $precision = 2) {
  $units = array(
    'B',
    'KB',
    'MB',
    'GB',
    'TB',
  );
  $bytes = max($bytes, 0);
  $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  $pow = min($pow, count($units) - 1);
  $bytes /= pow(1024, $pow);
  return round($bytes, $precision) . ' ' . $units[$pow];
}