From 06605139326aae8b5621f9cbea4b22b696576e27 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 2 Jan 2025 09:38:45 +0800 Subject: [PATCH] Convert data to JSON --- .../jobtypes/performance/format_rundata.php | 92 +++++++++++++++++++ .../main/jobtypes/performance/performance.sh | 14 ++- 2 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 runner/main/jobtypes/performance/format_rundata.php diff --git a/runner/main/jobtypes/performance/format_rundata.php b/runner/main/jobtypes/performance/format_rundata.php new file mode 100644 index 0000000..ebffd71 --- /dev/null +++ b/runner/main/jobtypes/performance/format_rundata.php @@ -0,0 +1,92 @@ +. + +/** + * This file formats the data from the run into a format that can be used by the performance test system more widely. + * + * @copyright Andrew Lyons + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + */ + +// Removing the script name. +array_shift($argv); + +foreach ($argv as $inputfile) { + $filename = pathinfo($inputfile, PATHINFO_FILENAME); + $filepath = pathinfo($inputfile, PATHINFO_DIRNAME); + if (!str_ends_with($inputfile, '.php')) { + echo 'Error: You need to specify the runs filenames without their .php suffix.' . PHP_EOL; + exit(1); + } + + if (!file_exists($inputfile)) { + echo "Error: The file $inputfile does not exist." . PHP_EOL; + exit(1); + } + + $data = get_normalised_dataset($inputfile); + $outputfile = "{$filename}.json"; + file_put_contents("{$filepath}/{$filename}.json", json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); + + echo "Converted file {$inputfile} to {$outputfile}" . PHP_EOL; +} + +function get_normalised_dataset($datapath) { + require_once($datapath); + $runinfovars = [ + 'host', + 'sitepath', + 'group', + 'rundesc', + 'users', + 'loopcount', + 'rampup', + 'throughput', + 'size', + 'baseversion', + 'siteversion', + 'sitebranch', + 'sitecommit', + ]; + + foreach ($runinfovars as $var) { + // In case runs don't have all vars defined. + if (empty($$var)) { + $$var = 'Unknown'; + } + } + + $filename = pathinfo($datapath, PATHINFO_FILENAME); + + return (object) [ + 'filename' => "{$filename}.json", + 'host' => $host, + 'sitepath' => $sitepath, + 'group' => $group, + 'rundesc' => $rundesc, + 'users' => $users, + 'loopcount' => $loopcount, + 'rampup' => $rampup, + 'throughput' => $throughput, + 'size' => $size, + 'baseversion' => $baseversion, + 'siteversion' => $siteversion, + 'sitebranch' => $sitebranch, + 'sitecommit' => $sitecommit, + 'results' => $results, + ]; +} diff --git a/runner/main/jobtypes/performance/performance.sh b/runner/main/jobtypes/performance/performance.sh index 0cf40ef..67a6431 100644 --- a/runner/main/jobtypes/performance/performance.sh +++ b/runner/main/jobtypes/performance/performance.sh @@ -238,12 +238,20 @@ function performance_run() { # Performance job type teardown. function performance_teardown() { + DATADIR="${SHAREDDIR}/output/runs" + cp "${BASEDIR}/jobtypes/performance/format_rundata.php" "${DATADIR}/format_rundata.php" + docker run \ + -v "${DATADIR}:/shared" \ + -w /shared \ + php:8.3-cli \ + php /shared/format_rundata.php rundata.php + echo "Storing data with a git commit of '${GIT_COMMIT}'" # We use the storage directory to store data for long term comparison. - TARGET="${WORKSPACE}/performance/storage/${MOODLE_BRANCH}/${SITESIZE}" - mkdir -p "${TARGET}" - cp -rf "${SHAREDDIR}/output/runs/rundata.php" "${TARGET}/${GIT_COMMIT}.php" + TARGETDIR=`dirname "${TARGET}"` + mkdir -p "${WORKSPACE}/${TARGETDIR}" + cp -rf "${DATADIR}/rundata.json" "${TARGET_FILE}" } # Calculate the command to run for Performance main execution,