From 87f9a3b15ed73dc60c854a232086fc484c0b29e5 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 20 Feb 2013 10:07:43 +0800 Subject: [PATCH 1/2] MDL-35716 report_performance: Performance report for moodle site This will report config setting which can affect moodle performance. Few of them are added in this patch: 1. Theme designer mode 2. Cache Javascript 3. Debug message set to developer 4. Backup - Active 5. Stats enabled. --- report/performance/db/access.php | 36 +++ report/performance/index.php | 89 ++++++ .../lang/en/report_performance.php | 50 +++ report/performance/locallib.php | 285 ++++++++++++++++++ report/performance/settings.php | 31 ++ report/performance/version.php | 29 ++ theme/base/style/admin.css | 6 +- 7 files changed, 523 insertions(+), 3 deletions(-) create mode 100644 report/performance/db/access.php create mode 100644 report/performance/index.php create mode 100644 report/performance/lang/en/report_performance.php create mode 100644 report/performance/locallib.php create mode 100644 report/performance/settings.php create mode 100644 report/performance/version.php diff --git a/report/performance/db/access.php b/report/performance/db/access.php new file mode 100644 index 00000000000..db3d034ac78 --- /dev/null +++ b/report/performance/db/access.php @@ -0,0 +1,36 @@ +. + +/** + * Capabilities + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$capabilities = array( + 'report/performance:view' => array( + 'riskbitmask' => RISK_CONFIG, + 'captype' => 'read', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'manager' => CAP_ALLOW + ), + ) +); diff --git a/report/performance/index.php b/report/performance/index.php new file mode 100644 index 00000000000..09551115d24 --- /dev/null +++ b/report/performance/index.php @@ -0,0 +1,89 @@ +. + +/** + * Performance overview report + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('NO_OUTPUT_BUFFERING', true); + +require('../../config.php'); +require_once($CFG->dirroot.'/report/performance/locallib.php'); +require_once($CFG->libdir.'/adminlib.php'); + +require_login(); + +// Show detailed info about one issue only. +$issue = optional_param('issue', '', PARAM_ALPHANUMEXT); + +$reportperformance = new report_performance(); +$issues = $reportperformance->get_issue_list(); + +// Test if issue valid string. +if (array_search($issue, $issues, true) === false) { + $issue = ''; +} + +// Print the header. +admin_externalpage_setup('reportperformance', '', null, '', array('pagelayout'=>'report')); +echo $OUTPUT->header(); + +echo $OUTPUT->heading(get_string('pluginname', 'report_performance')); + +$strissue = get_string('issue', 'report_performance'); +$strvalue = get_string('value', 'report_performance'); +$strcomments = get_string('comments', 'report_performance'); +$stredit = get_string('edit'); + +$table = new html_table(); +$table->head = array($strissue, $strvalue, $strcomments, $stredit); +$table->colclasses = array('mdl-left issue', 'mdl-left value', 'mdl-left comments', 'mdl-left config'); +$table->attributes = array('class' => 'admintable performancereport generaltable'); +$table->id = 'performanceissuereporttable'; +$table->data = array(); + +// Print details of one issue only. +if ($issue and ($issueresult = $reportperformance::$issue())) { + $reportperformance->add_issue_to_table($table, $issueresult, true); + + $PAGE->set_docs_path('report/security/' . $issue); + + echo html_writer::table($table); + + echo $OUTPUT->box($issueresult->details, 'generalbox boxwidthnormal boxaligncenter'); + + echo $OUTPUT->continue_button(new moodle_url('/report/performance/index.php')); +} else { + // Add Performance report description on main list page. + $morehelplink = $OUTPUT->doc_link('report/performance', get_string('morehelp', 'report_performance')); + echo $OUTPUT->box(get_string('performancereportdesc', 'report_performance', $morehelplink), 'generalbox mdl-align'); + + foreach ($issues as $issue) { + $issueresult = $reportperformance::$issue(); + if (!$issueresult) { + // Ignore this test. + continue; + } + $reportperformance->add_issue_to_table($table, $issueresult, false); + } + echo html_writer::table($table); +} + +echo $OUTPUT->footer(); diff --git a/report/performance/lang/en/report_performance.php b/report/performance/lang/en/report_performance.php new file mode 100644 index 00000000000..d460eccc66d --- /dev/null +++ b/report/performance/lang/en/report_performance.php @@ -0,0 +1,50 @@ +. + +/** + * Lang strings + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['check_backup'] = 'Automated backup'; +$string['check_backup_comment_disable'] = 'Performance may be affected during the backup process. If enabled, backups should be scheduled for off-peak times.'; +$string['check_backup_comment_enable'] = 'Performance may be affected during the backup process. Backups should be scheduled for off-peak times.'; +$string['check_backup_details'] = 'Enabling automated backup will automatically create archives of all the courses on the server at the time you specified.

During this process, it will consume more server resources and may affect performance.

'; +$string['check_cachejs_comment_disable'] = 'If enabled, page loading performance is improved.'; +$string['check_cachejs_comment_enable'] = 'If disabled, page might load slow.'; +$string['check_cachejs_details'] = 'Javascript caching and compression greatly improves page loading performance. It is strongly recommended for production sites.'; +$string['check_debugmsg_comment_nodeveloper'] = 'If set to DEVELOPER, performance may be affected slightly.'; +$string['check_debugmsg_comment_developer'] = 'If set other then DEVELOPER, performance may be improved slightly.'; +$string['check_debugmsg_details'] = 'There is rarely any advantage in going to Developer level, unless you are a developer, in which case it is strongly recommended.

Once you have got the error message, and copied and pasted it somewhere. HIGHLY RECOMMENDED to turn Debug back to NONE. Debug messages can give clues to a hacker as to the setup of your site and may affect performance.

'; +$string['check_enablestats_comment_disable'] = 'Performance may be affected by statistics processing. If enabled, statistics settings should be set with caution.'; +$string['check_enablestats_comment_enable'] = 'Performance may be affected by statistics processing. Statistics settings should be set with caution.'; +$string['check_enablestats_details'] = 'Enabling this will process the logs in cronjob and gather some statistics. Depending on the amount of traffic on your site, this can take awhile.

During this process, it will consume more server resources and may affect performance.

'; +$string['check_themedesignermode_comment_enable'] = 'If disabled, images and style sheets are cached, resulting in significant performance improvements.'; +$string['check_themedesignermode_comment_disable'] = 'If enabled, images and style sheets will not be cached, resulting in significant performance degradation.'; +$string['check_themedesignermode_details'] = 'This is often the cause of slow Moodle sites.

On average it might take at least twice the amount of CPU to run a Moodle site with theme designer mode enabled.

'; +$string['comments'] = 'Comments'; +$string['edit'] = 'Edit'; +$string['enabled'] = 'Enabled'; +$string['disabled'] = 'Disabled'; +$string['issue'] = 'Issue'; +$string['morehelp'] = 'more help'; +$string['performance:view'] = 'View performance report'; +$string['performancereportdesc'] = 'This report lists issues which may affect performance of the site {$a}'; +$string['pluginname'] = 'Performance overview'; +$string['value'] = 'Value'; diff --git a/report/performance/locallib.php b/report/performance/locallib.php new file mode 100644 index 00000000000..b14a1275680 --- /dev/null +++ b/report/performance/locallib.php @@ -0,0 +1,285 @@ +. + +/** + * This file contains classes for report_performance + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +/** + * Class defining issue result. + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class report_performance_issue { + /** @var string issue identifier */ + public $issue; + /** @var string issue name */ + public $name; + /** @var string shown as status */ + public $statusstr; + /** @var string string defines issue status */ + public $status; + /** @var string shown as comment */ + public $comment; + /** @var string details aboout issue*/ + public $details; + /** @var string link pointing to configuration */ + public $configlink; +} + +/** + * This contains functions to get list of issues and there results. + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class report_performance { + /** + * This is used when issue is ok and there is no impact on performance. + */ + const REPORT_PERFORMANCE_OK = 'ok'; + + /** + * This is used to notify that issue might impact performance. + */ + const REPORT_PERFORMANCE_WARNING = 'warning'; + + /** + * This is used to notify if issue is serious and will impact performance. + */ + const REPORT_PERFORMANCE_SERIOUS = 'serious'; + + /** + * This is used to notify if issue is critical and will significantly impact performance. + */ + const REPORT_PERFORMANCE_CRITICAL = 'critical'; + + /** + * Return list of performance check function list. + * + * @return array list of performance issues. + */ + public function get_issue_list() { + return array( + 'report_performance_check_themedesignermode', + 'report_performance_check_cachejs', + 'report_performance_check_debugmsg', + 'report_performance_check_automatic_backup', + 'report_performance_check_enablestats' + ); + } + + /** + * Returns document link for performance issue + * + * @param string $issue string describing issue + * @param string $name name of issue + * @return string issue link pointing to docs page. + */ + public function doc_link($issue, $name) { + global $CFG, $OUTPUT; + + if (empty($CFG->docroot)) { + return $name; + } + + return $OUTPUT->doc_link('report/performance/'.$issue, $name); + } + + /** + * Helper function to add issue details to table. + * + * @param html_table $table table in which issue details should be added + * @param report_performance_issues $issueresult issue result to be added + * @param bool $detail true if issue if displayed in detail. + */ + public function add_issue_to_table(&$table, $issueresult, $detailed = false) { + global $OUTPUT; + $statusarr = array(self::REPORT_PERFORMANCE_OK => 'statusok', + self::REPORT_PERFORMANCE_WARNING => 'statuswarning', + self::REPORT_PERFORMANCE_SERIOUS => 'statusserious', + self::REPORT_PERFORMANCE_CRITICAL => 'statuscritical'); + + $row = array(); + if ($detailed) { + $row[0] = $this->doc_link($issueresult->issue, $issueresult->name); + } else { + $url = new moodle_url('/report/performance/index.php', array('issue' => $issueresult->issue)); + $row[0] = html_writer::link($url, $issueresult->name); + } + $row[1] = html_writer::tag('span', $issueresult->statusstr, array('class' => $statusarr[$issueresult->status])); + $row[2] = $issueresult->comment; + if (!empty($issueresult->configlink)) { + $editicon = html_writer::empty_tag('img', array('alt' => $issueresult->issue, 'class' => 'icon', + 'src' => $OUTPUT->pix_url('i/settings'))); + $row[3] = $OUTPUT->action_link($issueresult->configlink, $editicon); + } else { + $row[3] = ''; + } + + $table->data[] = $row; + } + + /** + * Verifies if theme designer mode is enabled. + * + * @return report_performance_issue result of themedesigner issue. + */ + public static function report_performance_check_themedesignermode() { + global $CFG; + $issueresult = new report_performance_issue(); + $issueresult->issue = 'report_performance_check_themedesignermode'; + $issueresult->name = get_string('themedesignermode', 'admin'); + + if (empty($CFG->themedesignermode)) { + $issueresult->statusstr = get_string('disabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_OK; + $issueresult->comment = get_string('check_themedesignermode_comment_disable', 'report_performance'); + } else { + $issueresult->statusstr = get_string('enabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL; + $issueresult->comment = get_string('check_themedesignermode_comment_enable', 'report_performance'); + } + + $issueresult->details = get_string('check_themedesignermode_details', 'report_performance'); + $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'themedesignermode')); + return $issueresult; + } + + /** + * Checks if javascript is cached. + * + * @return report_performance_issue result of cachejs issue. + */ + public static function report_performance_check_cachejs() { + global $CFG; + $issueresult = new report_performance_issue(); + $issueresult->issue = 'report_performance_check_cachejs'; + $issueresult->name = get_string('cachejs', 'admin'); + + if (empty($CFG->cachejs)) { + $issueresult->statusstr = get_string('disabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL; + $issueresult->comment = get_string('check_cachejs_comment_disable', 'report_performance'); + } else { + $issueresult->statusstr = get_string('enabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_OK; + $issueresult->comment = get_string('check_cachejs_comment_enable', 'report_performance'); + } + + $issueresult->details = get_string('check_cachejs_details', 'report_performance'); + $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'cachejs')); + return $issueresult; + } + + /** + * Checks debug config. + * + * @return report_performance_issue result of debugmsg issue. + */ + public static function report_performance_check_debugmsg() { + global $CFG; + $issueresult = new report_performance_issue(); + $issueresult->issue = 'report_performance_check_debugmsg'; + $issueresult->name = get_string('debug', 'admin'); + $debugchoices = array(DEBUG_NONE => 'debugnone', + DEBUG_MINIMAL => 'debugminimal', + DEBUG_NORMAL => 'debugnormal', + DEBUG_ALL => 'debugall', + DEBUG_DEVELOPER => 'debugdeveloper'); + // If debug is not set then consider it as 0. + if (!isset($CFG->themedesignermode)) { + $CFG->debug = DEBUG_NONE; + } + + $issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin'); + if ($CFG->debug != DEBUG_DEVELOPER) { + $issueresult->status = self::REPORT_PERFORMANCE_OK; + $issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance'); + } else { + $issueresult->status = self::REPORT_PERFORMANCE_WARNING; + $issueresult->comment = get_string('check_debugmsg_comment_developer', 'report_performance'); + } + + $issueresult->details = get_string('check_debugmsg_details', 'report_performance'); + + $issueresult->configlink = new moodle_url('/admin/settings.php', array('section' => 'debugging')); + return $issueresult; + } + + /** + * Checks automatic backup config. + * + * @return report_performance_issue result of automatic backup issue. + */ + public static function report_performance_check_automatic_backup() { + global $CFG; + $issueresult = new report_performance_issue(); + $issueresult->issue = 'report_performance_check_automatic_backup'; + $issueresult->name = get_string('check_backup', 'report_performance'); + + if (!empty($CFG->backup_auto_active) && ($CFG->backup_auto_active == 1)) { + $issueresult->statusstr = get_string('autoactiveenabled', 'backup'); + $issueresult->status = self::REPORT_PERFORMANCE_WARNING; + $issueresult->comment = get_string('check_backup_comment_enable', 'report_performance'); + } else { + if (empty($CFG->backup_auto_active)) { + $issueresult->statusstr = get_string('autoactivedisabled', 'backup'); + } else { + $issueresult->statusstr = get_string('autoactivemanual', 'backup'); + } + $issueresult->status = self::REPORT_PERFORMANCE_OK; + $issueresult->comment = get_string('check_backup_comment_disable', 'report_performance'); + } + + $issueresult->details = get_string('check_backup_details', 'report_performance'); + $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'backup_auto_active')); + return $issueresult; + } + + /** + * Checks if stats are enabled. + */ + public static function report_performance_check_enablestats() { + global $CFG; + $issueresult = new report_performance_issue(); + $issueresult->issue = 'report_performance_check_enablestats'; + $issueresult->name = get_string('enablestats', 'admin'); + + if (!empty($CFG->enablestats)) { + $issueresult->statusstr = get_string('enabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_WARNING; + $issueresult->comment = get_string('check_enablestats_comment_enable', 'report_performance'); + } else { + $issueresult->statusstr = get_string('disabled', 'report_performance'); + $issueresult->status = self::REPORT_PERFORMANCE_OK; + $issueresult->comment = get_string('check_enablestats_comment_disable', 'report_performance'); + } + + $issueresult->details = get_string('check_enablestats_details', 'report_performance'); + $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'enablestats')); + return $issueresult; + } +} diff --git a/report/performance/settings.php b/report/performance/settings.php new file mode 100644 index 00000000000..f856e36aff4 --- /dev/null +++ b/report/performance/settings.php @@ -0,0 +1,31 @@ +. + +/** + * Settings and links + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$ADMIN->add('reports', new admin_externalpage('reportperformance', get_string('pluginname', 'report_performance'), + $CFG->wwwroot."/report/performance/index.php", 'report/performance:view')); + +// No report settings. +$settings = null; diff --git a/report/performance/version.php b/report/performance/version.php new file mode 100644 index 00000000000..9486159dc85 --- /dev/null +++ b/report/performance/version.php @@ -0,0 +1,29 @@ +. + +/** + * Version info for report_performance. + * + * @package report_performance + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$plugin->version = 2013021300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2012112900; // Requires this Moodle version. +$plugin->component = 'report_performance'; // Full name of the plugin (used for diagnostics). diff --git a/theme/base/style/admin.css b/theme/base/style/admin.css index e98ce044cc2..bb4e8d4de92 100644 --- a/theme/base/style/admin.css +++ b/theme/base/style/admin.css @@ -78,9 +78,9 @@ #page-admin-course-index.dir-rtl .editcourse td[align="right"] {text-align: left;} #page-admin-report-security-index .timewarninghidden {display:none;} -#page-admin-report-security-index .statuswarning {background-color: #f0e000;} -#page-admin-report-security-index .statusserious {background-color: #f07000;} -#page-admin-report-security-index .statuscritical {background-color: #f00000;} +#page-admin-report-security-index .statuswarning, #page-admin-report-performance-index .statuswarning {background-color: #f0e000;} +#page-admin-report-security-index .statusserious, #page-admin-report-performance-index .statusserious {background-color: #f07000;} +#page-admin-report-security-index .statuscritical, #page-admin-report-performance-index .statuscritical {background-color: #f00000;} #page-admin-report-capability-index .rolecaps th {text-align: left;} #page-admin-report-capability-index #settingsform #capabilitysearch {width: 30em;} From 5c9e8898c0625343eb6772da6f7ea419092c272f Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Mon, 11 Mar 2013 12:55:49 +0800 Subject: [PATCH 2/2] MDL-35716: Added performance to core plugin list --- lib/pluginlib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index fdc95f6b1f1..087b6cb4b6b 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -532,7 +532,7 @@ class plugin_manager { 'report' => array( 'backups', 'completion', 'configlog', 'courseoverview', - 'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', 'security', 'stats' + 'log', 'loglive', 'outline', 'participation', 'progress', 'questioninstances', 'security', 'stats', 'performance' ), 'repository' => array(