Renamed class files for PSR-4.
This commit is contained in:
1 parent
03ff2b61ff
commit
a77dd9e4c8
10 files changed
+701
-700
No files matched your search
+3
-2
@@ -8,7 +8,6 @@
|
|||||||
"authors" : [
|
"authors" : [
|
||||||
{
|
{
|
||||||
"name" : "Andrey Savchenko",
|
"name" : "Andrey Savchenko",
|
||||||
"email" : "contact@rarst.net",
|
|
||||||
"homepage": "http://www.Rarst.net/"
|
"homepage": "http://www.Rarst.net/"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -16,7 +15,9 @@
|
|||||||
"issues": "https://github.com/Rarst/laps/issues"
|
"issues": "https://github.com/Rarst/laps/issues"
|
||||||
},
|
},
|
||||||
"autoload" : {
|
"autoload" : {
|
||||||
"classmap": ["src/"]
|
"psr-4": {
|
||||||
|
"Rarst\\Laps\\" : "src/"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"require" : {
|
"require" : {
|
||||||
"composer/installers": "~1.0",
|
"composer/installers": "~1.0",
|
||||||
|
|||||||
@@ -1,106 +1,106 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main set of events for WordPress core
|
* Main set of events for WordPress core
|
||||||
*/
|
*/
|
||||||
class Core_Events extends Laps_Events {
|
class Core_Events extends Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_events() {
|
public function get_events() {
|
||||||
|
|
||||||
$stops = array();
|
$stops = array();
|
||||||
|
|
||||||
$stops['plugins_loaded'][ - 2 ] = array(
|
$stops['plugins_loaded'][ - 2 ] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Plugins Load',
|
'event' => 'Plugins Load',
|
||||||
'category' => 'plugin',
|
'category' => 'plugin',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['plugins_loaded'][ - 1 ] = array(
|
$stops['plugins_loaded'][ - 1 ] = array(
|
||||||
'event' => 'Plugins Loaded Hook',
|
'event' => 'Plugins Loaded Hook',
|
||||||
'category' => 'plugin',
|
'category' => 'plugin',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['plugins_loaded'][20] = array(
|
$stops['plugins_loaded'][20] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Plugins Loaded Hook',
|
'event' => 'Plugins Loaded Hook',
|
||||||
'category' => 'plugin',
|
'category' => 'plugin',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['setup_theme'][0] = array(
|
$stops['setup_theme'][0] = array(
|
||||||
'event' => 'Themes Load',
|
'event' => 'Themes Load',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['after_setup_theme'][20] = array(
|
$stops['after_setup_theme'][20] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Themes Load',
|
'event' => 'Themes Load',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['init'][- 1] = array(
|
$stops['init'][- 1] = array(
|
||||||
'event' => 'Core Init',
|
'event' => 'Core Init',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['wp_loaded'][20] = array(
|
$stops['wp_loaded'][20] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Core Init',
|
'event' => 'Core Init',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['admin_init'][- 1] = array(
|
$stops['admin_init'][- 1] = array(
|
||||||
'event' => 'Core Admin Init',
|
'event' => 'Core Admin Init',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['admin_init'][ PHP_INT_MAX -1 ] = array(
|
$stops['admin_init'][ PHP_INT_MAX -1 ] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Core Admin Init',
|
'event' => 'Core Admin Init',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['_admin_menu'][- 1] = array(
|
$stops['_admin_menu'][- 1] = array(
|
||||||
'event' => 'Admin Menu',
|
'event' => 'Admin Menu',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
$stops['admin_menu'][ PHP_INT_MAX -1 ] = array(
|
$stops['admin_menu'][ PHP_INT_MAX -1 ] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Admin Menu',
|
'event' => 'Admin Menu',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['admin_bar_menu'][-1] = array(
|
$stops['admin_bar_menu'][-1] = array(
|
||||||
'event' => 'Toolbar',
|
'event' => 'Toolbar',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['loop_start'][10] = array(
|
$stops['loop_start'][10] = array(
|
||||||
'event' => 'Main Loop',
|
'event' => 'Main Loop',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['loop_end'][10] = array(
|
$stops['loop_end'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Main Loop',
|
'event' => 'Main Loop',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['admin_enqueue_scripts'][10] = array(
|
$stops['admin_enqueue_scripts'][10] = array(
|
||||||
'event' => 'Admin Print Scripts',
|
'event' => 'Admin Print Scripts',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
$stops['admin_print_scripts'][10] = array(
|
$stops['admin_print_scripts'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Admin Print Scripts',
|
'event' => 'Admin Print Scripts',
|
||||||
'category' => 'core',
|
'category' => 'core',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $stops;
|
return $stops;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,62 +1,62 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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/
|
||||||
*/
|
*/
|
||||||
class Genesis_Events extends Laps_Events {
|
class Genesis_Events extends Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function is_applicable() {
|
protected function is_applicable() {
|
||||||
|
|
||||||
return function_exists( 'genesis' );
|
return function_exists( 'genesis' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_events() {
|
protected function get_events() {
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
|
|
||||||
$events['genesis_before_header'][10] = array(
|
$events['genesis_before_header'][10] = array(
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['genesis_after_header'][10] = array(
|
$events['genesis_after_header'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['genesis_before_sidebar_widget_area'][10] = array(
|
$events['genesis_before_sidebar_widget_area'][10] = array(
|
||||||
'event' => 'Sidebar',
|
'event' => 'Sidebar',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['genesis_after_sidebar_widget_area'][10] = array(
|
$events['genesis_after_sidebar_widget_area'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Sidebar',
|
'event' => 'Sidebar',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['genesis_before_sidebar_alt_widget_area'][10] = array(
|
$events['genesis_before_sidebar_alt_widget_area'][10] = array(
|
||||||
'event' => 'Sidebar (alternate)',
|
'event' => 'Sidebar (alternate)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['genesis_after_sidebar_alt_widget_area'][10] = array(
|
$events['genesis_after_sidebar_alt_widget_area'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Sidebar (alternate)',
|
'event' => 'Sidebar (alternate)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,59 +1,59 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events for Hybrid Core based themes
|
* Events for Hybrid Core based themes
|
||||||
*
|
*
|
||||||
* @link http://themehybrid.com/hybrid-core
|
* @link http://themehybrid.com/hybrid-core
|
||||||
*/
|
*/
|
||||||
class Hybrid_Events extends Laps_Events {
|
class Hybrid_Events extends Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function is_applicable() {
|
protected function is_applicable() {
|
||||||
|
|
||||||
return defined( 'HYBRID_VERSION' ) && function_exists( 'hybrid_get_prefix' );
|
return defined( 'HYBRID_VERSION' ) && function_exists( 'hybrid_get_prefix' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_events() {
|
protected function get_events() {
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
$prefix = hybrid_get_prefix();
|
$prefix = hybrid_get_prefix();
|
||||||
|
|
||||||
$events["{$prefix}_before_header"][10] = array(
|
$events["{$prefix}_before_header"][10] = array(
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events["{$prefix}_after_header"][10] = array(
|
$events["{$prefix}_after_header"][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$sidebars = get_theme_support( 'hybrid-core-sidebars' );
|
$sidebars = get_theme_support( 'hybrid-core-sidebars' );
|
||||||
|
|
||||||
if ( ! empty( $sidebars[0] ) ) {
|
if ( ! empty( $sidebars[0] ) ) {
|
||||||
foreach ( $sidebars[0] as $sidebar ) {
|
foreach ( $sidebars[0] as $sidebar ) {
|
||||||
|
|
||||||
$events["{$prefix}_before_{$sidebar}"][10] = array(
|
$events["{$prefix}_before_{$sidebar}"][10] = array(
|
||||||
'event' => "Sidebar ({$sidebar})",
|
'event' => "Sidebar ({$sidebar})",
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events["{$prefix}_after_{$sidebar}"][10] = array(
|
$events["{$prefix}_after_{$sidebar}"][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => "Sidebar ({$sidebar})",
|
'event' => "Sidebar ({$sidebar})",
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+318
-318
@@ -1,318 +1,318 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
use Symfony\Component\Stopwatch\Stopwatch;
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main plugin's class.
|
* Main plugin's class.
|
||||||
*/
|
*/
|
||||||
class Laps {
|
class Laps {
|
||||||
|
|
||||||
/** @var Stopwatch $stopwatch */
|
/** @var Stopwatch $stopwatch */
|
||||||
public static $stopwatch;
|
public static $stopwatch;
|
||||||
public static $events = array();
|
public static $events = array();
|
||||||
public static $query_starts = array();
|
public static $query_starts = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks.
|
* Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks.
|
||||||
*/
|
*/
|
||||||
public static function on_load() {
|
public static function on_load() {
|
||||||
|
|
||||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$stopwatch = new Stopwatch();
|
self::$stopwatch = new Stopwatch();
|
||||||
self::$stopwatch->start( 'Plugins Load', 'plugin' );
|
self::$stopwatch->start( 'Plugins Load', 'plugin' );
|
||||||
$events = new Core_Events();
|
$events = new Core_Events();
|
||||||
self::add_events( $events->get() );
|
self::add_events( $events->get() );
|
||||||
|
|
||||||
add_action( 'pre_update_option_active_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) );
|
add_action( 'pre_update_option_active_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) );
|
||||||
add_action( 'pre_update_site_option_active_sitewide_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) );
|
add_action( 'pre_update_site_option_active_sitewide_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) );
|
||||||
add_action( 'pre_http_request', array( __CLASS__, 'pre_http_request' ), 10, 3 );
|
add_action( 'pre_http_request', array( __CLASS__, 'pre_http_request' ), 10, 3 );
|
||||||
add_action( 'http_api_debug', array( __CLASS__, 'http_api_debug' ), 10, 5 );
|
add_action( 'http_api_debug', array( __CLASS__, 'http_api_debug' ), 10, 5 );
|
||||||
add_action( 'after_setup_theme', array( __CLASS__, 'after_setup_theme' ), 15 );
|
add_action( 'after_setup_theme', array( __CLASS__, 'after_setup_theme' ), 15 );
|
||||||
add_action( 'init', array( __CLASS__, 'init' ) );
|
add_action( 'init', array( __CLASS__, 'init' ) );
|
||||||
|
|
||||||
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
|
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
|
||||||
add_filter( 'query', array( __CLASS__, 'query' ), 20 );
|
add_filter( 'query', array( __CLASS__, 'query' ), 20 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook events by name and priority from array.
|
* Hook events by name and priority from array.
|
||||||
*
|
*
|
||||||
* @param array $stops
|
* @param array $stops
|
||||||
*/
|
*/
|
||||||
public static function add_events( $stops ) {
|
public static function add_events( $stops ) {
|
||||||
|
|
||||||
self::$events = array_merge( self::$events, $stops );
|
self::$events = array_merge( self::$events, $stops );
|
||||||
|
|
||||||
foreach ( $stops as $hook_name => $data ) {
|
foreach ( $stops as $hook_name => $data ) {
|
||||||
|
|
||||||
foreach ( array_keys( $data ) as $priority ) {
|
foreach ( array_keys( $data ) as $priority ) {
|
||||||
|
|
||||||
add_action( $hook_name, array( __CLASS__, 'tick' ), $priority );
|
add_action( $hook_name, array( __CLASS__, 'tick' ), $priority );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorder active plugins so Laps is first and starts timing load early.
|
* Reorder active plugins so Laps is first and starts timing load early.
|
||||||
*
|
*
|
||||||
* @param array $plugins
|
* @param array $plugins
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function pre_update_option_active_plugins( $plugins ) {
|
public static function pre_update_option_active_plugins( $plugins ) {
|
||||||
|
|
||||||
$plugin = plugin_basename( dirname( __DIR__ ) . '/laps.php' );
|
$plugin = plugin_basename( dirname( __DIR__ ) . '/laps.php' );
|
||||||
$key = array_search( $plugin, $plugins );
|
$key = array_search( $plugin, $plugins );
|
||||||
|
|
||||||
if ( false !== $key && $key > 0 ) {
|
if ( false !== $key && $key > 0 ) {
|
||||||
|
|
||||||
unset( $plugins[ $key ] );
|
unset( $plugins[ $key ] );
|
||||||
array_unshift( $plugins, $plugin );
|
array_unshift( $plugins, $plugin );
|
||||||
$plugins = array_values( $plugins );
|
$plugins = array_values( $plugins );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $plugins;
|
return $plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark action for the event on Stopwatch.
|
* Mark action for the event on Stopwatch.
|
||||||
*
|
*
|
||||||
* @param mixed $input pass through if added to filter
|
* @param mixed $input pass through if added to filter
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function tick( $input = null ) {
|
public static function tick( $input = null ) {
|
||||||
|
|
||||||
global $wp_filter;
|
global $wp_filter;
|
||||||
|
|
||||||
$filter_name = current_filter();
|
$filter_name = current_filter();
|
||||||
$filter_instance = $wp_filter[ $filter_name ];
|
$filter_instance = $wp_filter[ $filter_name ];
|
||||||
$priority = $filter_instance instanceof \WP_Hook ? $filter_instance->current_priority() : key( $filter_instance );
|
$priority = $filter_instance instanceof \WP_Hook ? $filter_instance->current_priority() : key( $filter_instance );
|
||||||
|
|
||||||
// See https://core.trac.wordpress.org/ticket/41185 on broken priority, but more general sanity check.
|
// See https://core.trac.wordpress.org/ticket/41185 on broken priority, but more general sanity check.
|
||||||
if ( empty( self::$events[ $filter_name ][ $priority ] ) ) {
|
if ( empty( self::$events[ $filter_name ][ $priority ] ) ) {
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = wp_parse_args(
|
$event = wp_parse_args(
|
||||||
self::$events[ $filter_name ][ $priority ],
|
self::$events[ $filter_name ][ $priority ],
|
||||||
array(
|
array(
|
||||||
'action' => 'start',
|
'action' => 'start',
|
||||||
'category' => null,
|
'category' => null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( 'stop' === $event['action'] && ! self::$stopwatch->isStarted( $event['event'] ) ) {
|
if ( 'stop' === $event['action'] && ! self::$stopwatch->isStarted( $event['event'] ) ) {
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$stopwatch->{$event['action']}( $event['event'], $event['category'] );
|
self::$stopwatch->{$event['action']}( $event['event'], $event['category'] );
|
||||||
|
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture SQL queries start times
|
* Capture SQL queries start times
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function query( $query ) {
|
public static function query( $query ) {
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( empty( self::$query_starts ) && ! empty( $wpdb->queries ) ) {
|
if ( empty( self::$query_starts ) && ! empty( $wpdb->queries ) ) {
|
||||||
self::$query_starts[ count( $wpdb->queries ) ] = microtime( true ) * 1000;
|
self::$query_starts[ count( $wpdb->queries ) ] = microtime( true ) * 1000;
|
||||||
} else {
|
} else {
|
||||||
self::$query_starts[] = microtime( true ) * 1000;
|
self::$query_starts[] = microtime( true ) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture start time of HTTP request
|
* Capture start time of HTTP request
|
||||||
*
|
*
|
||||||
* @param boolean $false
|
* @param boolean $false
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function pre_http_request( $false, $args, $url ) {
|
public static function pre_http_request( $false, $args, $url ) {
|
||||||
|
|
||||||
self::$stopwatch->start( $url, 'http' );
|
self::$stopwatch->start( $url, 'http' );
|
||||||
|
|
||||||
return $false;
|
return $false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture end time of HTTP request
|
* Capture end time of HTTP request
|
||||||
*
|
*
|
||||||
* @param array|\WP_Error $response
|
* @param array|\WP_Error $response
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param object $class
|
* @param object $class
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @param string $url
|
* @param string $url
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function http_api_debug( $response, $type, $class, $args, $url ) {
|
public static function http_api_debug( $response, $type, $class, $args, $url ) {
|
||||||
|
|
||||||
self::$stopwatch->stop( $url );
|
self::$stopwatch->stop( $url );
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When theme is done possibly add vendor-specific events.
|
* When theme is done possibly add vendor-specific events.
|
||||||
*/
|
*/
|
||||||
public static function after_setup_theme() {
|
public static function after_setup_theme() {
|
||||||
|
|
||||||
foreach ( array( 'THA', 'Hybrid', 'Genesis', 'Thematic', 'Yoast' ) as $vendor ) {
|
foreach ( array( 'THA', 'Hybrid', 'Genesis', 'Thematic', 'Yoast' ) as $vendor ) {
|
||||||
|
|
||||||
$class = "Rarst\\Laps\\{$vendor}_Events";
|
$class = "Rarst\\Laps\\{$vendor}_Events";
|
||||||
/** @var Laps_Events $events */
|
/** @var Laps_Events $events */
|
||||||
$events = new $class;
|
$events = new $class;
|
||||||
self::add_events( $events->get() );
|
self::add_events( $events->get() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
||||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
||||||
add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 100 );
|
add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 100 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function enqueue_scripts() {
|
public static function enqueue_scripts() {
|
||||||
|
|
||||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||||
wp_register_script( 'laps', plugins_url( "js/laps{$suffix}.js", __DIR__ ), array( 'jquery' ), '3.3.1', true );
|
wp_register_script( 'laps', plugins_url( "js/laps{$suffix}.js", __DIR__ ), array( 'jquery' ), '3.3.1', true );
|
||||||
wp_register_style( 'laps', plugins_url( "css/laps{$suffix}.css", __DIR__ ) );
|
wp_register_style( 'laps', plugins_url( "css/laps{$suffix}.css", __DIR__ ) );
|
||||||
|
|
||||||
if ( is_admin_bar_showing() ) {
|
if ( is_admin_bar_showing() ) {
|
||||||
wp_enqueue_script( 'laps' );
|
wp_enqueue_script( 'laps' );
|
||||||
wp_enqueue_style( 'laps' );
|
wp_enqueue_style( 'laps' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render interface and add to the toolbar.
|
* Render interface and add to the toolbar.
|
||||||
*
|
*
|
||||||
* @param \WP_Admin_Bar $wp_admin_bar
|
* @param \WP_Admin_Bar $wp_admin_bar
|
||||||
*/
|
*/
|
||||||
public static function admin_bar_menu( $wp_admin_bar ) {
|
public static function admin_bar_menu( $wp_admin_bar ) {
|
||||||
|
|
||||||
if ( ! apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) {
|
if ( ! apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $timestart, $wpdb;
|
global $timestart, $wpdb;
|
||||||
|
|
||||||
$mustache = new \Mustache_Engine(
|
$mustache = new \Mustache_Engine(
|
||||||
array(
|
array(
|
||||||
'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __DIR__ ) . '/views' ),
|
'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __DIR__ ) . '/views' ),
|
||||||
'cache' => new Mustache_Cache_FrozenCache( dirname( __DIR__ ) . '/views/cache' ),
|
'cache' => new Mustache_Cache_FrozenCache( dirname( __DIR__ ) . '/views/cache' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( self::$stopwatch->isStarted( 'Toolbar' ) ) {
|
if ( self::$stopwatch->isStarted( 'Toolbar' ) ) {
|
||||||
self::$stopwatch->stop( 'Toolbar' );
|
self::$stopwatch->stop( 'Toolbar' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = self::$stopwatch->getSectionEvents( '__root__' );
|
$events = self::$stopwatch->getSectionEvents( '__root__' );
|
||||||
$start = $timestart * 1000;
|
$start = $timestart * 1000;
|
||||||
$end = microtime( true ) * 1000;
|
$end = microtime( true ) * 1000;
|
||||||
$total = $end - $start;
|
$total = $end - $start;
|
||||||
$event_data = array();
|
$event_data = array();
|
||||||
$http_data = array();
|
$http_data = array();
|
||||||
|
|
||||||
foreach ( $events as $name => $event ) {
|
foreach ( $events as $name => $event ) {
|
||||||
|
|
||||||
$offset = round( ( $event->getOrigin() - $start ) / $total * 100, 2 );
|
$offset = round( ( $event->getOrigin() - $start ) / $total * 100, 2 );
|
||||||
$duration = $event->getDuration();
|
$duration = $event->getDuration();
|
||||||
$width = round( $duration / $total * 100, 2 );
|
$width = round( $duration / $total * 100, 2 );
|
||||||
$category = $event->getCategory();
|
$category = $event->getCategory();
|
||||||
|
|
||||||
if ( 'http' === $category ) {
|
if ( 'http' === $category ) {
|
||||||
$http_data[] = compact( 'name', 'offset', 'duration', 'width', 'category' );
|
$http_data[] = compact( 'name', 'offset', 'duration', 'width', 'category' );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$memory = $event->getMemory() / 1024 / 1024;
|
$memory = $event->getMemory() / 1024 / 1024;
|
||||||
|
|
||||||
$event_data[] = compact( 'name', 'offset', 'duration', 'width', 'category', 'memory' );
|
$event_data[] = compact( 'name', 'offset', 'duration', 'width', 'category', 'memory' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$query_data = array();
|
$query_data = array();
|
||||||
$last_query_end = 0;
|
$last_query_end = 0;
|
||||||
$last_offset = 0;
|
$last_offset = 0;
|
||||||
$last_duration = 0;
|
$last_duration = 0;
|
||||||
|
|
||||||
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
|
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
|
||||||
|
|
||||||
foreach ( $wpdb->queries as $key => $query ) {
|
foreach ( $wpdb->queries as $key => $query ) {
|
||||||
$query_start = isset( self::$query_starts[ $key ] ) ? self::$query_starts[ $key ] : $last_query_end;
|
$query_start = isset( self::$query_starts[ $key ] ) ? self::$query_starts[ $key ] : $last_query_end;
|
||||||
list( $sql, $duration, $trace ) = $query;
|
list( $sql, $duration, $trace ) = $query;
|
||||||
$sql = trim( $sql );
|
$sql = trim( $sql );
|
||||||
$category = 'query-read';
|
$category = 'query-read';
|
||||||
|
|
||||||
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {
|
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {
|
||||||
$category = 'query-write';
|
$category = 'query-write';
|
||||||
}
|
}
|
||||||
|
|
||||||
$duration *= 1000;
|
$duration *= 1000;
|
||||||
$last_query_end = $query_start + $duration;
|
$last_query_end = $query_start + $duration;
|
||||||
$offset = round( ( $query_start - $start ) / $total * 100, 2 );
|
$offset = round( ( $query_start - $start ) / $total * 100, 2 );
|
||||||
|
|
||||||
// if query is indistinguishably close to previous then stack it
|
// if query is indistinguishably close to previous then stack it
|
||||||
if ( $offset === $last_offset ) {
|
if ( $offset === $last_offset ) {
|
||||||
$key = count( $query_data ) - 1;
|
$key = count( $query_data ) - 1;
|
||||||
$query_data[ $key ]['sql'] .= '<br />' . $sql;
|
$query_data[ $key ]['sql'] .= '<br />' . $sql;
|
||||||
|
|
||||||
$last_duration += $duration;
|
$last_duration += $duration;
|
||||||
$width = round( $last_duration / $total * 100, 2 );
|
$width = round( $last_duration / $total * 100, 2 );
|
||||||
$query_data[ $key ]['width'] = $width;
|
$query_data[ $key ]['width'] = $width;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = round( $duration / $total * 100, 2 );
|
$width = round( $duration / $total * 100, 2 );
|
||||||
$last_offset = $offset;
|
$last_offset = $offset;
|
||||||
$last_duration = $duration;
|
$last_duration = $duration;
|
||||||
|
|
||||||
$query_data[] = compact( 'sql', 'duration', 'offset', 'width', 'category' );
|
$query_data[] = compact( 'sql', 'duration', 'offset', 'width', 'category' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$html = $mustache->render(
|
$html = $mustache->render(
|
||||||
'laps',
|
'laps',
|
||||||
array(
|
array(
|
||||||
'events' => $event_data,
|
'events' => $event_data,
|
||||||
'queries' => $query_data,
|
'queries' => $query_data,
|
||||||
'savequeries' => defined( 'SAVEQUERIES' ) && SAVEQUERIES,
|
'savequeries' => defined( 'SAVEQUERIES' ) && SAVEQUERIES,
|
||||||
'http' => $http_data,
|
'http' => $http_data,
|
||||||
'savehttp' => ! empty( $http_data ),
|
'savehttp' => ! empty( $http_data ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$wp_admin_bar->add_node( array(
|
$wp_admin_bar->add_node( array(
|
||||||
'id' => 'laps',
|
'id' => 'laps',
|
||||||
'title' => sprintf( 'Lap: %ss', round( $total / 1000, 3 ) ),
|
'title' => sprintf( 'Lap: %ss', round( $total / 1000, 3 ) ),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$wp_admin_bar->add_node( array(
|
$wp_admin_bar->add_node( array(
|
||||||
'id' => 'laps_output',
|
'id' => 'laps_output',
|
||||||
'parent' => 'laps',
|
'parent' => 'laps',
|
||||||
'meta' => array( 'html' => $html ),
|
'meta' => array( 'html' => $html ),
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for bulk event providers
|
* Base class for bulk event providers
|
||||||
*/
|
*/
|
||||||
abstract class Laps_Events {
|
abstract class Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve array of event data
|
* Retrieve array of event data
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function get() {
|
||||||
|
|
||||||
if ( $this->is_applicable() ) {
|
if ( $this->is_applicable() ) {
|
||||||
return $this->get_events();
|
return $this->get_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is event pack relevant to current runtime
|
* Is event pack relevant to current runtime
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function is_applicable() {
|
protected function is_applicable() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inherit with internal events compiling and return
|
* Inherit with internal events compiling and return
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
abstract protected function get_events();
|
abstract protected function get_events();
|
||||||
}
|
}
|
||||||
File renamed without changes.
@@ -1,51 +1,51 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events for Theme Hook Alliance
|
* Events for Theme Hook Alliance
|
||||||
*
|
*
|
||||||
* @link http://zamoose.github.io/themehookalliance/
|
* @link http://zamoose.github.io/themehookalliance/
|
||||||
*/
|
*/
|
||||||
class THA_Events extends Laps_Events {
|
class THA_Events extends Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function is_applicable() {
|
protected function is_applicable() {
|
||||||
|
|
||||||
return defined( 'THA_HOOKS_VERSION' );
|
return defined( 'THA_HOOKS_VERSION' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_events() {
|
protected function get_events() {
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
|
|
||||||
$events['tha_header_before'][10] = array(
|
$events['tha_header_before'][10] = array(
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['tha_header_after'][10] = array(
|
$events['tha_header_after'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['tha_sidebars_before'][10] = array(
|
$events['tha_sidebars_before'][10] = array(
|
||||||
'event' => 'Sidebars',
|
'event' => 'Sidebars',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['tha_sidebars_after'][10] = array(
|
$events['tha_sidebars_after'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Sidebars',
|
'event' => 'Sidebars',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,62 +1,62 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Rarst\Laps;
|
namespace Rarst\Laps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events for Thematic Framework based themes
|
* Events for Thematic Framework based themes
|
||||||
*
|
*
|
||||||
* @link http://thematictheme.com/
|
* @link http://thematictheme.com/
|
||||||
*/
|
*/
|
||||||
class Thematic_Events extends Laps_Events {
|
class Thematic_Events extends Laps_Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function is_applicable() {
|
protected function is_applicable() {
|
||||||
|
|
||||||
return function_exists( 'thematic_init' );
|
return function_exists( 'thematic_init' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function get_events() {
|
protected function get_events() {
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
|
|
||||||
$events['thematic_aboveheader'][10] = array(
|
$events['thematic_aboveheader'][10] = array(
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['thematic_belowheader'][10] = array(
|
$events['thematic_belowheader'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Header',
|
'event' => 'Header',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['widget_area_primary_aside'][10] = array(
|
$events['widget_area_primary_aside'][10] = array(
|
||||||
'event' => 'Sidebar (primary aside)',
|
'event' => 'Sidebar (primary aside)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['thematic_betweenmainasides'][10] = array(
|
$events['thematic_betweenmainasides'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Sidebar (primary aside)',
|
'event' => 'Sidebar (primary aside)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['widget_area_secondary_aside'][10] = array(
|
$events['widget_area_secondary_aside'][10] = array(
|
||||||
'event' => 'Sidebar (secondary aside)',
|
'event' => 'Sidebar (secondary aside)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
$events['thematic_belowmainasides'][10] = array(
|
$events['thematic_belowmainasides'][10] = array(
|
||||||
'action' => 'stop',
|
'action' => 'stop',
|
||||||
'event' => 'Sidebar (secondary aside)',
|
'event' => 'Sidebar (secondary aside)',
|
||||||
'category' => 'theme',
|
'category' => 'theme',
|
||||||
);
|
);
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
Reference in new issue
Block a user