dsc71976 2010-09-11 07:26
浏览 89
已采纳

PHP:获取ImageMagick / GraphicsMagick的CPU使用率

In PHP, is there a way I can capture what the CPU usage is of each ImagaMagick/GraphicsMagick method I execute? Memory usage would be nice, too.

Basically, I'm trying to benchmark how much resources each library uses in my application.

Failed attempt:

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());
  • 写回答

1条回答 默认 最新

  • doume1301 2010-09-11 08:03
    关注

    Memory usage should be a matter of recording the output of memory_get_usage(true) and memory_get_peak_usage(true) before and after each call you want to measure, then subtracting them.

    CPU usage I'm not sure about. On unix systems it could involve doing exec() to get the output of ps -ef | grep $phpPid, then parsing that. You can get $phpPid = getmypid();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探