Skip to content

Commit

Permalink
Merge branch 'MDL-39733_25' of git://github.com/stronk7/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_25_STABLE
  • Loading branch information
Sam Hemelryk committed Jul 1, 2013
2 parents bb9024d + 16a2860 commit f0d974f
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 18 deletions.
4 changes: 4 additions & 0 deletions admin/settings/development.php
Expand Up @@ -65,6 +65,10 @@
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);
Expand Down
56 changes: 56 additions & 0 deletions admin/tool/profiling/export.php
@@ -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 changes: 70 additions & 0 deletions admin/tool/profiling/import.php
@@ -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 changes: 47 additions & 0 deletions admin/tool/profiling/import_form.php
@@ -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'));
}
}
9 changes: 4 additions & 5 deletions admin/tool/profiling/index.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -161,6 +160,9 @@

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
Expand All @@ -179,9 +181,6 @@
$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.
Expand Down
11 changes: 10 additions & 1 deletion admin/tool/profiling/lang/en/tool_profiling.php
Expand Up @@ -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';
Expand Down
5 changes: 2 additions & 3 deletions admin/tool/profiling/version.php
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -873,6 +873,8 @@
$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';
Expand Down
1 change: 1 addition & 0 deletions lib/filelib.php
Expand Up @@ -1516,6 +1516,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'),
Expand Down
1 change: 1 addition & 0 deletions lib/moodlelib.php
Expand Up @@ -6057,6 +6057,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':
Expand Down
6 changes: 3 additions & 3 deletions lib/xhprof/readme_moodle.txt
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f0d974f

Please sign in to comment.