CodeIgniter Forums
Profiler Memory Usage is misleading - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Profiler Memory Usage is misleading (/showthread.php?tid=12312)



Profiler Memory Usage is misleading - El Forum - 10-14-2008

[eluser]dmorin[/eluser]
The profiler uses mem_get_usage to report memory usage. This function gets the memory usage at the current moment and since the profiler is included at the end of script execution, the number it provides can be very misleading depending on what has been unset, etc.

Using memory_get_peak_usage gives a more accurate figure especially considering this is the kind of number you need to know when running into out of memory errors. Since this is only available in 5.2 and higher it should be in addition to the current function.

~line 346 in Profiler.php could become

Code:
$output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage)." bytes";
if (function_exists('memory_get_peak_usage')) {
    $output .= " ( " . number_format(memory_get_peak_usage()) . " peak bytes )";
}
$output .= "</div>";