16 Commits
Author SHA1 Message Date
Andrey Savchenko 59a17105ae Released version 3.2. 2019-01-30 19:06:55 +02:00
Andrey Savchenko e5079ce186 Added error message on unsupported PHP version. 2019-01-30 19:06:40 +02:00
Andrey Savchenko 657fccb2de Deprecated dedicated classes for extension events. 2019-01-30 19:01:15 +02:00
Andrey Savchenko cc8c8a4756 Added Beaver Builder events. 2019-01-30 18:57:49 +02:00
Andrey Savchenko 2700d83208 Fixed tracking of load events when network–activated. 2019-01-29 17:42:10 +02:00
Andrey Savchenko 8be22411f7 Added WooCommerce loop item event. 2019-01-29 16:34:08 +02:00
Andrey Savchenko a678997c44 Fixed handling of reoccurring hook events. 2019-01-29 16:23:49 +02:00
Andrey Savchenko b4c49f3c67 Released version 3.1 2019-01-22 16:39:05 +02:00
Andrey Savchenko 4d93d2542d Corrected class description. 2019-01-22 16:35:15 +02:00
Andrey Savchenko e1176b7f67 Added error message on incomplete install. 2019-01-22 16:34:25 +02:00
Andrey Savchenko 828d70cdd1 Added PHP version and OPcache status information. 2019-01-22 16:27:38 +02:00
Andrey Savchenko 15ff72afb0 Added WooCommerce events.
Fixes #29
2019-01-22 16:14:14 +02:00
Andrey Savchenko ad246ad1bc Fixed headers error from new line in Server Timing.
Fixes #28
2019-01-22 15:12:21 +02:00
Andrey Savchenko c1a389dc17 Fixed fatal error when HTTP request is pre–filtered. 2019-01-09 19:04:15 +02:00
Andrey Savchenko d724958dec Rounded memory value, saw a screenshot with it blowing up (hadn't seen on my systems). 2019-01-02 23:22:31 +02:00
Andrey Savchenko 950031bbaf Dropped Bootstrap bits from ignore to stop production build complaining. 2019-01-01 22:06:43 +02:00
17 changed files with 215 additions and 25 deletions

No files matched your search

+28
View File
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased ## Unreleased
## 3.2 - 2019-01-30
### Added
- Beaver Builder events
- error message on unsupported PHP version
### Fixed
- handling of reoccurring hook events
- tracking of load events when network–activated
### Deprecated
- dedicated classes for extension events.
## 3.1 - 2019-01-22
### Added
- WooCommerce events
- PHP version and OPcache status information
- error message on incomplete install
### Fixed
- headers error from new line in Server Timing
## 3.0.1 - 2019-01-09
### Fixed
- fatal error when HTTP request is pre–filtered
## 3.0 - 2018-12-28 ## 3.0 - 2018-12-28
### Added ### Added
-5
View File
@@ -47,11 +47,6 @@
], ],
"symfony/stopwatch": [ "symfony/stopwatch": [
"Tests" "Tests"
],
"twbs/bootstrap" : [
"docs",
"grunt",
"js/tests"
] ]
} }
} }
+9 -1
View File
@@ -5,7 +5,7 @@ Plugin Name: Laps
Plugin URI: https://github.com/Rarst/laps Plugin URI: https://github.com/Rarst/laps
Description: Light WordPress profiler. Description: Light WordPress profiler.
Author: Andrey “Rarst” Savchenko Author: Andrey “Rarst” Savchenko
Version: 3.0 Version: 3.2
Author URI: https://www.rarst.net/ Author URI: https://www.rarst.net/
Text Domain: laps Text Domain: laps
Domain Path: /lang Domain Path: /lang
@@ -16,6 +16,14 @@ if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
} }
if ( ! class_exists( '\Rarst\Laps\Plugin' ) ) {
trigger_error( 'Laps not fully installed! Please install with Composer or download full release archive.', E_USER_ERROR );
}
if ( PHP_VERSION_ID < 70103 ) {
trigger_error( 'Laps requires PHP version >=7.1.3.', E_USER_ERROR );
}
$laps = new \Rarst\Laps\Plugin(); $laps = new \Rarst\Laps\Plugin();
$laps->run(); $laps->run();
+52
View File
@@ -0,0 +1,52 @@
<?php
declare( strict_types=1 );
namespace Rarst\Laps\Event;
/**
* Events for third party themes and plugins.
*/
class Extension_Events implements Hook_Event_Config_Interface {
/**
* @return array[]
*/
public function get_events(): array {
return $this->beaver_builder();
}
/**
* Beaver Builder events.
*
* @return array
*/
private function beaver_builder(): array {
$plugin = class_exists( 'FLBuilderLoader' ) ? [
[
'Beaver Builder Post Content',
'plugin',
'fl_builder_before_render_content',
'fl_builder_after_render_content',
],
[
'Beaver Builder Module',
'plugin',
'fl_builder_before_render_module',
'fl_builder_after_render_module',
],
] : [];
$theme = class_exists( 'FLTheme' ) ? [
[ 'Beaver Builder Top Bar', 'theme', 'fl_before_top_bar', 'fl_after_top_bar' ],
[ 'Beaver Builder Header', 'theme', 'fl_before_header', 'fl_after_header' ],
[ 'Beaver Builder Page Content', 'theme', 'fl_before_content', 'fl_after_content' ],
[ 'Beaver Builder Post', 'theme', 'fl_before_post', 'fl_after_post' ],
[ 'Beaver Builder Footer Widgets', 'theme', 'fl_before_footer_widgets', 'fl_after_footer_widgets' ],
[ 'Beaver Builder Footer', 'theme', 'fl_before_footer', 'fl_after_footer' ],
] : [];
return array_merge( $plugin, $theme );
}
}
+2
View File
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
* Events for Genesis Framework based themes * Events for Genesis Framework based themes
* *
* @link http://my.studiopress.com/themes/genesis/ * @link http://my.studiopress.com/themes/genesis/
*
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
*/ */
class Genesis_Events implements Hook_Event_Config_Interface { class Genesis_Events implements Hook_Event_Config_Interface {
+2
View File
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
* Events for Hybrid Core based themes * Events for Hybrid Core based themes
* *
* @link http://themehybrid.com/hybrid-core * @link http://themehybrid.com/hybrid-core
*
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
*/ */
class Hybrid_Events implements Hook_Event_Config_Interface { class Hybrid_Events implements Hook_Event_Config_Interface {
+2
View File
@@ -7,6 +7,8 @@ namespace Rarst\Laps\Event;
* Events for Theme Hook Alliance * Events for Theme Hook Alliance
* *
* @link http://zamoose.github.io/themehookalliance/ * @link http://zamoose.github.io/themehookalliance/
*
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
*/ */
class THA_Events implements Hook_Event_Config_Interface { class THA_Events implements Hook_Event_Config_Interface {
+27
View File
@@ -0,0 +1,27 @@
<?php
declare( strict_types=1 );
namespace Rarst\Laps\Event;
/**
* Events for WooCommerce plugin
*
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
*/
class WooCommerce_Events implements Hook_Event_Config_Interface {
/**
* @return array
*/
public function get_events(): array {
return class_exists( 'WooCommerce' ) ? [
[ 'WooCommerce Init', 'plugin', 'before_woocommerce_init', 'woocommerce_init' ],
[ 'WooCommerce Shop Loop', 'plugin', 'woocommerce_before_shop_loop', 'woocommerce_after_shop_loop' ],
[ 'WooCommerce Shop Item', 'plugin', 'woocommerce_before_shop_loop_item', 'woocommerce_after_shop_loop_item' ],
[ 'WooCommerce Single Product', 'plugin', 'woocommerce_before_single_product', 'woocommerce_after_single_product' ],
[ 'WooCommerce Cart', 'plugin', 'woocommerce_before_cart', 'woocommerce_after_cart' ],
[ 'WooCommerce Checkout', 'plugin', 'woocommerce_before_checkout_form', 'woocommerce_after_checkout_form' ],
] : [];
}
}
+2
View File
@@ -5,6 +5,8 @@ namespace Rarst\Laps\Event;
/** /**
* Events for Yoast plugins * Events for Yoast plugins
*
* @deprecated 3.2:4.0 Events going to be moved to Extension_Events class.
*/ */
class Yoast_Events implements Hook_Event_Config_Interface { class Yoast_Events implements Hook_Event_Config_Interface {
+1 -1
View File
@@ -64,7 +64,7 @@ class Server_Timing_Manager {
$header .= sprintf( '%s;dur=%.2f;desc="%s", ', $record->get_category(), $duration, $record->get_name() ); $header .= sprintf( '%s;dur=%.2f;desc="%s", ', $record->get_category(), $duration, $record->get_name() );
} }
header( 'Server-Timing: ' . $header ); header( 'Server-Timing: ' . preg_replace( '/\R/', '', $header ) );
return $input; return $input;
} }
+9 -5
View File
@@ -6,9 +6,11 @@ namespace Rarst\Laps\Provider;
use Pimple\Container; use Pimple\Container;
use Pimple\ServiceProviderInterface; use Pimple\ServiceProviderInterface;
use Rarst\Laps\Event\Core_Events; use Rarst\Laps\Event\Core_Events;
use Rarst\Laps\Event\Extension_Events;
use Rarst\Laps\Event\Genesis_Events; use Rarst\Laps\Event\Genesis_Events;
use Rarst\Laps\Event\Hybrid_Events; use Rarst\Laps\Event\Hybrid_Events;
use Rarst\Laps\Event\THA_Events; use Rarst\Laps\Event\THA_Events;
use Rarst\Laps\Event\WooCommerce_Events;
use Rarst\Laps\Event\Yoast_Events; use Rarst\Laps\Event\Yoast_Events;
/** /**
@@ -23,11 +25,13 @@ class Hook_Event_Provider implements ServiceProviderInterface {
$pimple['hook.events'] = function (): array { $pimple['hook.events'] = function (): array {
return [ return [
'core' => new Core_Events(), 'core' => new Core_Events(),
'genesis' => new Genesis_Events(), 'extension' => new Extension_Events(),
'hybrid' => new Hybrid_Events(), 'genesis' => new Genesis_Events(),
'tha' => new THA_Events(), 'hybrid' => new Hybrid_Events(),
'yoast' => new Yoast_Events(), 'tha' => new THA_Events(),
'woocommerce' => new WooCommerce_Events(),
'yoast' => new Yoast_Events(),
]; ];
}; };
} }
+17 -5
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' );
} }
/** /**
@@ -30,14 +34,22 @@ class Core_Load_Collector implements Record_Collector_Interface {
$request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT ); $request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
$php = 'PHP Load – ' . PHP_VERSION;
if ( function_exists( 'opcache_get_status' ) ) {
$zend_status = opcache_get_status();
$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 Load', $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' ),
]; ];
} }
} }
+44 -1
View File
@@ -26,6 +26,9 @@ class Hook_Collector extends Stopwatch_Collector {
/** @var Hook_Formatter */ /** @var Hook_Formatter */
protected $formatter; protected $formatter;
/** @var array $calls Tracks number of calls for recurrent events. */
private $calls = [];
/** /**
* @param Stopwatch $stopwatch Stopwatch instance. * @param Stopwatch $stopwatch Stopwatch instance.
* @param Hook_Event_Config_Interface[] $event_configs Starts and stops configuration. * @param Hook_Event_Config_Interface[] $event_configs Starts and stops configuration.
@@ -34,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;
@@ -44,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.
* *
@@ -97,6 +113,8 @@ class Hook_Collector extends Stopwatch_Collector {
if ( '' !== $start ) { if ( '' !== $start ) {
add_action( $start, function ( $input = null ) use ( $event, $category, $start, $stop ) { add_action( $start, function ( $input = null ) use ( $event, $category, $start, $stop ) {
$event .= $this->get_count_suffix( $event, true );
if ( 'Sidebar' === $event ) { if ( 'Sidebar' === $event ) {
$event = $input; $event = $input;
} }
@@ -115,6 +133,8 @@ class Hook_Collector extends Stopwatch_Collector {
if ( '' !== $stop ) { if ( '' !== $stop ) {
add_action( $stop, function ( $input = null ) use ( $event ) { add_action( $stop, function ( $input = null ) use ( $event ) {
$event .= $this->get_count_suffix( $event );
if ( 'Sidebar' === $event ) { if ( 'Sidebar' === $event ) {
$event = $input; $event = $input;
} }
@@ -126,6 +146,29 @@ class Hook_Collector extends Stopwatch_Collector {
} }
} }
/**
* Get the suffix to use if event occurs multiple times.
*
* @param string $event Event name.
* @param boolean $increment Flag to increment count.
*
* @return string
*/
private function get_count_suffix( string $event, bool $increment = false ): string {
if ( ! isset( $this->calls[ $event ] ) ) {
$this->calls[ $event ] = 0;
}
if ( $increment ) {
$this->calls[ $event ] ++;
}
$count = (int) $this->calls[ $event ];
return $count > 1 ? " ({$count})" : '';
}
/** /**
* When theme is done possibly add vendor-specific events. * When theme is done possibly add vendor-specific events.
*/ */
+5 -5
View File
@@ -35,16 +35,16 @@ class Http_Collector extends Stopwatch_Collector {
/** /**
* Capture start time of HTTP request * Capture start time of HTTP request
* *
* @param boolean $false Whether to preempt an HTTP request's return value. Default false. * @param false|array|\WP_Error $false Whether to preempt an HTTP request's return value. Default false.
* @param array $args HTTP request arguments. * @param array $args HTTP request arguments.
* @param string $url The request URL. * @param string $url The request URL.
* *
* @return boolean * @return boolean
*/ */
public function pre_http_request( bool $false, array $args, string $url ): bool { public function pre_http_request( $false, array $args, string $url ) {
$this->start( $url, 'http' ); $this->start( $url, 'http' );
$this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5, true ); $this->callers[ $url ] = wp_debug_backtrace_summary( __CLASS__, 5 );
return $false; return $false;
} }
+1 -1
View File
@@ -43,7 +43,7 @@ class Stopwatch_Record implements Record_Interface {
public function get_description(): string { public function get_description(): string {
$duration = round( $this->stopwatch_event->getDuration() ); $duration = round( $this->stopwatch_event->getDuration() );
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024; $memory = round( $this->stopwatch_event->getMemory() / 1024 / 1024, 2 );
$description = '' !== $this->description ? "<hr />{$this->description}" : ''; $description = '' !== $this->description ? "<hr />{$this->description}" : '';
return "{$this->name} – {$duration} ms – {$memory} MB{$description}"; return "{$this->name} – {$duration} ms – {$memory} MB{$description}";
+14
View File
@@ -7,6 +7,7 @@ use Rarst\Laps\Event\Core_Events;
use Rarst\Laps\Event\Genesis_Events; use Rarst\Laps\Event\Genesis_Events;
use Rarst\Laps\Event\Hybrid_Events; use Rarst\Laps\Event\Hybrid_Events;
use Rarst\Laps\Event\THA_Events; use Rarst\Laps\Event\THA_Events;
use Rarst\Laps\Event\WooCommerce_Events;
use Rarst\Laps\Event\Yoast_Events; use Rarst\Laps\Event\Yoast_Events;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
@@ -62,6 +63,19 @@ class EventTest extends LapsTestCase {
$this->assertNotEmpty( $events ); $this->assertNotEmpty( $events );
} }
public function testWooCommerce() {
$woocommerce = new WooCommerce_Events();
$this->assertEmpty( $woocommerce->get_events() );
$this->getMockBuilder( 'WooCommerce' )->allowMockingUnknownTypes()->getMock();
$events = $woocommerce->get_events();
$this->assertInternalType( 'array', $events );
$this->assertNotEmpty( $events );
}
public function testYoast() { public function testYoast() {
$yoast = new Yoast_Events(); $yoast = new Yoast_Events();
-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)' ) );