1

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?

yivi
  • 42,438
  • 18
  • 116
  • 138
gherkins
  • 14,603
  • 6
  • 44
  • 70

1 Answers1

1

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
}
gherkins
  • 14,603
  • 6
  • 44
  • 70