From 187536f6c4a141b445da56f6971d02b743f6bf60 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 17 Sep 2011 10:04:29 +0200 Subject: [PATCH] MDL-29029 move profiling to admin tools AMOS BEGIN MOV [calls,report_profiling],[calls,tool_profiling] MOV [cannotfindanyrunforurl,report_profiling],[cannotfindanyrunforurl,tool_profiling] MOV [cannotfindanyrunforrunid,report_profiling],[cannotfindanyrunforrunid,tool_profiling] MOV [comment,report_profiling],[comment,tool_profiling] MOV [differencesbetween2runsof,report_profiling],[differencesbetween2runsof,tool_profiling] MOV [executiontime,report_profiling],[executiontime,tool_profiling] MOV [cputime,report_profiling],[cputime,tool_profiling] MOV [lastrunof,report_profiling],[lastrunof,tool_profiling] MOV [markreferencerun,report_profiling],[markreferencerun,tool_profiling] MOV [memory,report_profiling],[memory,tool_profiling] MOV [pluginname,report_profiling],[pluginname,tool_profiling] MOV [profilingfocusscript,report_profiling],[profilingfocusscript,tool_profiling] MOV [profilingruns,report_profiling],[profilingruns,tool_profiling] MOV [profilingrunsfor,report_profiling],[profilingrunsfor,tool_profiling] MOV [referencerun,report_profiling],[referencerun,tool_profiling] MOV [runid,report_profiling],[runid,tool_profiling] MOV [summaryof,report_profiling],[summaryof,tool_profiling] MOV [viewdetails,report_profiling],[viewdetails,tool_profiling] MOV [viewdiff,report_profiling],[viewdiff,tool_profiling] MOV [viewdiffdetails,report_profiling],[viewdiffdetails,tool_profiling] AMOS END --- admin/report/profiling/settings.php | 8 ---- admin/report/profiling/styles.css | 25 ------------ admin/{report => tool}/profiling/index.php | 35 ++++++++-------- .../profiling/lang/en/tool_profiling.php} | 9 +++-- admin/tool/profiling/settings.php | 31 ++++++++++++++ admin/tool/profiling/styles.css | 25 ++++++++++++ admin/tool/profiling/version.php | 30 ++++++++++++++ lib/pluginlib.php | 4 +- lib/xhprof/xhprof_moodle.php | 40 +++++++++---------- 9 files changed, 132 insertions(+), 75 deletions(-) delete mode 100644 admin/report/profiling/settings.php delete mode 100644 admin/report/profiling/styles.css rename admin/{report => tool}/profiling/index.php (84%) rename admin/{report/profiling/lang/en/report_profiling.php => tool/profiling/lang/en/tool_profiling.php} (86%) create mode 100644 admin/tool/profiling/settings.php create mode 100644 admin/tool/profiling/styles.css create mode 100644 admin/tool/profiling/version.php diff --git a/admin/report/profiling/settings.php b/admin/report/profiling/settings.php deleted file mode 100644 index bf2dc5ff2cb..00000000000 --- a/admin/report/profiling/settings.php +++ /dev/null @@ -1,8 +0,0 @@ -profilingenabled) || !empty($CFG->earlyprofilingenabled))) { - $ADMIN->add('development', new admin_externalpage('reportprofiling', get_string('pluginname', 'report_profiling'), "$CFG->wwwroot/$CFG->admin/report/profiling/index.php", 'moodle/site:config')); -} diff --git a/admin/report/profiling/styles.css b/admin/report/profiling/styles.css deleted file mode 100644 index c4c0804e8ad..00000000000 --- a/admin/report/profiling/styles.css +++ /dev/null @@ -1,25 +0,0 @@ -/* report_profiling styles */ - -.path-admin-report-profiling .profilingruntable .label { - font-weight: bold; -} -.path-admin-report-profiling .profiling_worse { - color: red; -} -.path-admin-report-profiling .profiling_better { - color: green; -} -.path-admin-report-profiling .profiling_same { - color: dimgrey; -} -.path-admin-report-profiling .profiling_important, -.path-admin-report-profiling .flexible .referencerun { - font-weight: bold; -} -.path-admin-report-profiling .flexible .r1 .cell { - background-color: whitesmoke; -} -.path-admin-report-profiling .flexible { - margin-left:auto; - margin-right:auto -} diff --git a/admin/report/profiling/index.php b/admin/tool/profiling/index.php similarity index 84% rename from admin/report/profiling/index.php rename to admin/tool/profiling/index.php index efc32fa3290..197a6944ef2 100644 --- a/admin/report/profiling/index.php +++ b/admin/tool/profiling/index.php @@ -1,5 +1,4 @@ . /** - * @package core + * Profiling tool. + * + * @package tool * @subpackage profiling * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -24,7 +25,9 @@ // TODO: Move all the DB stuff to profiling_db_xxxx() function in xhprof_moodle.php -require_once(dirname(__FILE__).'/../../../config.php'); +// TODO: it is wrong when core lib references ANY plugin lang strings, maybe more login could be moved here (skodak) + +require_once(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir . '/xhprof/xhprof_moodle.php'); @@ -41,11 +44,11 @@ $runcomment = optional_param('runcomment', null, PARAM_TEXT); $dbfields = 'runid, url, totalexecutiontime, totalcputime, ' . 'totalcalls, totalmemory, runreference, runcomment, timecreated'; -admin_externalpage_setup('reportprofiling'); +admin_externalpage_setup('toolprofiling'); // Always add listurl if available if ($listurl) { - $listurlnav = new moodle_url('/admin/report/profiling/index.php', array('listurl' => $listurl)); + $listurlnav = new moodle_url('/admin/tool/profiling/index.php', array('listurl' => $listurl)); $PAGE->navbar->add($listurl, $listurlnav); } @@ -65,7 +68,7 @@ if (isset($script)) { // No run found for script, warn and exit if (!$run) { - notice(get_string('cannotfindanyrunforurl', 'report_profiling', $script), 'index.php'); + notice(get_string('cannotfindanyrunforurl', 'tool_profiling', $script), 'index.php'); } // Check if there is any previous run marked as reference one @@ -75,7 +78,7 @@ if (isset($script)) { 'timecreated DESC', 'runid', 0, 1); $prevrunid = $prevreferences ? reset($prevreferences)->runid : false; echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); - $header = get_string('lastrunof', 'report_profiling', $script); + $header = get_string('lastrunof', 'tool_profiling', $script); echo $OUTPUT->heading($header); $table = profiling_print_run($run, $prevrunid); echo $table; @@ -93,7 +96,7 @@ if (isset($script)) { $run2 = $runtemp; } echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); - $header = get_string('differencesbetween2runsof', 'report_profiling', $run1->url); + $header = get_string('differencesbetween2runsof', 'tool_profiling', $run1->url); echo $OUTPUT->heading($header); $table = profiling_print_rundiff($run1, $run2); echo $table; @@ -117,7 +120,7 @@ if (isset($script)) { // No run found for runid, warn and exit if (!$run) { - notice(get_string('cannotfindanyrunforrunid', 'report_profiling', $runid), 'index.php'); + notice(get_string('cannotfindanyrunforrunid', 'tool_profiling', $runid), 'index.php'); } // Check if there is any previous run marked as reference one @@ -127,7 +130,7 @@ if (isset($script)) { 'timecreated DESC', 'runid', 0, 1); $prevrunid = $prevreferences ? reset($prevreferences)->runid : false; echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); - $header = get_string('summaryof', 'report_profiling', $run->url); + $header = get_string('summaryof', 'tool_profiling', $run->url); echo $OUTPUT->heading($header); $table = profiling_print_run($run, $prevrunid); echo $table; @@ -139,17 +142,17 @@ if (isset($script)) { // The flexitable that will root listings $table = new xhprof_table_sql('profiling-list-table'); - $baseurl = $CFG->wwwroot . '/admin/report/profiling/index.php'; + $baseurl = $CFG->wwwroot . '/admin/tool/profiling/index.php'; // Check if we are listing all or some URL ones $sqlconditions = ''; $sqlparams = array(); if (!isset($listurl)) { - $header = get_string('pluginname', 'report_profiling'); + $header = get_string('pluginname', 'tool_profiling'); $sqlconditions = '1 = 1'; $table->set_listurlmode(false); } else { - $header = get_string('profilingrunsfor', 'report_profiling', $listurl); + $header = get_string('profilingrunsfor', 'tool_profiling', $listurl); $sqlconditions = 'url = :url'; $sqlparams['url'] = $listurl; $table->set_listurlmode(true); @@ -167,9 +170,9 @@ if (isset($script)) { 'url', 'timecreated', 'totalexecutiontime', 'totalcputime', 'totalcalls', 'totalmemory', 'runcomment'); $headers = array( - get_string('url'), get_string('date'), get_string('executiontime', 'report_profiling'), - get_string('cputime', 'report_profiling'), get_string('calls', 'report_profiling'), - get_string('memory', 'report_profiling'), get_string('comment', 'report_profiling')); + get_string('url'), get_string('date'), get_string('executiontime', 'tool_profiling'), + get_string('cputime', 'tool_profiling'), get_string('calls', 'tool_profiling'), + get_string('memory', 'tool_profiling'), get_string('comment', 'tool_profiling')); $table->define_columns($columns); $table->define_headers($headers); $table->sortable(true, 'timecreated', SORT_DESC); diff --git a/admin/report/profiling/lang/en/report_profiling.php b/admin/tool/profiling/lang/en/tool_profiling.php similarity index 86% rename from admin/report/profiling/lang/en/report_profiling.php rename to admin/tool/profiling/lang/en/tool_profiling.php index b22196654f6..bdc8dd7bd57 100644 --- a/admin/report/profiling/lang/en/report_profiling.php +++ b/admin/tool/profiling/lang/en/tool_profiling.php @@ -16,11 +16,12 @@ // along with Moodle. If not, see . /** - * Strings for component 'report_profiling', language 'en', branch 'MOODLE_20_STABLE' + * Strings for component 'tool_profiling', language 'en', branch 'MOODLE_22_STABLE' * - * @package report_profiling - * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package tool + * @subpackage profiling + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['calls'] = 'Function calls'; diff --git a/admin/tool/profiling/settings.php b/admin/tool/profiling/settings.php new file mode 100644 index 00000000000..70bd8d7d7f5 --- /dev/null +++ b/admin/tool/profiling/settings.php @@ -0,0 +1,31 @@ +. + +/** + * Profiling tool settings. + * + * @package tool + * @subpackage profiling + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +// profiling tool, added to development +if (extension_loaded('xhprof') && function_exists('xhprof_enable') && (!empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled))) { + $ADMIN->add('development', new admin_externalpage('toolprofiling', get_string('pluginname', 'tool_profiling'), "$CFG->wwwroot/$CFG->admin/tool/profiling/index.php", 'moodle/site:config')); +} diff --git a/admin/tool/profiling/styles.css b/admin/tool/profiling/styles.css new file mode 100644 index 00000000000..03ec2af301b --- /dev/null +++ b/admin/tool/profiling/styles.css @@ -0,0 +1,25 @@ +/* tool_profiling styles */ + +.path-admin-tool-profiling .profilingruntable .label { + font-weight: bold; +} +.path-admin-tool-profiling .profiling_worse { + color: red; +} +.path-admin-tool-profiling .profiling_better { + color: green; +} +.path-admin-tool-profiling .profiling_same { + color: dimgrey; +} +.path-admin-tool-profiling .profiling_important, +.path-admin-tool-profiling .flexible .referencerun { + font-weight: bold; +} +.path-admin-tool-profiling .flexible .r1 .cell { + background-color: whitesmoke; +} +.path-admin-tool-profiling .flexible { + margin-left:auto; + margin-right:auto +} diff --git a/admin/tool/profiling/version.php b/admin/tool/profiling/version.php new file mode 100644 index 00000000000..f27f9d144fc --- /dev/null +++ b/admin/tool/profiling/version.php @@ -0,0 +1,30 @@ +. + +/** + * Version details. + * + * @package tool + * @subpackage profiling + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +$plugin->version = 2011091700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2011091600; // Requires this Moodle version +$plugin->component = 'tool_profiling'; // Full name of the plugin (used for diagnostics) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 829cc8f2831..f85317442f4 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -343,7 +343,7 @@ class plugin_manager { 'report' => array( 'backups', 'configlog', 'courseoverview', - 'customlang', 'log', 'profiling', 'questioninstances', + 'customlang', 'log', 'questioninstances', 'security', 'spamcleaner', 'stats', 'unittest' ), @@ -367,7 +367,7 @@ class plugin_manager { ), 'tool' => array( - 'capability', 'unsuproles' + 'capability', 'profiling', 'unsuproles' ), 'webservice' => array( diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index 28c41f30065..a53fd61f54c 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -280,23 +280,23 @@ function profiling_print_run($run, $prevrunid = null) { $table->attributes['class'] = 'profilingruntable'; $table->colclasses = array('label', 'value'); $table->data = array( - array(get_string('runid', 'report_profiling'), $run->runid), + array(get_string('runid', 'tool_profiling'), $run->runid), array(get_string('url'), $run->url), array(get_string('date'), userdate($run->timecreated, '%d %B %Y, %H:%M')), - array(get_string('executiontime', 'report_profiling'), format_float($run->totalexecutiontime / 1000, 3) . ' ms'), - array(get_string('cputime', 'report_profiling'), format_float($run->totalcputime / 1000, 3) . ' ms'), - array(get_string('calls', 'report_profiling'), $run->totalcalls), - array(get_string('memory', 'report_profiling'), format_float($run->totalmemory / 1024, 0) . ' KB'), - array(get_string('markreferencerun', 'report_profiling'), $referenceform)); + array(get_string('executiontime', 'tool_profiling'), format_float($run->totalexecutiontime / 1000, 3) . ' ms'), + array(get_string('cputime', 'tool_profiling'), format_float($run->totalcputime / 1000, 3) . ' ms'), + array(get_string('calls', 'tool_profiling'), $run->totalcalls), + array(get_string('memory', 'tool_profiling'), format_float($run->totalmemory / 1024, 0) . ' KB'), + array(get_string('markreferencerun', 'tool_profiling'), $referenceform)); $output = $OUTPUT->box(html_writer::table($table), 'generalbox boxwidthwide boxaligncenter profilingrunbox', 'profiling_summary', true); // Add link to details - $strviewdetails = get_string('viewdetails', 'report_profiling'); + $strviewdetails = get_string('viewdetails', 'tool_profiling'); $url = profiling_urls('run', $run->runid); $output.=$OUTPUT->heading('' . $strviewdetails . '', 3, 'main profilinglink'); // If there is one previous run marked as reference, add link to diff if ($prevrunid) { - $strviewdiff = get_string('viewdiff', 'report_profiling'); + $strviewdiff = get_string('viewdiff', 'tool_profiling'); $url = 'index.php?runid=' . $run->runid . '&runid2=' . $prevrunid . '&listurl=' . urlencode($run->url); $output.=$OUTPUT->heading('' . $strviewdiff . '', 3, 'main profilinglink'); } @@ -327,28 +327,28 @@ function profiling_print_rundiff($run1, $run2) { $table->attributes['class'] = 'profilingruntable'; $table->colclasses = array('label', 'value1', 'value2'); $table->data = array( - array(get_string('runid', 'report_profiling'), + array(get_string('runid', 'tool_profiling'), '' . $run1->runid . '', '' . $run2->runid . ''), array(get_string('url'), $run1->url, $run2->url), array(get_string('date'), userdate($run1->timecreated, '%d %B %Y, %H:%M'), userdate($run2->timecreated, '%d %B %Y, %H:%M')), - array(get_string('executiontime', 'report_profiling'), + array(get_string('executiontime', 'tool_profiling'), format_float($run1->totalexecutiontime / 1000, 3) . ' ms', format_float($run2->totalexecutiontime / 1000, 3) . ' ms ' . $diffexecutiontime), - array(get_string('cputime', 'report_profiling'), + array(get_string('cputime', 'tool_profiling'), format_float($run1->totalcputime / 1000, 3) . ' ms', format_float($run2->totalcputime / 1000, 3) . ' ms ' . $diffcputime), - array(get_string('calls', 'report_profiling'), $run1->totalcalls, $run2->totalcalls . ' ' . $diffcalls), - array(get_string('memory', 'report_profiling'), + array(get_string('calls', 'tool_profiling'), $run1->totalcalls, $run2->totalcalls . ' ' . $diffcalls), + array(get_string('memory', 'tool_profiling'), format_float($run1->totalmemory / 1024, 0) . ' KB', format_float($run2->totalmemory / 1024, 0) . ' KB ' . $diffmemory), - array(get_string('referencerun', 'report_profiling'), $referencetext1, $referencetext2)); + array(get_string('referencerun', 'tool_profiling'), $referencetext1, $referencetext2)); $output = $OUTPUT->box(html_writer::table($table), 'generalbox boxwidthwide boxaligncenter profilingrunbox', 'profiling_summary', true); // Add link to details - $strviewdetails = get_string('viewdiffdetails', 'report_profiling'); + $strviewdetails = get_string('viewdiffdetails', 'tool_profiling'); $url = profiling_urls('diff', $run1->runid, $run2->runid); - //$url = $CFG->wwwroot . '/admin/report/profiling/index.php?run=' . $run->runid; + //$url = $CFG->wwwroot . '/admin/tool/profiling/index.php?run=' . $run->runid; $output.=$OUTPUT->heading('' . $strviewdetails . '', 3, 'main profilinglink'); return $output; @@ -535,7 +535,7 @@ class xhprof_table_sql extends table_sql { global $OUTPUT; // Build the link to latest run for the script - $scripturl = new moodle_url('/admin/report/profiling/index.php', array('script' => $row->url, 'listurl' => $row->url)); + $scripturl = new moodle_url('/admin/tool/profiling/index.php', array('script' => $row->url, 'listurl' => $row->url)); $scriptaction = $OUTPUT->action_link($scripturl, $row->url); // Decide, based on $this->listurlmode which actions to show @@ -543,8 +543,8 @@ class xhprof_table_sql extends table_sql { $detailsaction = ''; } else { // Build link icon to script details (pix + url + actionlink) - $detailsimg = $OUTPUT->pix_icon('t/right', get_string('profilingfocusscript', 'report_profiling', $row->url)); - $detailsurl = new moodle_url('/admin/report/profiling/index.php', array('listurl' => $row->url)); + $detailsimg = $OUTPUT->pix_icon('t/right', get_string('profilingfocusscript', 'tool_profiling', $row->url)); + $detailsurl = new moodle_url('/admin/tool/profiling/index.php', array('listurl' => $row->url)); $detailsaction = $OUTPUT->action_link($detailsurl, $detailsimg); } @@ -557,7 +557,7 @@ class xhprof_table_sql extends table_sql { protected function col_timecreated($row) { global $OUTPUT; $fdate = userdate($row->timecreated, '%d %b %Y, %H:%M'); - $url = new moodle_url('/admin/report/profiling/index.php', array('runid' => $row->runid, 'listurl' => $row->url)); + $url = new moodle_url('/admin/tool/profiling/index.php', array('runid' => $row->runid, 'listurl' => $row->url)); return $OUTPUT->action_link($url, $fdate); } -- 2.39.2