0

所以,这是这个 wep 应用程序,它愉快地运行 python 脚本,通过消息排队,带有 Symfony 进程组件:

$stopwatch = new Stopwatch();
$stopwatch->start('cmd');

$process = new Process($somePythonCmd, null, ['PYENV_VERSION' => 'unicornenv']);
$process->start();
$process->wait();

$event = $stopwatch->stop('cmd');
$metrics = [
    'duration' => Helper::formatTime($event->getDuration() / 1000),
    'memory' => Helper::formatMemory($event->getMemory())
];

我认为这衡量了 PHP 进程本身的内存消耗,对吧?

有没有办法测量python脚本的实际内存使用情况?

4

1 回答 1

1

有点解决方法:

...但是您可以在命令前面加上/usr/bin/time
这将为您提供流程 errorOutput 中的指标

$cmd = [
            '/usr/bin/time',
            'python',
            'script',
        ];

$process = new Process($cmd, null, ['PYENV_VERSION' => 'someenv']);
$process->start();
$process->wait();

if ($process->isSuccessful()) {
    $metrics = $process->getErrorOutput();
    //14.60user 0.65system 0:09.54elapsed 159%CPU (0avgtext+0avgdata 1292616maxresident)k 24inputs+72outputs (0major+346624minor)pagefaults 0swaps
}
于 2021-09-15T08:02:11.447 回答