From d0d4cf57864dee7694cd193db4845b0b6eadf749 Mon Sep 17 00:00:00 2001 From: Kelly Karnetsky Date: Thu, 15 Mar 2018 16:26:33 -0600 Subject: [PATCH] Version 0.3.3 --- composer.json | 16 +++ load-wp-performance-profiler.php | 6 +- readme.md | 24 ++++ readme.txt | 13 +- wp-performance-profiler/admin/database.php | 0 wp-performance-profiler/admin/index.php | 10 ++ wp-performance-profiler/admin/maintenance.php | 0 wp-performance-profiler/admin/settings.php | 0 wp-performance-profiler/assets/css/admin.css | 0 wp-performance-profiler/assets/js/admin.js | 0 wp-performance-profiler/classes/helpers.php | 12 -- .../classes/logger-advanced.php | 121 +++++++++--------- .../classes/logger-base.php | 2 +- .../classes/logger-basic.php | 8 +- .../classes/pagination.php | 0 wp-performance-profiler/compatibility.php | 0 wp-performance-profiler/core.php | 111 ++++++++++++++++ wp-performance-profiler/index.php | 4 +- wp-performance-profiler/must-run.php | 0 wp-performance-profiler/upgrade.php | 0 wp-performance-profiler/util.php | 0 .../views/admin/database.php | 0 .../views/admin/detail.php | 0 wp-performance-profiler/views/admin/help.php | 0 .../views/admin/maintenance.php | 0 .../views/admin/plugins.php | 0 .../views/admin/requests.php | 0 .../views/admin/settings.php | 0 .../views/results-advanced.php | 0 .../wp-performance-profiler.php | 12 ++ 30 files changed, 254 insertions(+), 85 deletions(-) create mode 100755 composer.json mode change 100644 => 100755 load-wp-performance-profiler.php create mode 100755 readme.md mode change 100644 => 100755 readme.txt mode change 100644 => 100755 wp-performance-profiler/admin/database.php mode change 100644 => 100755 wp-performance-profiler/admin/index.php mode change 100644 => 100755 wp-performance-profiler/admin/maintenance.php mode change 100644 => 100755 wp-performance-profiler/admin/settings.php mode change 100644 => 100755 wp-performance-profiler/assets/css/admin.css mode change 100644 => 100755 wp-performance-profiler/assets/js/admin.js mode change 100644 => 100755 wp-performance-profiler/classes/helpers.php mode change 100644 => 100755 wp-performance-profiler/classes/logger-advanced.php mode change 100644 => 100755 wp-performance-profiler/classes/logger-base.php mode change 100644 => 100755 wp-performance-profiler/classes/logger-basic.php mode change 100644 => 100755 wp-performance-profiler/classes/pagination.php mode change 100644 => 100755 wp-performance-profiler/compatibility.php create mode 100755 wp-performance-profiler/core.php mode change 100644 => 100755 wp-performance-profiler/index.php mode change 100644 => 100755 wp-performance-profiler/must-run.php mode change 100644 => 100755 wp-performance-profiler/upgrade.php mode change 100644 => 100755 wp-performance-profiler/util.php mode change 100644 => 100755 wp-performance-profiler/views/admin/database.php mode change 100644 => 100755 wp-performance-profiler/views/admin/detail.php mode change 100644 => 100755 wp-performance-profiler/views/admin/help.php mode change 100644 => 100755 wp-performance-profiler/views/admin/maintenance.php mode change 100644 => 100755 wp-performance-profiler/views/admin/plugins.php mode change 100644 => 100755 wp-performance-profiler/views/admin/requests.php mode change 100644 => 100755 wp-performance-profiler/views/admin/settings.php mode change 100644 => 100755 wp-performance-profiler/views/results-advanced.php create mode 100755 wp-performance-profiler/wp-performance-profiler.php diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..74f5a72 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "interconnectit/plugin-icit-profiler", + "type": "wordpress-plugin", + "homepage": "https://github.com/interconnectit/plugin-icit-profiler", + "authors": [ + { + "name": "interconnect/it", + "email": "support@interconnectit.com", + "homepage": "https://interconnectit.com/" + } + ], + "require": { + "php": ">=5.6", + "composer/installers": "~1.0" + } +} diff --git a/load-wp-performance-profiler.php b/load-wp-performance-profiler.php old mode 100644 new mode 100755 index 4f5b92f..1816a00 --- a/load-wp-performance-profiler.php +++ b/load-wp-performance-profiler.php @@ -6,11 +6,11 @@ * Author: Damian Gostomski * Author URI: http://interconnectit.com * Description: Pinpoint slow parts of your site, so that you can make them faster. - * Version: 0.3 + * Version: 0.3.2 * * This file exists to make installing this as a mu-plugin as easy as possible, and also works for regular plugins. */ -! defined( 'ICIT_PERFORMANCE_PROFILER_LOADER_FILE' ) && define( 'ICIT_PERFORMANCE_PROFILER_LOADER_FILE', plugin_basename( __FILE__ ) ); +!defined('ICIT_PERFORMANCE_PROFILER_LOADER_FILE') && define('ICIT_PERFORMANCE_PROFILER_LOADER_FILE', plugin_basename(__FILE__)); -require_once 'wp-performance-profiler/index.php'; +require_once __DIR__ . '/wp-performance-profiler/wp-performance-profiler.php'; diff --git a/readme.md b/readme.md new file mode 100755 index 0000000..e1bf7fd --- /dev/null +++ b/readme.md @@ -0,0 +1,24 @@ +# Icit Profiler + +## Requirements + +Make sure all dependencies have been installed before moving on: + +* [PHP 5.6](http://php.net/manual/en/install.php) +* [Composer](https://getcomposer.org/download/) + +## Install + +Add the following to the projects composer.json file: + +``` json +"repositories": [ + { + "type": "git", + "url": "git@github.com:interconnectit/plugin-icit-profiler.git" + } +], +"require": { + "interconnectit/plugin-icit-profiler": "dev-master" +} +``` diff --git a/readme.txt b/readme.txt old mode 100644 new mode 100755 index 772b6b8..e40549b --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: gostomski, interconnectit Tags: performance, optimisation, profiler, plugins, speed Requires at least: 4.0.1 -Tested up to: 4.9 -Stable tag: 0.4 +Tested up to: 4.3 +Stable tag: 0.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -21,6 +21,9 @@ The WordPress Performance Profiler will monitor the performance of your site and == Installation == +Please note that you will need PHP 5.3 or above to be able to run this plugin +and we recommend you are using production sites on at least PHP 5.5 or above. + To install the WordPress Performance Profiler as a must-use plugin (recommended): 1. If you don't already have have a folder called `mu-plugins` inside your wp-content directory, create it @@ -70,16 +73,12 @@ Yes, although this plugin is primarily meant as a developer tool - so is most be If you are going to run it in a production environment, it's recommended to set the advanced logging level to a very low number, and the basic level to a low-medium number. With a large amount of traffic, this will still capture a lot of data with minimal overhead. If you run it with higher values (especially for the advanced logging), you'll need to periodically purge the database in the maintenance tab. -= Can I manually log requests = += Can I manually log requests? = If you don't want to run the profiler all the time, or only want to log specific requests, you can manually log them by adding `?profiler` to the query string. This will enable the advanced profiler, but if you want just basic logging, add `?profiler=basic`. By using the query string, you will override any default settings. == Changelog == -= 0.4.0 = -* First new version since fork -* Fix for memory usage not displaying correctly in certain cases -* Minor hook tweaks = 0.3.0 = * Added ability to view plugins ordered by average duration, minimum duration, maximum duration and standard deviation diff --git a/wp-performance-profiler/admin/database.php b/wp-performance-profiler/admin/database.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/admin/index.php b/wp-performance-profiler/admin/index.php old mode 100644 new mode 100755 index 5c3cd3a..e181a2f --- a/wp-performance-profiler/admin/index.php +++ b/wp-performance-profiler/admin/index.php @@ -570,6 +570,16 @@ public function admin_notices() { =' ) && version_compare( PHP_VERSION, '7.2.0', '<' ) ) || defined( 'HHVM_VERSION' ) ): ?> +
+

+ Oops! + WP Performance Profiler doesn't work with PHP7.0 or 7.1 or HHVM. +

+
+ prefix . 'profiler_plugins'; - $schema = array( - 'request_id' => '%d', - 'plugin' => '%s', - 'count' => '%d', - 'duration' => '%f', - ); - $data = array(); - - foreach( $this->stats as $plugin ) { - $data[] = array( - 'request_id' => $request_id, - 'plugin' => $plugin['plugin'], - 'count' => $plugin['count'], - 'duration' => $plugin['duration'], + if ( $this->stats ) { + $table = $wpdb->prefix . 'profiler_plugins'; + $schema = array( + 'request_id' => '%d', + 'plugin' => '%s', + 'count' => '%d', + 'duration' => '%f', ); + $data = array(); + foreach ( $this->stats as $plugin ) { + $data[] = array( + 'request_id' => $request_id, + 'plugin' => $plugin['plugin'], + 'count' => $plugin['count'], + 'duration' => $plugin['duration'], + ); + } + if ( $data ) { + $this->bulk_insert( $table, $schema, $data ); + } } - $this->bulk_insert( $table, $schema, $data ); - // We'll also store all the database queries and link them to this request - $table = $wpdb->prefix . 'profiler_queries'; - $schema = array( - 'request_id' => '%d', - 'duration' => '%f', - 'plugin' => '%s', - 'the_query' => '%s', - 'stack' => '%s', - ); - $data = array(); - foreach( $wpdb->queries as $query ) { - $data[] = array( - 'request_id' => $request_id, - 'duration' => $query[1] * 1000, - 'plugin' => $this->get_plugin_from_query( $query[0] ), - 'the_query' => $query[0], - 'stack' => $query[2], + if ( $wpdb->queries ) { + $table = $wpdb->prefix . 'profiler_queries'; + $schema = array( + 'request_id' => '%d', + 'duration' => '%f', + 'plugin' => '%s', + 'the_query' => '%s', + 'stack' => '%s', ); - - $this->time_database += $query[1] * 1000; - } - - $this->bulk_insert( $table, $schema, $data ); - - // Then, we'll store the detailed logs for each function - $table = $wpdb->prefix . 'profiler_functions'; - $schema = array( - 'request_id' => '%d', - 'plugin' => '%s', - 'function' => '%s', - 'count' => '%d', - 'duration' => '%f', - ); - $data = array(); - - foreach( $this->stats as $plugin ) { - foreach( $plugin['functions'] as $function ) { + $data = array(); + foreach ( $wpdb->queries as $query ) { $data[] = array( 'request_id' => $request_id, - 'plugin' => $plugin['plugin'], - 'function' => $function['function'], - 'count' => $function['count'], - 'duration' => $function['duration'], + 'duration' => $query[1] * 1000, + 'plugin' => $this->get_plugin_from_query( $query[0] ), + 'the_query' => $query[0], + 'stack' => $query[2], ); + + $this->time_database += $query[1] * 1000; + } + if ( $data ) { + $this->bulk_insert( $table, $schema, $data ); } } - $this->bulk_insert( $table, $schema, $data ); + // Then, we'll store the detailed logs for each function + if ( $this->stats ) { + $table = $wpdb->prefix . 'profiler_functions'; + $schema = array( + 'request_id' => '%d', + 'plugin' => '%s', + 'function' => '%s', + 'count' => '%d', + 'duration' => '%f', + ); + $data = array(); + foreach ( $this->stats as $plugin ) { + foreach ( $plugin['functions'] as $function ) { + $data[] = array( + 'request_id' => $request_id, + 'plugin' => $plugin['plugin'], + 'function' => $function['function'], + 'count' => $function['count'], + 'duration' => $function['duration'], + ); + } + } + if ( $data ) { + $this->bulk_insert( $table, $schema, $data ); + } + } // Insert the detailed information for this request $table = $wpdb->prefix . 'profiler_details'; diff --git a/wp-performance-profiler/classes/logger-base.php b/wp-performance-profiler/classes/logger-base.php old mode 100644 new mode 100755 index 4f00c99..4bf3cc6 --- a/wp-performance-profiler/classes/logger-base.php +++ b/wp-performance-profiler/classes/logger-base.php @@ -35,9 +35,9 @@ public function save_request() { $data = array( 'timestamp' => time(), 'duration' => $now - $this->start, + 'memory' => memory_get_usage( true ), 'queries' => get_num_queries(), 'request' => $_SERVER['REQUEST_URI'], - 'memory' => Helpers::get_memory_usage(), 'template' => $this->template, 'type' => icit_profiler_current_request_type(), 'payload' => $payload, diff --git a/wp-performance-profiler/classes/logger-basic.php b/wp-performance-profiler/classes/logger-basic.php old mode 100644 new mode 100755 index 8e1bedc..99cb5b4 --- a/wp-performance-profiler/classes/logger-basic.php +++ b/wp-performance-profiler/classes/logger-basic.php @@ -15,14 +15,16 @@ public function __construct() { public function save() { global $wpdb; - + // Save the base request $request_id = $this->save_request(); // We need to save the duration of DB queries as well $database_duration = 0; - foreach( $wpdb->queries as $query ) { - $database_duration += $query[1] * 1000; + if ( $wpdb->queries ) { + foreach ($wpdb->queries as $query) { + $database_duration += $query[1] * 1000; + } } $table = $wpdb->prefix . 'profiler_details'; diff --git a/wp-performance-profiler/classes/pagination.php b/wp-performance-profiler/classes/pagination.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/compatibility.php b/wp-performance-profiler/compatibility.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/core.php b/wp-performance-profiler/core.php new file mode 100755 index 0000000..13bdfaf --- /dev/null +++ b/wp-performance-profiler/core.php @@ -0,0 +1,111 @@ +get_logging_level(); + + // If we're in the admin, do the core setup + // This is on top of optionally logging as well + if( is_admin() ) { + require_once ICIT_PERFORMANCE_PROFILER_DIR . 'admin/index.php'; + require_once ICIT_PERFORMANCE_PROFILER_DIR . 'classes/pagination.php'; + } + + // Create an instance of the logger, which will take over from here + switch( $logging_level ) { + case 'basic': + require_once ICIT_PERFORMANCE_PROFILER_DIR . 'classes/logger-basic.php'; + self::$logger = new Basic_Logger; + break; + case 'advanced': + require_once ICIT_PERFORMANCE_PROFILER_DIR . 'classes/logger-advanced.php'; + self::$logger = new Advanced_Logger; + break; + } + + // Register a callback to save and render the data + if( self::$logger !== null ) { + add_action( 'shutdown', array( self::$logger, 'save' ), 999 ); + } + } + + public function is_active() { + $settings = get_option( 'icit_performance_profiler' ); + + return isset( $settings['active'] ) ? $settings['active'] : true; + } + + public function get_logging_level() { + $settings = get_option( 'icit_performance_profiler' ); + $type = icit_profiler_current_request_type(); + + // Are we forcing logging via the query string? + // This overrides the other settings below + if( isset( $_GET['profiler'] ) ) { + $level = $_GET['profiler']; + + // If we've set the type, it must be part of our whitelist + // Else, we're set it to the default + return in_array( $level, array( 'basic', 'advanced' ) ) ? $level : 'advanced'; + } + + // Are we logging this type of request? + if( ! isset( $settings['request_types'][ $type ] ) ) return 'none'; + + // Do we need either basic or advanced logging + // We'll always check advanced first, as we'd rather that than basic + // As we want the ability to have a decimal percentage + // We get a number between 0 and 10000 and divide by 100 + // This will give us 2 decimal places + $chance = rand( 0, 10000 ) / 100; + if( $chance <= $settings['advanced_frequency'] ) return 'advanced'; + if( $chance <= $settings['basic_frequency'] ) return 'basic'; + + return 'none'; + } +} +Core::instance(); diff --git a/wp-performance-profiler/index.php b/wp-performance-profiler/index.php old mode 100644 new mode 100755 index e412886..22af098 --- a/wp-performance-profiler/index.php +++ b/wp-performance-profiler/index.php @@ -8,7 +8,7 @@ * Author: Damian Gostomski * Author URI: http://interconnectit.com * Description: Pinpoint slow parts of your site, so that you can make them faster. - * Version: 0.4 + * Version: 0.3 */ // Setup helper constants @@ -78,7 +78,7 @@ public function __construct() { // Register a callback to save and render the data if( self::$logger !== null ) { - add_action( 'shutdown', array( self::$logger, 'save' ), 9999 ); + add_action( 'shutdown', array( self::$logger, 'save' ), 999 ); } } diff --git a/wp-performance-profiler/must-run.php b/wp-performance-profiler/must-run.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/upgrade.php b/wp-performance-profiler/upgrade.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/util.php b/wp-performance-profiler/util.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/database.php b/wp-performance-profiler/views/admin/database.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/detail.php b/wp-performance-profiler/views/admin/detail.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/help.php b/wp-performance-profiler/views/admin/help.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/maintenance.php b/wp-performance-profiler/views/admin/maintenance.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/plugins.php b/wp-performance-profiler/views/admin/plugins.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/requests.php b/wp-performance-profiler/views/admin/requests.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/admin/settings.php b/wp-performance-profiler/views/admin/settings.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/views/results-advanced.php b/wp-performance-profiler/views/results-advanced.php old mode 100644 new mode 100755 diff --git a/wp-performance-profiler/wp-performance-profiler.php b/wp-performance-profiler/wp-performance-profiler.php new file mode 100755 index 0000000..c0c5b9d --- /dev/null +++ b/wp-performance-profiler/wp-performance-profiler.php @@ -0,0 +1,12 @@ +=') && require_once(__DIR__ . '/core.php');