first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for tool_profiling.
*
* @package tool_profiling
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_profiling\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_profiling implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+56
View 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(__DIR__ . '/../../../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
View 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(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
require_once(__DIR__ . '/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
View 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'));
}
}
+192
View File
@@ -0,0 +1,192 @@
<?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.
*
* @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
*/
// TODO: Move all the DB stuff to profiling_db_xxxx() function in xhprof_moodle.php
// TODO: it is wrong when core lib references ANY plugin lang strings, maybe more login could be moved here (skodak)
require_once(__DIR__ . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
define('PROFILING_RUNSPERPAGE', 50);
// page parameters
$script = optional_param('script', null, PARAM_PATH);
$runid = optional_param('runid', null, PARAM_ALPHANUM);
$runid2 = optional_param('runid2', null, PARAM_ALPHANUM);
$listurl = optional_param('listurl', null, PARAM_PATH);
$runreference= optional_param('runreference', 0, PARAM_INT);
$runcomment = optional_param('runcomment', null, PARAM_TEXT);
$dbfields = 'runid, url, totalexecutiontime, totalcputime, ' .
'totalcalls, totalmemory, runreference, runcomment, timecreated';
admin_externalpage_setup('toolprofiling');
// Always add listurl if available
if ($listurl) {
$listurlnav = new moodle_url('/admin/tool/profiling/index.php', array('listurl' => $listurl));
$PAGE->navbar->add($listurl, $listurlnav);
}
// Add a new nav item to make $listurl clickable for the Boost theme.
if (isset($script)) {
$lastrunnav = get_string('lastrun', 'tool_profiling');
$PAGE->navbar->add($lastrunnav);
}
// Header
echo $OUTPUT->header();
// We have requested the last available run for one script
if (isset($script)) {
// Get the last available run for the given script
$run = $DB->get_record_sql("SELECT $dbfields
FROM {profiling}
WHERE url = ?
AND id = (SELECT MAX(id)
FROM {profiling}
WHERE url = ?)",
array($script, $script), IGNORE_MISSING);
// No run found for script, warn and exit
if (!$run) {
notice(get_string('cannotfindanyrunforurl', 'tool_profiling', $script), 'index.php');
}
// Check if there is any previous run marked as reference one
$prevreferences = $DB->get_records_select('profiling',
'url = ? AND runreference = 1 AND timecreated < ?',
array($run->url, $run->timecreated),
'timecreated DESC', 'runid, runcomment, timecreated', 0, 10);
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
$header = get_string('lastrunof', 'tool_profiling', $script);
echo $OUTPUT->heading($header);
$table = profiling_print_run($run, $prevreferences);
echo $table;
echo $OUTPUT->box_end();
// We have requested the diff between 2 runs
} else if (isset($runid) && isset($runid2)) {
$run1 = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, MUST_EXIST);
$run2 = $DB->get_record('profiling', array('runid'=>$runid2), $dbfields, MUST_EXIST);
if ($run1->url == $run2->url && $run1->runid != $run2->runid) {
if ($run2->timecreated < $run1->timecreated) {
$runtemp = $run1;
$run1 = $run2;
$run2 = $runtemp;
}
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
$header = get_string('differencesbetween2runsof', 'tool_profiling', $run1->url);
echo $OUTPUT->heading($header);
$table = profiling_print_rundiff($run1, $run2);
echo $table;
echo $OUTPUT->box_end();
}
// We have requested one run, invoke it
} else if (isset($runid)) {
// Check if we are trying to update the runreference/runcomment for the run
if (isset($runcomment) && confirm_sesskey()) {
$id = $DB->get_field('profiling', 'id', array('runid' => $runid), MUST_EXIST);
$rec = new stdClass();
$rec->id = $id;
$rec->runreference = (bool)$runreference;
$rec->runcomment = $runcomment;
$DB->update_record('profiling', $rec);
}
// Get the requested runid
$run = $DB->get_record('profiling', array('runid'=>$runid), $dbfields, IGNORE_MISSING);
// No run found for runid, warn and exit
if (!$run) {
notice(get_string('cannotfindanyrunforrunid', 'tool_profiling', $runid), 'index.php');
}
// Check if there is any previous run marked as reference one
$prevreferences = $DB->get_records_select('profiling',
'url = ? AND runreference = 1 AND timecreated < ?',
array($run->url, $run->timecreated),
'timecreated DESC', 'runid, runcomment, timecreated', 0, 10);
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
$header = get_string('summaryof', 'tool_profiling', $run->url);
echo $OUTPUT->heading($header);
$table = profiling_print_run($run, $prevreferences);
echo $table;
echo $OUTPUT->box_end();
// Default: List one page of runs
} else {
// The flexitable that will root listings
$table = new xhprof_table_sql('profiling-list-table');
$baseurl = $CFG->wwwroot . '/'.$CFG->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', 'tool_profiling');
$sqlconditions = '1 = 1';
$table->set_listurlmode(false);
} else {
$header = get_string('profilingrunsfor', 'tool_profiling', $listurl);
$sqlconditions = 'url = :url';
$sqlparams['url'] = $listurl;
$table->set_listurlmode(true);
$baseurl .= '?listurl=' . urlencode($listurl);
}
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
$table->set_sql($dbfields, '{profiling}', $sqlconditions, $sqlparams);
$table->set_count_sql("SELECT COUNT(*) FROM {profiling} WHERE $sqlconditions", $sqlparams);
$columns = array(
'url', 'timecreated', 'totalexecutiontime', 'totalcputime',
'totalcalls', 'totalmemory', 'runcomment');
$headers = array(
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);
$table->define_baseurl($baseurl);
$table->column_suppress('url');
$table->out(PROFILING_RUNSPERPAGE, true);
}
// Footer.
echo $OUTPUT->footer();
@@ -0,0 +1,57 @@
<?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/>.
/**
* Strings for component 'tool_profiling', language 'en', branch 'MOODLE_22_STABLE'
*
* @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();
$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['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['lastrun'] = 'Summary of last run';
$string['markreferencerun'] = 'Mark as reference run/comment';
$string['memory'] = 'Memory used';
$string['pluginname'] = 'Profiling runs';
$string['profilingfocusscript'] = 'Focus on profiling runs for the script: {$a}';
$string['profilingruns'] = 'Profiling runs';
$string['profilingrunsfor'] = 'Profiling runs for {$a}';
$string['referencerun'] = 'Reference run/comment';
$string['runid'] = 'Run ID';
$string['summaryof'] = 'Summary of {$a}';
$string['viewdetails'] = 'View profiling details';
$string['viewdiff'] = 'View profiling differences with:';
$string['viewdiffdetails'] = 'View profiling diff details';
$string['privacy:metadata'] = 'The Profiling runs plugin does not store any personal data.';
+36
View File
@@ -0,0 +1,36 @@
<?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 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.
$hasextension = extension_loaded('tideways_xhprof');
$hasextension = $hasextension || extension_loaded('tideways');
$hasextension = $hasextension || extension_loaded('xhprof');
$isenabled = !empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled);
if ($hasextension && $isenabled) {
$ADMIN->add('development', new admin_externalpage('toolprofiling', get_string('pluginname', 'tool_profiling'),
"$CFG->wwwroot/$CFG->admin/tool/profiling/index.php", 'moodle/site:config'));
}
+27
View File
@@ -0,0 +1,27 @@
/* 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 {
margin-left: auto;
margin-right: auto;
}
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Version details.
*
* @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 = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'tool_profiling'; // Full name of the plugin (used for diagnostics)