Added PHP and core load collector.

This commit is contained in:
Andrey Savchenko committed 2018-02-23 15:12:29 +02:00
1 parent e74777c2a9
commit 4238509861
4 files changed
+59 -3

No files matched your search

+2
View File
@@ -5,6 +5,7 @@ namespace Rarst\Laps\Provider;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Rarst\Laps\Plugin;
use Rarst\Laps\Record\Core_Load_Collector;
use Rarst\Laps\Record\Hook_Record_Collector;
use Rarst\Laps\Record\Http_Record_Collector;
use Rarst\Laps\Record\Record_Collector_Interface;
@@ -27,6 +28,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
$pimple['collectors'] = function ( Plugin $laps ) {
return [
'core' => new Core_Load_Collector(),
'hook' => new Hook_Record_Collector( $laps['stopwatch'], $laps['hook.events'] ),
'http' => new Http_Record_Collector( $laps['stopwatch'] ),
'sql' => new Sql_Record_Collector(),
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Rarst\Laps\Record;
/**
* Covers pre–plugin load time from available data.
*/
class Core_Load_Collector implements Record_Collector_Interface {
/** @var float $timeload */
protected $timeload;
/**
* Store core load end, plugin load start mark.
*/
public function __construct() {
$this->timeload = microtime( true );
}
/**
* @return Record_Interface[]
*/
public function get_records() {
global $timestart;
$request_time = $_SERVER['REQUEST_TIME_FLOAT'];
return [
new Record( 'PHP Load', $request_time, $timestart - $request_time, '', 'php' ),
// TODO This includes network plugins on multisite, need conditional label if Laps is network–activated.
new Record( 'Core and MU Plugins Load', $timestart, $this->timeload - $timestart, '', 'core' ),
];
}
}
+1 -3
View File
@@ -24,9 +24,7 @@ class Timeline_Iterator implements \Iterator {
*/
public function __construct( Recursive_Record_Iterator $iterator ) {
global $timestart;
$this->origin = $timestart;
$this->origin = $_SERVER['REQUEST_TIME_FLOAT'];
$this->iterator = $iterator;
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Rarst\Laps\Tests\Record;
use Rarst\Laps\Record\Core_Load_Collector;
use Rarst\Laps\Record\Record_Interface;
use Rarst\Laps\Tests\LapsTestCase;
class CoreTest extends LapsTestCase {
public function testCollector() {
$collector = new Core_Load_Collector();
$records = $collector->get_records();
$this->assertInternalType( 'array', $records );
$this->assertCount( 2, $records );
$this->assertInstanceOf( Record_Interface::class, $records[0] );
}
}