2021-05-04 422次浏览

Another Yii3 family package was released. This time it is profiler. The package provides an ability to record performance profiles:

$profiler->begin('test');
//...some code
    $profiler->begin('test');
    //...some code
    $profiler->end('test');
 //...some code
 $profiler->end('test');

$messages = $profiler->getMessages(); 
print_r($messages);

gives you

Array
(
    [0] => Yiisoft\Profiler\Message Object
        (
            [level:Yiisoft\Profiler\Message:private] => application
            [token:Yiisoft\Profiler\Message:private] => test
            [context:Yiisoft\Profiler\Message:private] => Array
                (
                    [token] => test
                    [category] => application
                    [nestedLevel] => 0
                    [time] => 1614703708.4328
                    [beginTime] => 1614703708.4328
                    [beginMemory] => 7696440
                    [endTime] => 1614703708.4331
                    [endMemory] => 7702392
                    [duration] => 0.0003058910369873
                    [memoryDiff] => 5952
                )

        )

)

The data collected could be processed (usually saved) to one or more targets.

As usual, the package is fully covered with tests and types.