Example #1
0
 /**
  * Prints current memory usage
  */
 function dm()
 {
     $used_mem = memory_get_peak_usage(false);
     echo 'Memory: using ' . round($used_mem / 1024 / 1024, 1) . 'M';
     $memory_limit = ini_get('memory_limit');
     if ($memory_limit == '-1') {
         echo ' (no limit)' . PHP_EOL;
     } else {
         $limit = datasize_to_bytes($memory_limit);
         $pct = round($used_mem / $limit * 100, 1);
         $limit_s = round($limit / 1024 / 1024, 1);
         echo ' (' . $pct . '% of ' . $limit_s . 'M)' . PHP_EOL;
     }
 }
Example #2
0
/**
 * Debug function. Returns memory usage
 */
function dm()
{
    $used_mem = memory_get_peak_usage(false);
    $res = 'Memory: using ' . round(ConvertDatasize::convert('byte', 'MiB', $used_mem), 1) . ' MiB';
    $memory_limit = ini_get('memory_limit');
    if ($memory_limit != '-1') {
        // "-1" means "no memory limit"
        $limit = datasize_to_bytes($memory_limit);
        $pct = round($used_mem / $limit * 100, 1);
        $limit_s = round(ConvertDatasize::convert('byte', 'MiB', $limit), 1);
        $res .= ' (' . $pct . '% of ' . $limit_s . ' MiB)' . ln();
    } else {
        $res .= ' (no limit)' . ln();
    }
    if (extension_loaded('apc')) {
        $info = apc_cache_info('', true);
        $res .= 'APC: using ' . round(ConvertDatasize::convert('byte', 'MiB', $info['mem_size']), 2) . ' MiB' . ', ' . $info['num_hits'] . ' hits, ' . $info['num_misses'] . ' misses, ' . $info['num_entries'] . ' entries (max ' . $info['num_slots'] . ')' . ln();
    }
    return $res;
}