LoginSignup
1
0

More than 5 years have passed since last update.

Symfony2.5未満でもプログレスバーにメモリ使用量出したい

Posted at

前置き

Symfony2.5 だと
Progress Bar (Symfony Console component)
↑こんな感じに、すごくいい感じでメモリを表示することができるけど、それ以下だと出来ないので

やっつけ的に

protected function execute(InputInterface $input, OutputInterface $output)
{
    $tmpProgress = $this->getHelperSet()->get('progress');

    $progress = function () use (&$tmpProgress) {
        $tmpProgress->setFormat(
            ProgressHelper::FORMAT_VERBOSE .
            sprintf(
                ' Memory: %.2f MB / %.2f MB',
                memory_get_usage(true) / 1024 / 1024,
                memory_get_peak_usage(true) / 1024 / 1024
            )
        );

        return $tmpProgress;
    };

    $max = 50;
    $progress()->start($output, $max);

    $i = 0;
    $data = [];
    while ($i++ < $max) {
        $progress()->advance();

        $data = array_merge($data, range(1, $i * 100));
    }

    $progress()->finish();
}

こんな感じで

$ ./app/console test
 50/50 [============================] 100% Elapsed:  1 sec Memory: 53.00 MB / 54.25 MB

やったりすることもあった。でも効率悪そう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0