Progress Loggers

Progress loggers show the real-time progress of the test suite.

The progress logger has many methods which are called during the lifetime of the PHPBench run.

Create a new progress-logger class similar to the following:

namespace PhpBench\Examples\Extension\ProgressLogger;

use PhpBench\Benchmark\RunnerConfig;
use PhpBench\Model\Benchmark;
use PhpBench\Model\Iteration;
use PhpBench\Model\Subject;
use PhpBench\Model\Suite;
use PhpBench\Model\Variant;
use PhpBench\Progress\LoggerInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CatLogger implements LoggerInterface
{
    /**
     * @var OutputInterface
     */
    private $output;

    public function __construct(OutputInterface $output)
    {
        $this->output = $output;
    }

    public function startSuite(RunnerConfig $config, Suite $suite)
    {
    }

    public function endSuite(Suite $suite)
    {
    }

    public function benchmarkStart(Benchmark $benchmark)
    {
    }

    public function benchmarkEnd(Benchmark $benchmark)
    {
    }

    public function subjectStart(Subject $subject)
    {
    }

    public function subjectEnd(Subject $subject)
    {
    }

    public function variantStart(Variant $variant)
    {
    }

    public function variantEnd(Variant $variant)
    {
    }

    public function iterationStart(Iteration $iteration)
    {
        $this->output->write('🐈');
    }

    public function iterationEnd(Iteration $iteration)
    {
    }

    public function retryStart(int $rejectionCount)
    {
    }
}

And register with your DI container:

class AcmeExtension implements ExtensionInterface
{
    public function configure(OptionsResolver $resolver): void
    {
    }

    public function load(Container $container): void
    {
        $container->register(CatLogger::class, function (Container $container) {
            return new CatLogger(
                $container->get(ConsoleExtension::SERVICE_OUTPUT_ERR)
            );
        }, [
            RunnerExtension::TAG_PROGRESS_LOGGER => [
                'name' => 'cats',
            ]
        ]);
    }
}

Run it with:

$ phpbench run --progress=cats