Fixed tracking of load events when network–activated.
This commit is contained in:
1 parent
8be22411f7
commit
2700d83208
4 files changed
+22
-4
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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->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' ),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,12 @@ class Hook_Collector extends Stopwatch_Collector {
|
||||
|
||||
parent::__construct( $stopwatch );
|
||||
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -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)' ) );
|
||||
|
||||
Reference in new issue
Block a user