mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-55504 profiling: Support for PHPUnit and big profiles.
To support PHPUnit we need to support large profiles, these may include backups and restores. To do that the following was required; - gzcompress for database space saving. - gzcompress for XML DomDocument field to say < 10Mb and allow imports. - Save PHPUnit runs directly to a file so they can be imported to the normal database. - Memory allowance on profiling view pages increases to support large profiles.
This commit is contained in:
parent
5c33a0db21
commit
8f7dcb3453
@ -648,6 +648,7 @@ $CFG->admin = 'admin';
|
||||
// $CFG->phpunit_prefix = 'phpu_';
|
||||
// $CFG->phpunit_dataroot = '/home/example/phpu_moodledata';
|
||||
// $CFG->phpunit_directorypermissions = 02777; // optional
|
||||
// $CFG->phpunit_profilingenabled = true; // optional to profile PHPUnit runs.
|
||||
//
|
||||
//
|
||||
//=========================================================================
|
||||
|
@ -219,6 +219,10 @@ require_once("$CFG->dirroot/lib/phpunit/lib.php");
|
||||
|
||||
// finish moodle init
|
||||
define('ABORT_AFTER_CONFIG_CANCEL', true);
|
||||
if (isset($CFG->phpunit_profilingenabled) && $CFG->phpunit_profilingenabled) {
|
||||
$CFG->profilingenabled = true;
|
||||
$CFG->profilingincluded = '*';
|
||||
}
|
||||
require("$CFG->dirroot/lib/setup.php");
|
||||
|
||||
raise_memory_limit(MEMORY_HUGE);
|
||||
|
@ -34,6 +34,7 @@ require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_login();
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
raise_memory_limit(MEMORY_HUGE);
|
||||
\core\session\manager::write_close();
|
||||
// End moodle modification.
|
||||
|
||||
|
@ -36,6 +36,7 @@ require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
||||
require_login();
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
raise_memory_limit(MEMORY_HUGE);
|
||||
\core\session\manager::write_close();
|
||||
// End moodle modification.
|
||||
|
||||
|
@ -29,6 +29,7 @@ require_once($CFG->libdir . '/xhprof/xhprof_lib/utils/xhprof_runs.php');
|
||||
// Need some stuff from moodle.
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
require_once($CFG->libdir . '/setuplib.php');
|
||||
require_once($CFG->libdir . '/filelib.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');
|
||||
@ -586,6 +587,9 @@ function profiling_import_runs($file, $commentprefix = '') {
|
||||
$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']))) {
|
||||
if (@gzuncompress(base64_decode($runarr['data'])) === false) {
|
||||
$runarr['data'] = base64_encode(gzcompress(base64_decode($runarr['data'])));
|
||||
}
|
||||
$DB->insert_record('profiling', $runarr);
|
||||
} else {
|
||||
return false;
|
||||
@ -818,7 +822,12 @@ class moodle_xhprofrun implements iXHProfRuns {
|
||||
|
||||
$run_desc = $this->url . ($rec->runreference ? ' (R) ' : ' ') . ' - ' . s($rec->runcomment);
|
||||
|
||||
return unserialize(base64_decode($rec->data));
|
||||
// Handle historical runs that aren't compressed.
|
||||
if (@gzuncompress(base64_decode($rec->data)) === false) {
|
||||
return unserialize(base64_decode($rec->data));
|
||||
} else {
|
||||
return unserialize(gzuncompress(base64_decode($rec->data)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -828,7 +837,7 @@ class moodle_xhprofrun implements iXHProfRuns {
|
||||
* Note that $type is completely ignored
|
||||
*/
|
||||
public function save_run($xhprof_data, $type, $run_id = null) {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
|
||||
if (is_null($this->url)) {
|
||||
xhprof_error("Warning: You must use the prepare_run() method before saving it");
|
||||
@ -847,7 +856,7 @@ class moodle_xhprofrun implements iXHProfRuns {
|
||||
$rec = new stdClass();
|
||||
$rec->runid = $this->runid;
|
||||
$rec->url = $this->url;
|
||||
$rec->data = base64_encode(serialize($xhprof_data));
|
||||
$rec->data = base64_encode(gzcompress(serialize($xhprof_data), 9));
|
||||
$rec->totalexecutiontime = $this->totalexecutiontime;
|
||||
$rec->totalcputime = $this->totalcputime;
|
||||
$rec->totalcalls = $this->totalcalls;
|
||||
@ -855,6 +864,21 @@ class moodle_xhprofrun implements iXHProfRuns {
|
||||
$rec->timecreated = $this->timecreated;
|
||||
|
||||
$DB->insert_record('profiling', $rec);
|
||||
|
||||
if (PHPUNIT_TEST) {
|
||||
// Calculate export variables.
|
||||
$tempdir = 'profiling';
|
||||
make_temp_directory($tempdir);
|
||||
$runids = array($this->runid);
|
||||
$filename = $this->runid . '.mpr';
|
||||
$filepath = $CFG->tempdir . '/' . $tempdir . '/' . $filename;
|
||||
|
||||
// Generate the mpr file and send it.
|
||||
if (profiling_export_runs($runids, $filepath)) {
|
||||
fprintf(STDERR, "Profiling data saved to: ".$filepath."\n");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->runid;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user