phpsymfonyprofilingsymfony-process

How to get the memory usage of a script that runs via symfony-process?


So, here's this wep-app, happily running python scripts, queued via messages, with the Symfony Process component:

$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())
];

I think this measures the memory consumption of the PHP process itself, right?

Is there a way to measure the actual memory usage of the python script?


Solution

  • somewhat of a workaround:

    ...but you can prefix the command with /usr/bin/time,
    which will give you the metrics in the process 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
    }