Fixed tracking of load events when network–activated.

This commit is contained in:
Andrey Savchenko committed 2019-01-29 17:42:10 +02:00
1 parent 8be22411f7
commit 2700d83208
4 files changed
+24 -6

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- handling of reoccurring hook events - handling of reoccurring hook events
- tracking of load events when network–activated
## 3.1 - 2019-01-22 ## 3.1 - 2019-01-22
+9 -4
View File
@@ -14,11 +14,15 @@ class Core_Load_Collector implements Record_Collector_Interface {
/** @var float $timeload */ /** @var float $timeload */
protected $timeload; protected $timeload;
/** @var bool Flag if Laps is network activated. */
private $network_activated;
/** /**
* Store core load end, plugin load start mark. * Store plugin load start mark.
*/ */
public function __construct() { public function __construct() {
$this->timeload = microtime( true ); $this->timeload = microtime( true );
$this->network_activated = ! did_action( 'muplugins_loaded' );
} }
/** /**
@@ -37,14 +41,15 @@ class Core_Load_Collector implements Record_Collector_Interface {
$php .= empty( $zend_status['opcache_enabled'] ) ? '' : ' – OPcache'; $php .= empty( $zend_status['opcache_enabled'] ) ? '' : ' – OPcache';
} }
$load = $this->network_activated ? 'Core Load' : 'Core & MU Plugins Load';
/** /**
* @var float $request_time * @var float $request_time
* @var float $timestart * @var float $timestart
*/ */
return [ return [
new Record( $php, $request_time, $timestart - $request_time, '', 'php' ), new Record( $php, $request_time, $timestart - $request_time, '', 'php' ),
// TODO This includes network plugins on multisite, need conditional label if Laps is network–activated. new Record( $load, $timestart, $this->timeload - $timestart, '', 'core' ),
new Record( 'Core and MU Plugins Load', $timestart, $this->timeload - $timestart, '', 'core' ),
]; ];
} }
} }
+14 -1
View File
@@ -37,7 +37,12 @@ class Hook_Collector extends Stopwatch_Collector {
parent::__construct( $stopwatch ); parent::__construct( $stopwatch );
$this->start( 'Plugins Load', 'plugin' ); if ( did_action( 'muplugins_loaded' ) ) {
$this->start( 'Plugins Load', 'plugin' );
} else {
$this->start( 'Network & MU Plugins Load', 'plugin' );
add_action( 'muplugins_loaded', [ $this, 'muplugins_loaded' ], PHP_INT_MAX );
}
$this->add_events( $event_configs['core']->get_events() ); $this->add_events( $event_configs['core']->get_events() );
unset( $event_configs['core'] ); unset( $event_configs['core'] );
$this->event_configs = $event_configs; $this->event_configs = $event_configs;
@@ -47,6 +52,14 @@ class Hook_Collector extends Stopwatch_Collector {
$this->formatter = new Hook_Formatter(); $this->formatter = new Hook_Formatter();
} }
/**
* Time the point between network/MU plugins and regular if network activated.
*/
public function muplugins_loaded() {
$this->stop( 'Network & MU Plugins Load' );
$this->start( 'Plugins Load', 'plugin' );
}
/** /**
* Hook events by name and priority from array. * Hook events by name and priority from array.
* *
-1
View File
@@ -18,7 +18,6 @@ class HookTest extends LapsTestCase {
$stopwatch = new Stopwatch(); $stopwatch = new Stopwatch();
$collector = new Hook_Collector( $stopwatch, [ 'core' => new Core_Events() ] ); $collector = new Hook_Collector( $stopwatch, [ 'core' => new Core_Events() ] );
$this->assertTrue( $stopwatch->isStarted( 'Plugins Load' ) );
$this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) ); $this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) );
$this->assertTrue( has_action( 'plugins_loaded', 'function ($input)' ) ); $this->assertTrue( has_action( 'plugins_loaded', 'function ($input)' ) );