Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/profiling/index.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 // TODO: Move all the DB stuff to profiling_db_xxxx() function in xhprof_moodle.php
00027 
00028 // TODO: it is wrong when core lib references ANY plugin lang strings, maybe more login could be moved here (skodak)
00029 
00030 require_once(dirname(__FILE__) . '/../../../config.php');
00031 require_once($CFG->libdir.'/adminlib.php');
00032 require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
00033 
00034 define('PROFILING_RUNSPERPAGE', 50);
00035 
00036 // page parameters
00037 $script   = optional_param('script', null, PARAM_PATH);
00038 $runid    = optional_param('runid', null, PARAM_ALPHANUM);
00039 $runid2   = optional_param('runid2', null, PARAM_ALPHANUM);
00040 $listurl  = optional_param('listurl', null, PARAM_PATH);
00041 $runreference= optional_param('runreference', 0, PARAM_INT);
00042 $runcomment  = optional_param('runcomment', null, PARAM_TEXT);
00043 
00044 $dbfields = 'runid, url, totalexecutiontime, totalcputime, ' .
00045             'totalcalls, totalmemory, runreference, runcomment, timecreated';
00046 
00047 admin_externalpage_setup('toolprofiling');
00048 
00049 // Always add listurl if available
00050 if ($listurl) {
00051     $listurlnav = new moodle_url('/admin/tool/profiling/index.php', array('listurl' => $listurl));
00052     $PAGE->navbar->add($listurl, $listurlnav);
00053 }
00054 
00055 // Header
00056 echo $OUTPUT->header();
00057 
00058 // We have requested the last available run for one script
00059 if (isset($script)) {
00060     // Get the last available run for the given script
00061     $run = $DB->get_record_sql("SELECT $dbfields
00062                                  FROM {profiling}
00063                                 WHERE url = ?
00064                                   AND id = (SELECT MAX(id)
00065                                               FROM {profiling}
00066                                              WHERE url = ?)",
00067                               array($script, $script), IGNORE_MISSING);
00068 
00069     // No run found for script, warn and exit
00070     if (!$run) {
00071         notice(get_string('cannotfindanyrunforurl', 'tool_profiling', $script), 'index.php');
00072     }
00073 
00074     // Check if there is any previous run marked as reference one
00075     $prevreferences = $DB->get_records_select('profiling',
00076                                               'url = ? AND runreference = 1 AND timecreated < ?',
00077                                               array($run->url, $run->timecreated),
00078                                               'timecreated DESC', 'runid', 0, 1);
00079     $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
00080     echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
00081     $header = get_string('lastrunof', 'tool_profiling', $script);
00082     echo $OUTPUT->heading($header);
00083     $table = profiling_print_run($run, $prevrunid);
00084     echo $table;
00085     echo $OUTPUT->box_end();
00086 
00087 
00088 // We have requested the diff between 2 runs
00089 } else if (isset($runid) && isset($runid2)) {
00090     $run1 = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, MUST_EXIST);
00091     $run2 = $DB->get_record('profiling', array('runid'=>$runid2), $dbfields, MUST_EXIST);
00092     if ($run1->url == $run2->url && $run1->runid != $run2->runid) {
00093         if ($run2->timecreated < $run1->timecreated) {
00094             $runtemp = $run1;
00095             $run1 = $run2;
00096             $run2 = $runtemp;
00097         }
00098         echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
00099         $header = get_string('differencesbetween2runsof', 'tool_profiling', $run1->url);
00100         echo $OUTPUT->heading($header);
00101         $table = profiling_print_rundiff($run1, $run2);
00102         echo $table;
00103         echo $OUTPUT->box_end();
00104     }
00105 
00106 
00107 // We have requested one run, invoke it
00108 } else if (isset($runid)) {
00109     // Check if we are trying to update the runreference/runcomment for the run
00110     if (isset($runcomment) && confirm_sesskey()) {
00111         $id = $DB->get_field('profiling', 'id', array('runid' => $runid), MUST_EXIST);
00112         $rec = new stdClass();
00113         $rec->id = $id;
00114         $rec->runreference = (bool)$runreference;
00115         $rec->runcomment   = $runcomment;
00116         $DB->update_record('profiling', $rec);
00117     }
00118     // Get the requested runid
00119     $run = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, IGNORE_MISSING);
00120 
00121     // No run found for runid, warn and exit
00122     if (!$run) {
00123         notice(get_string('cannotfindanyrunforrunid', 'tool_profiling', $runid), 'index.php');
00124     }
00125 
00126     // Check if there is any previous run marked as reference one
00127     $prevreferences = $DB->get_records_select('profiling',
00128                                               'url = ? AND runreference = 1 AND timecreated < ?',
00129                                               array($run->url, $run->timecreated),
00130                                               'timecreated DESC', 'runid', 0, 1);
00131     $prevrunid = $prevreferences ? reset($prevreferences)->runid : false;
00132     echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
00133     $header = get_string('summaryof', 'tool_profiling', $run->url);
00134     echo $OUTPUT->heading($header);
00135     $table = profiling_print_run($run, $prevrunid);
00136     echo $table;
00137     echo $OUTPUT->box_end();
00138 
00139 
00140 // Default: List one page of runs
00141 } else {
00142 
00143     // The flexitable that will root listings
00144     $table = new xhprof_table_sql('profiling-list-table');
00145     $baseurl = $CFG->wwwroot . '/admin/tool/profiling/index.php';
00146 
00147     // Check if we are listing all or some URL ones
00148     $sqlconditions = '';
00149     $sqlparams = array();
00150     if (!isset($listurl)) {
00151         $header = get_string('pluginname', 'tool_profiling');
00152         $sqlconditions = '1 = 1';
00153         $table->set_listurlmode(false);
00154     } else {
00155         $header =  get_string('profilingrunsfor', 'tool_profiling', $listurl);
00156         $sqlconditions = 'url = :url';
00157         $sqlparams['url'] = $listurl;
00158         $table->set_listurlmode(true);
00159         $baseurl .= '?listurl=' . urlencode($listurl);
00160     }
00161 
00162     echo $OUTPUT->heading($header);
00163 
00164     // TODO: Fix flexitable to validate tsort/thide/tshow/tifirs/tilast/page
00165     // TODO: Fix table_sql to allow it to work without WHERE clause
00166     // add silly condition (1 = 1) because of table_sql bug
00167     $table->set_sql($dbfields, '{profiling}', $sqlconditions, $sqlparams);
00168     $table->set_count_sql("SELECT COUNT(*) FROM {profiling} WHERE $sqlconditions", $sqlparams);
00169     $columns = array(
00170         'url', 'timecreated', 'totalexecutiontime', 'totalcputime',
00171         'totalcalls', 'totalmemory', 'runcomment');
00172     $headers = array(
00173         get_string('url'), get_string('date'), get_string('executiontime', 'tool_profiling'),
00174         get_string('cputime', 'tool_profiling'), get_string('calls', 'tool_profiling'),
00175         get_string('memory', 'tool_profiling'), get_string('comment', 'tool_profiling'));
00176     $table->define_columns($columns);
00177     $table->define_headers($headers);
00178     $table->sortable(true, 'timecreated', SORT_DESC);
00179     $table->define_baseurl($baseurl);
00180     $table->column_suppress('url');
00181     $table->out(PROFILING_RUNSPERPAGE, true);
00182 
00183     // Print the controller block with different options
00184     echo profiling_list_controls($listurl);
00185 }
00186 
00187 // Footer.
00188 echo $OUTPUT->footer();
00189 
 All Data Structures Namespaces Files Functions Variables Enumerations