diff --git a/CHANGELOG.md b/CHANGELOG.md index 02063b5..e4f7308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - handling of reoccurring hook events +- tracking of load events when network–activated ## 3.1 - 2019-01-22 diff --git a/src/Record/Collector/Core_Load_Collector.php b/src/Record/Collector/Core_Load_Collector.php index bb5886b..2750387 100644 --- a/src/Record/Collector/Core_Load_Collector.php +++ b/src/Record/Collector/Core_Load_Collector.php @@ -14,11 +14,15 @@ class Core_Load_Collector implements Record_Collector_Interface { /** @var float $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() { - $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'; } + $load = $this->network_activated ? 'Core Load' : 'Core & MU Plugins Load'; + /** * @var float $request_time * @var float $timestart */ return [ 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( 'Core and MU Plugins Load', $timestart, $this->timeload - $timestart, '', 'core' ), + new Record( $load, $timestart, $this->timeload - $timestart, '', 'core' ), ]; } } diff --git a/src/Record/Collector/Hook_Collector.php b/src/Record/Collector/Hook_Collector.php index 791b585..4c04ebb 100644 --- a/src/Record/Collector/Hook_Collector.php +++ b/src/Record/Collector/Hook_Collector.php @@ -37,7 +37,12 @@ class Hook_Collector extends Stopwatch_Collector { 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() ); unset( $event_configs['core'] ); $this->event_configs = $event_configs; @@ -47,6 +52,14 @@ class Hook_Collector extends Stopwatch_Collector { $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. * diff --git a/tests/Record/HookTest.php b/tests/Record/HookTest.php index 78f205b..07474f9 100644 --- a/tests/Record/HookTest.php +++ b/tests/Record/HookTest.php @@ -18,7 +18,6 @@ class HookTest extends LapsTestCase { $stopwatch = new Stopwatch(); $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( 'plugins_loaded', 'function ($input)' ) );