Skip to content

Commit

Permalink
Convert data to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 2, 2025
1 parent 21296a7 commit 0660513
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
92 changes: 92 additions & 0 deletions runner/main/jobtypes/performance/format_rundata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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/>.

/**
* 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 <[email protected]>
* @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,
];
}
14 changes: 11 additions & 3 deletions runner/main/jobtypes/performance/performance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0660513

Please sign in to comment.