mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Merge branch 'MDL-39733' of git://github.com/stronk7/moodle
This commit is contained in:
commit
93b2977d9d
@ -65,6 +65,10 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
60 => new lang_string('numminutes', '', 60),
|
||||
30 => new lang_string('numminutes', '', 30),
|
||||
15 => new lang_string('numminutes', '', 15))));
|
||||
// Define the prefix to be added to imported profiling runs.
|
||||
$temp->add(new admin_setting_configtext('profilingimportprefix',
|
||||
new lang_string('profilingimportprefix', 'admin'),
|
||||
new lang_string('profilingimportprefix_desc', 'admin'), '(I)', PARAM_TAG, 10));
|
||||
|
||||
// Add the 'profiling' page to admin block
|
||||
$ADMIN->add('development', $temp);
|
||||
|
56
admin/tool/profiling/export.php
Normal file
56
admin/tool/profiling/export.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Profiling tool export utility.
|
||||
*
|
||||
* @package tool_profiling
|
||||
* @copyright 2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
|
||||
// Page parameters.
|
||||
$runid = required_param('runid', PARAM_ALPHANUM);
|
||||
$listurl = required_param('listurl', PARAM_PATH);
|
||||
|
||||
admin_externalpage_setup('toolprofiling');
|
||||
|
||||
$PAGE->navbar->add(get_string('export', 'tool_profiling'));
|
||||
|
||||
// Calculate export variables.
|
||||
$tempdir = 'profiling';
|
||||
make_temp_directory($tempdir);
|
||||
$runids = array($runid);
|
||||
$filename = $runid . '.mpr';
|
||||
$filepath = $CFG->tempdir . '/' . $tempdir . '/' . $filename;
|
||||
|
||||
// Generate the mpr file and send it.
|
||||
if (profiling_export_runs($runids, $filepath)) {
|
||||
send_file($filepath, $filename, 0, 0, false, false, '', true);
|
||||
unlink($filepath); // Delete once sent.
|
||||
die;
|
||||
}
|
||||
|
||||
// Something wrong happened, notice it and done.
|
||||
$urlparams = array(
|
||||
'runid' => $runid,
|
||||
'listurl' => $listurl);
|
||||
$url = new moodle_url('/admin/tool/profiling/index.php', $urlparams);
|
||||
notice(get_string('exportproblem', 'tool_profiling', $urlparams), $url);
|
70
admin/tool/profiling/import.php
Normal file
70
admin/tool/profiling/import.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Profiling tool import utility.
|
||||
*
|
||||
* @package tool_profiling
|
||||
* @copyright 2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_once(dirname(__FILE__) . '/import_form.php');
|
||||
|
||||
admin_externalpage_setup('toolprofiling');
|
||||
|
||||
$PAGE->navbar->add(get_string('import', 'tool_profiling'));
|
||||
|
||||
// Calculate export variables.
|
||||
$tempdir = 'profiling';
|
||||
make_temp_directory($tempdir);
|
||||
|
||||
// URL where we'll end, both on success and failure.
|
||||
$url = new moodle_url('/admin/tool/profiling/index.php');
|
||||
|
||||
// Instantiate the upload profiling runs form.
|
||||
$mform = new profiling_import_form();
|
||||
|
||||
// If there is any file to import.
|
||||
if ($data = $mform->get_data()) {
|
||||
$filename = $mform->get_new_filename('mprfile');
|
||||
$file = $CFG->tempdir . '/' . $tempdir . '/' . $filename;
|
||||
$status = $mform->save_file('mprfile', $file);
|
||||
if ($status) {
|
||||
// File saved properly, let's import it.
|
||||
$status = profiling_import_runs($file, $data->importprefix);
|
||||
}
|
||||
// Delete the temp file, not needed anymore.
|
||||
if (file_exists($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
if ($status) {
|
||||
// Import ended ok, let's redirect to main profiling page.
|
||||
redirect($url, get_string('importok', 'tool_profiling', $filename));
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('import', 'tool_profiling'));
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
die;
|
||||
}
|
||||
|
||||
// Something wrong happened, notice it and done.
|
||||
notice(get_string('importproblem', 'tool_profiling', $filename), $url);
|
47
admin/tool/profiling/import_form.php
Normal file
47
admin/tool/profiling/import_form.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Profiling tool import utility form.
|
||||
*
|
||||
* @package tool_profiling
|
||||
* @copyright 2013 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();
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
|
||||
class profiling_import_form extends moodleform {
|
||||
public function definition () {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'settingsheader', get_string('upload'));
|
||||
|
||||
$mform->addElement('filepicker', 'mprfile', get_string('file'), null, array('accepted_types' => array('.mpr', '.zip')));
|
||||
$mform->addRule('mprfile', null, 'required');
|
||||
|
||||
$mform->addElement('text', 'importprefix',
|
||||
get_string('importprefix', 'tool_profiling'), array('size' => 10));
|
||||
$mform->setDefault('importprefix', $CFG->profilingimportprefix);
|
||||
$mform->setType('importprefix', PARAM_TAG);
|
||||
|
||||
$this->add_action_buttons(false, get_string('import', 'tool_profiling'));
|
||||
}
|
||||
}
|
@ -17,8 +17,7 @@
|
||||
/**
|
||||
* Profiling tool.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage profiling
|
||||
* @package tool_profiling
|
||||
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -161,6 +160,9 @@ if (isset($script)) {
|
||||
|
||||
echo $OUTPUT->heading($header);
|
||||
|
||||
// Print the controller block with different options.
|
||||
echo profiling_list_controls($listurl);
|
||||
|
||||
// TODO: Fix flexitable to validate tsort/thide/tshow/tifirs/tilast/page
|
||||
// TODO: Fix table_sql to allow it to work without WHERE clause
|
||||
// add silly condition (1 = 1) because of table_sql bug
|
||||
@ -179,9 +181,6 @@ if (isset($script)) {
|
||||
$table->define_baseurl($baseurl);
|
||||
$table->column_suppress('url');
|
||||
$table->out(PROFILING_RUNSPERPAGE, true);
|
||||
|
||||
// Print the controller block with different options
|
||||
echo profiling_list_controls($listurl);
|
||||
}
|
||||
|
||||
// Footer.
|
||||
|
@ -24,13 +24,22 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$string['calls'] = 'Function calls';
|
||||
$string['cannotfindanyrunforurl'] = 'Sorry, cannot find any profiling run for the \'{$a}\' URL';
|
||||
$string['cannotfindanyrunforrunid'] = 'Sorry, cannot find the \'{$a}\' profiling run';
|
||||
$string['comment'] = 'Comment';
|
||||
$string['cputime'] = 'CPU time';
|
||||
$string['differencesbetween2runsof'] = 'Differences between 2 runs of {$a}';
|
||||
$string['executiontime'] = 'Execution time';
|
||||
$string['cputime'] = 'CPU time';
|
||||
$string['export'] = 'Export';
|
||||
$string['exportproblem'] = 'Some problem happened exporting the profile run "{$a->runid}" corresponding to the request "{$a->listurl}".';
|
||||
$string['exportthis'] = 'Export this profiling run';
|
||||
$string['import'] = 'Import';
|
||||
$string['importok'] = 'File "{$a}" imported successfully.';
|
||||
$string['importprefix'] = 'Import prefix';
|
||||
$string['importproblem'] = 'Some problem happened importing the file "{$a}".';
|
||||
$string['lastrunof'] = 'Summary of last run of {$a}';
|
||||
$string['markreferencerun'] = 'Mark as reference run/comment';
|
||||
$string['memory'] = 'Memory used';
|
||||
|
@ -17,14 +17,13 @@
|
||||
/**
|
||||
* Version details.
|
||||
*
|
||||
* @package tool
|
||||
* @subpackage profiling
|
||||
* @package tool_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 = 2013050100; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2013050200; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2013050100; // Requires this Moodle version
|
||||
$plugin->component = 'tool_profiling'; // Full name of the plugin (used for diagnostics)
|
||||
|
@ -874,6 +874,8 @@ $string['profilingenabled'] = 'Enable profiling';
|
||||
$string['profilingenabled_help'] = 'If you enable this setting, then profiling will be available in this site and you will be able to define its behavior by configuring the next options.';
|
||||
$string['profilingexcluded'] = 'Exclude profiling';
|
||||
$string['profilingexcluded_help'] = 'List of (comma separated, absolute skipping wwwroot, callable) URLs that will be excluded from being profiled from the ones defined by \'Profile these\' setting.';
|
||||
$string['profilingimportprefix'] = 'Profiling import prefix';
|
||||
$string['profilingimportprefix_desc'] = 'For easier detection, all the imported profiling runs will be prefixed with the value specified here.';
|
||||
$string['profilingincluded'] = 'Profile these';
|
||||
$string['profilingincluded_help'] = 'List of (comma separated, absolute skipping wwwroot, callable) URLs that will be automatically profiled. Examples: /index.php, /course/view.php. Also accepts the * wildchar at any position. Examples: /mod/forum/*, /mod/*/view.php.';
|
||||
$string['profilinglifetime'] = 'Keep profiling runs';
|
||||
|
@ -1449,6 +1449,7 @@ function &get_mimetypes_array() {
|
||||
'mpeg' => array ('type'=>'video/mpeg', 'icon'=>'mpeg', 'groups'=>array('video','web_video'), 'string'=>'video'),
|
||||
'mpe' => array ('type'=>'video/mpeg', 'icon'=>'mpeg', 'groups'=>array('video','web_video'), 'string'=>'video'),
|
||||
'mpg' => array ('type'=>'video/mpeg', 'icon'=>'mpeg', 'groups'=>array('video','web_video'), 'string'=>'video'),
|
||||
'mpr' => array ('type'=>'application/vnd.moodle.profiling', 'icon'=>'moodle'),
|
||||
|
||||
'nbk' => array ('type'=>'application/x-smarttech-notebook', 'icon'=>'archive'),
|
||||
'notebook' => array ('type'=>'application/x-smarttech-notebook', 'icon'=>'archive'),
|
||||
|
@ -6070,6 +6070,7 @@ function get_file_packer($mimetype='application/zip') {
|
||||
switch ($mimetype) {
|
||||
case 'application/zip':
|
||||
case 'application/vnd.moodle.backup':
|
||||
case 'application/vnd.moodle.profiling':
|
||||
$classname = 'zip_packer';
|
||||
break;
|
||||
case 'application/x-tar':
|
||||
|
@ -24,9 +24,6 @@ TODO:
|
||||
* with the 3 reports (index, callgraph and typeahead), close seesion asap,
|
||||
so user can continue working with moodle while the report (specially
|
||||
the graph is being generated).
|
||||
* export/import profiling runs: Allow to pick any profile record, encapsulate
|
||||
it into some serialized/encoded way and allow download/upload. It requires
|
||||
DB changes in order to be able to specify the source of each record (own/imported).
|
||||
* improvements to the listing mode: various commodity details like:
|
||||
- allow to filter by various criteria
|
||||
- inline (and ajax) editing of reference/comment and deleting
|
||||
@ -36,6 +33,9 @@ TODO:
|
||||
- memory
|
||||
- cpu times
|
||||
(all them are right now enabled for everybody by default)
|
||||
* allow multiple runs to be exported together (right now only ONE can be
|
||||
exported at a time). Note it is only an UI restriction, backend supports multiple.
|
||||
|
||||
20101122 - MDL-24600 - Eloy Lafuente (stronk7): Original import of 0.9.2 release
|
||||
20110318 - MDL-26891 - Eloy Lafuente (stronk7): Implemented earlier profiling runs
|
||||
20130621 - MDL-39733 - Eloy Lafuente (stronk7): Export & import of profiling runs
|
||||
|
@ -23,13 +23,18 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// need some stuff from xhprof
|
||||
// Need some stuff from xhprof.
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_lib/utils/xhprof_lib.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_lib/utils/xhprof_runs.php');
|
||||
// need some stuff from moodle
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
// Need some stuff from moodle.
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
require_once($CFG->libdir . '/setuplib.php');
|
||||
require_once($CFG->libdir . '/phpunit/classes/util.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/xml_writer.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/output/xml_output.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/xml/output/file_xml_output.class.php');
|
||||
|
||||
// TODO: Change the implementation below to proper profiling class
|
||||
// TODO: Change the implementation below to proper profiling class.
|
||||
|
||||
/**
|
||||
* Returns if profiling is running, optionally setting it
|
||||
@ -300,6 +305,10 @@ function profiling_print_run($run, $prevrunid = null) {
|
||||
$url = 'index.php?runid=' . $run->runid . '&runid2=' . $prevrunid . '&listurl=' . urlencode($run->url);
|
||||
$output.=$OUTPUT->heading('<a href="' . $url . '" title="">' . $strviewdiff . '</a>', 3, 'main profilinglink');
|
||||
}
|
||||
// Add link to export this run.
|
||||
$strexport = get_string('exportthis', 'tool_profiling');
|
||||
$url = 'export.php?runid=' . $run->runid . '&listurl=' . urlencode($run->url);
|
||||
$output.=$OUTPUT->heading('<a href="' . $url . '" title="">' . $strexport . '</a>', 3, 'main profilinglink');
|
||||
|
||||
return $output;
|
||||
}
|
||||
@ -360,9 +369,11 @@ function profiling_print_rundiff($run1, $run2) {
|
||||
* like deletion/export/import...
|
||||
*/
|
||||
function profiling_list_controls($listurl) {
|
||||
global $CFG, $OUTPUT;
|
||||
global $CFG;
|
||||
|
||||
$output = '';
|
||||
$output = '<p class="centerpara buttons">';
|
||||
$output .= ' <a href="import.php">[' . get_string('import', 'tool_profiling') . ']</a>';
|
||||
$output .= '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
@ -408,6 +419,330 @@ function profiling_get_difference($number1, $number2, $units = '', $factor = 1,
|
||||
return $startspan . $delta . ' ' . $fnumdiff . ' ' . $units . ' (' . $fperdiff . '%)' . $endspan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export profiling runs to a .mpr (moodle profile runs) file.
|
||||
*
|
||||
* This function gets an array of profiling runs (array of runids) and
|
||||
* saves a .mpr file into destination for ulterior handling.
|
||||
*
|
||||
* Format of .mpr files:
|
||||
* mpr files are simple zip packages containing these files:
|
||||
* - moodle_profiling_runs.xml: Metadata about the information
|
||||
* exported. Contains some header information (version and
|
||||
* release of moodle, database, git hash - if available, date
|
||||
* of export...) and a list of all the runids included in the
|
||||
* export.
|
||||
* - runid.xml: One file per each run detailed in the main file,
|
||||
* containing the raw dump of the given runid in the profiling table.
|
||||
*
|
||||
* Possible improvement: Start storing some extra information in the
|
||||
* profiling table for each run (moodle version, database, git hash...).
|
||||
*
|
||||
* @param array $runids list of runids to be exported.
|
||||
* @param string $file filesystem fullpath to destination .mpr file.
|
||||
* @return boolean the mpr file has been successfully exported (true) or no (false).
|
||||
*/
|
||||
function profiling_export_runs(array $runids, $file) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// Verify we have passed proper runids.
|
||||
if (empty($runids)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify all the passed runids do exist.
|
||||
list ($insql, $inparams) = $DB->get_in_or_equal($runids);
|
||||
$reccount = $DB->count_records_select('profiling', 'runid ' . $insql, $inparams);
|
||||
if ($reccount != count($runids)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify the $file path is writeable.
|
||||
$base = dirname($file);
|
||||
if (!is_writable($base)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create temp directory where the temp information will be generated.
|
||||
$tmpdir = $base . '/' . md5(implode($runids) . time() . random_string(20));
|
||||
mkdir($tmpdir);
|
||||
|
||||
// Generate the xml contents in the temp directory.
|
||||
$status = profiling_export_generate($runids, $tmpdir);
|
||||
|
||||
// Package (zip) all the information into the final .mpr file.
|
||||
if ($status) {
|
||||
$status = profiling_export_package($file, $tmpdir);
|
||||
}
|
||||
|
||||
// Process finished ok, clean and return.
|
||||
fulldelete($tmpdir);
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a .mpr (moodle profile runs) file into moodle.
|
||||
*
|
||||
* See {@link profiling_export_runs()} for more details about the
|
||||
* implementation of .mpr files.
|
||||
*
|
||||
* @param string $file filesystem fullpath to target .mpr file.
|
||||
* @param string $commentprefix prefix to add to the comments of all the imported runs.
|
||||
* @return boolean the mpr file has been successfully imported (true) or no (false).
|
||||
*/
|
||||
function profiling_import_runs($file, $commentprefix = '') {
|
||||
global $DB;
|
||||
|
||||
// Any problem with the file or its directory, abort.
|
||||
if (!file_exists($file) or !is_readable($file) or !is_writable(dirname($file))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unzip the file into temp directory.
|
||||
$tmpdir = dirname($file) . '/' . time() . '_' . random_string(4);
|
||||
$fp = get_file_packer('application/vnd.moodle.profiling');
|
||||
$status = $fp->extract_to_pathname($file, $tmpdir);
|
||||
|
||||
// Look for master file and verify its format.
|
||||
if ($status) {
|
||||
$mfile = $tmpdir . '/moodle_profiling_runs.xml';
|
||||
if (!file_exists($mfile) or !is_readable($mfile)) {
|
||||
$status = false;
|
||||
} else {
|
||||
$mdom = new DOMDocument();
|
||||
if (!$mdom->load($mfile)) {
|
||||
$status = false;
|
||||
} else {
|
||||
$status = @$mdom->schemaValidateSource(profiling_get_import_main_schema());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify all detail files exist and verify their format.
|
||||
if ($status) {
|
||||
$runs = $mdom->getElementsByTagName('run');
|
||||
foreach ($runs as $run) {
|
||||
$rfile = $tmpdir . '/' . clean_param($run->getAttribute('ref'), PARAM_FILE);
|
||||
if (!file_exists($rfile) or !is_readable($rfile)) {
|
||||
$status = false;
|
||||
} else {
|
||||
$rdom = new DOMDocument();
|
||||
if (!$rdom->load($rfile)) {
|
||||
$status = false;
|
||||
} else {
|
||||
$status = @$rdom->schemaValidateSource(profiling_get_import_run_schema());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Everything looks ok, let's import all the runs.
|
||||
if ($status) {
|
||||
reset($runs);
|
||||
foreach ($runs as $run) {
|
||||
$rfile = $tmpdir . '/' . $run->getAttribute('ref');
|
||||
$rdom = new DOMDocument();
|
||||
$rdom->load($rfile);
|
||||
$runarr = array();
|
||||
$runarr['runid'] = clean_param($rdom->getElementsByTagName('runid')->item(0)->nodeValue, PARAM_ALPHANUMEXT);
|
||||
$runarr['url'] = clean_param($rdom->getElementsByTagName('url')->item(0)->nodeValue, PARAM_CLEAN);
|
||||
$runarr['runreference'] = clean_param($rdom->getElementsByTagName('runreference')->item(0)->nodeValue, PARAM_INT);
|
||||
$runarr['runcomment'] = $commentprefix . clean_param($rdom->getElementsByTagName('runcomment')->item(0)->nodeValue, PARAM_CLEAN);
|
||||
$runarr['timecreated'] = time(); // Now.
|
||||
$runarr['totalexecutiontime'] = clean_param($rdom->getElementsByTagName('totalexecutiontime')->item(0)->nodeValue, PARAM_INT);
|
||||
$runarr['totalcputime'] = clean_param($rdom->getElementsByTagName('totalcputime')->item(0)->nodeValue, PARAM_INT);
|
||||
$runarr['totalcalls'] = clean_param($rdom->getElementsByTagName('totalcalls')->item(0)->nodeValue, PARAM_INT);
|
||||
$runarr['totalmemory'] = clean_param($rdom->getElementsByTagName('totalmemory')->item(0)->nodeValue, PARAM_INT);
|
||||
$runarr['data'] = clean_param($rdom->getElementsByTagName('data')->item(0)->nodeValue, PARAM_CLEAN);
|
||||
// If the runid does not exist, insert it.
|
||||
if (!$DB->record_exists('profiling', array('runid' => $runarr['runid']))) {
|
||||
$DB->insert_record('profiling', $runarr);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the temp directory used for import.
|
||||
remove_dir($tmpdir);
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the mpr contents (xml files) in the temporal directory.
|
||||
*
|
||||
* @param array $runids list of runids to be generated.
|
||||
* @param string $tmpdir filesystem fullpath of tmp generation.
|
||||
* @return boolean the mpr contents have been generated (true) or no (false).
|
||||
*/
|
||||
function profiling_export_generate(array $runids, $tmpdir) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// Calculate the header information to be sent to moodle_profiling_runs.xml.
|
||||
$release = $CFG->release;
|
||||
$version = $CFG->version;
|
||||
$dbtype = $CFG->dbtype;
|
||||
$githash = phpunit_util::get_git_hash();
|
||||
$date = time();
|
||||
|
||||
// Create the xml output and writer for the main file.
|
||||
$mainxo = new file_xml_output($tmpdir . '/moodle_profiling_runs.xml');
|
||||
$mainxw = new xml_writer($mainxo);
|
||||
|
||||
// Output begins.
|
||||
$mainxw->start();
|
||||
$mainxw->begin_tag('moodle_profiling_runs');
|
||||
|
||||
// Send header information.
|
||||
$mainxw->begin_tag('info');
|
||||
$mainxw->full_tag('release', $release);
|
||||
$mainxw->full_tag('version', $version);
|
||||
$mainxw->full_tag('dbtype', $dbtype);
|
||||
if ($githash) {
|
||||
$mainxw->full_tag('githash', $githash);
|
||||
}
|
||||
$mainxw->full_tag('date', $date);
|
||||
$mainxw->end_tag('info');
|
||||
|
||||
// Send information about runs.
|
||||
$mainxw->begin_tag('runs');
|
||||
foreach ($runids as $runid) {
|
||||
// Get the run information from DB.
|
||||
$run = $DB->get_record('profiling', array('runid' => $runid), '*', MUST_EXIST);
|
||||
$attributes = array(
|
||||
'id' => $run->id,
|
||||
'ref' => $run->runid . '.xml');
|
||||
$mainxw->full_tag('run', null, $attributes);
|
||||
// Create the individual run file.
|
||||
$runxo = new file_xml_output($tmpdir . '/' . $attributes['ref']);
|
||||
$runxw = new xml_writer($runxo);
|
||||
$runxw->start();
|
||||
$runxw->begin_tag('moodle_profiling_run');
|
||||
$runxw->full_tag('id', $run->id);
|
||||
$runxw->full_tag('runid', $run->runid);
|
||||
$runxw->full_tag('url', $run->url);
|
||||
$runxw->full_tag('runreference', $run->runreference);
|
||||
$runxw->full_tag('runcomment', $run->runcomment);
|
||||
$runxw->full_tag('timecreated', $run->timecreated);
|
||||
$runxw->full_tag('totalexecutiontime', $run->totalexecutiontime);
|
||||
$runxw->full_tag('totalcputime', $run->totalcputime);
|
||||
$runxw->full_tag('totalcalls', $run->totalcalls);
|
||||
$runxw->full_tag('totalmemory', $run->totalmemory);
|
||||
$runxw->full_tag('data', $run->data);
|
||||
$runxw->end_tag('moodle_profiling_run');
|
||||
$runxw->stop();
|
||||
}
|
||||
$mainxw->end_tag('runs');
|
||||
$mainxw->end_tag('moodle_profiling_runs');
|
||||
$mainxw->stop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package (zip) the mpr contents (xml files) in the final location.
|
||||
*
|
||||
* @param string $file filesystem fullpath to destination .mpr file.
|
||||
* @param string $tmpdir filesystem fullpath of tmp generation.
|
||||
* @return boolean the mpr contents have been generated (true) or no (false).
|
||||
*/
|
||||
function profiling_export_package($file, $tmpdir) {
|
||||
// Get the list of files in $tmpdir.
|
||||
$filestemp = get_directory_list($tmpdir, '', false, true, true);
|
||||
$files = array();
|
||||
|
||||
// Add zip paths and fs paths to all them.
|
||||
foreach ($filestemp as $filetemp) {
|
||||
$files[$filetemp] = $tmpdir . '/' . $filetemp;
|
||||
}
|
||||
|
||||
// Get the zip_packer.
|
||||
$zippacker = get_file_packer('application/zip');
|
||||
|
||||
// Generate the packaged file.
|
||||
$zippacker->archive_to_pathname($files, $file);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the xml schema for the main import file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function profiling_get_import_main_schema() {
|
||||
$schema = <<<EOS
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
|
||||
<xs:element name="moodle_profiling_runs">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="info"/>
|
||||
<xs:element ref="runs"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="info">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="release"/>
|
||||
<xs:element type="xs:decimal" name="version"/>
|
||||
<xs:element type="xs:string" name="dbtype"/>
|
||||
<xs:element type="xs:string" minOccurs="0" name="githash"/>
|
||||
<xs:element type="xs:int" name="date"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="runs">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element maxOccurs="unbounded" ref="run"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="run">
|
||||
<xs:complexType>
|
||||
<xs:attribute type="xs:int" name="id"/>
|
||||
<xs:attribute type="xs:string" name="ref"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
EOS;
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the xml schema for each individual run import file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function profiling_get_import_run_schema() {
|
||||
$schema = <<<EOS
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
|
||||
<xs:element name="moodle_profiling_run">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:int" name="id"/>
|
||||
<xs:element type="xs:string" name="runid"/>
|
||||
<xs:element type="xs:string" name="url"/>
|
||||
<xs:element type="xs:int" name="runreference"/>
|
||||
<xs:element type="xs:string" name="runcomment"/>
|
||||
<xs:element type="xs:int" name="timecreated"/>
|
||||
<xs:element type="xs:int" name="totalexecutiontime"/>
|
||||
<xs:element type="xs:int" name="totalcputime"/>
|
||||
<xs:element type="xs:int" name="totalcalls"/>
|
||||
<xs:element type="xs:int" name="totalmemory"/>
|
||||
<xs:element type="xs:string" name="data"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:schema>
|
||||
EOS;
|
||||
return $schema;
|
||||
}
|
||||
/**
|
||||
* Custom implementation of iXHProfRuns
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user