Task/Reporting/AdvancedStatCounterTask.php
public function execute(ProcessState $state)
    {
        $now = new \DateTime();
        if (!$this->startedAt) {
            $this->startedAt = $now;
        }
        if ($this->preInitCounter < $this->getOption($state, 'skip_first')) {
            $this->preInitCounter++;
            $state->setSkipped(true);

            return;
        }
        if ($this->lastUpdate && 0 === $this->counter % $this->getOption($state, 'show_every')) {
            $diff = $now->diff($this->lastUpdate);
            $fullText = "Last iteration {$diff->format('%H:%I:%S')} ago";
            $items = $this->getOption($state, 'num_items') * $this->counter;
            $seconds = $now->getTimestamp() - $this->startedAt->getTimestamp();
            $rate = 'n/a';
            if ($seconds > 0) {
                $rate = number_format($items / $seconds, 2, ',', ' ');
            }
            $fullText .= " - {$rate} items/s - {$items} items processed";
            $fullText .= " in {$now->diff($this->startedAt)->format('%H:%I:%S')}";

            $this->logger->info($fullText);
        } else {
            $state->setSkipped(true);
        }
        $this->counter++;
        $this->lastUpdate = $now;
    }
public function execute(ProcessState $state)
    {
        $now = new \DateTime();
        if (!$this->startedAt) {
            $this->startedAt = $now;
        }
        if ($this->preInitCounter < $this->getOption($state, 'skip_first')) {
            $this->preInitCounter++;
            $state->setSkipped(true);

            return;
        }
        if ($this->lastUpdate && 0 === $this->counter % $this->getOption($state, 'show_every')) {
            $diff = $now->diff($this->lastUpdate);
            $fullText = "Last iteration {$diff->format('%H:%I:%S')} ago";
            $items = $this->getOption($state, 'num_items') * $this->counter;
            $seconds = $now->getTimestamp() - $this->startedAt->getTimestamp();
            $rate = 'n/a';
            if ($seconds > 0) {
                $rate = number_format($items / $seconds, 2, ',', ' ');
            }
            $fullText .= " - {$rate} items/s - {$items} items processed";
            $fullText .= " in {$now->diff($this->startedAt)->format('%H:%I:%S')}";

            $this->logger->info($fullText);
        } else {
            $state->setSkipped(true);
        }
        $this->counter++;
        $this->lastUpdate = $now;
    }
@param ProcessState $state

@throws \Symfony\Component\OptionsResolver\Exception\ExceptionInterface
@throws \InvalidArgumentException