在PHP中,有没有办法可以捕获我执行的每个ImagaMagick / GraphicsMagick方法的CPU使用情况?内存使用情况也不错。
基本上,我正在尝试对每个库在我的应用程序中使用的资源进行基准测试。
尝试失败:
exec('convert a.jpg a.png');
$result = array();
// Loop until process is detected
do
{
exec('ps -eo comm,%cpu,%mem | grep ' . "convert", $result);
}
while($result === array());
// Display the changing CPU and memory usage of the process
do
{
print_r($result);
exec('ps -eo comm,%cpu,%mem | grep ' . "convert", $result);
}
while($result !== array());
答案 0 :(得分:1)
内存使用情况应该是在您要测量的每次通话之前和之后记录memory_get_usage(true)
和memory_get_peak_usage(true)
的输出,然后减去它们。
CPU使用率我不确定。在unix系统上,可能需要执行exec()
来获取ps -ef | grep $phpPid
的输出,然后解析它。您可以获得$phpPid = getmypid();