Skip to content

Commit

Permalink
fix error logging in runner
Browse files Browse the repository at this point in the history
  • Loading branch information
IR0NSIGHT committed Feb 15, 2024
1 parent 9e41fb4 commit c6d5362
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions src/javascript/compare/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const execute = (command, onOutput, onError) => {
}
}

function effektBuildCommand(backend, effektFile) {
return `effekt.sh -b ${effektFile} --backend ${backend}`;
function effektBuildCommand(backend, effektFile, executableName) {
return `rm -f ./out/${executableName} && effekt.sh -b ${effektFile} --backend ${backend}`;
}

function effektCommand(amount, verifyArgs, executableName) {
Expand All @@ -46,7 +46,7 @@ function effektCommand(amount, verifyArgs, executableName) {
function executeCommands(commands, isVerify, backend, verbose) {
const outputs = [];
commands.forEach((command, index) => {
const performance = {name: command[0], effekt: {}, js: {}}
const performance = {name: command[0], effekt: {}, error: false , js: {}}
outputs.push(performance)

console.log("running benchmark:", performance.name)
Expand All @@ -62,14 +62,16 @@ function executeCommands(commands, isVerify, backend, verbose) {
performance.command = effektCmd;
const onRuntimeError = (error) => {
console.error(`benchmark ${executableName} execution crashed in effekt. log in output file`)
performance.error = true;
performance.effekt = { error: "runtime error", status: error.status, output: error.output.join("\n")};
}
const runEffekt = () => execute(effektCmd, (time) => performance.effekt = time, onRuntimeError)
const onCompileError = (error) => {
console.error(`benchmark ${executableName} compilation failed. log in output file`)
performance.error = true;
performance.effekt = { error: "compile error", status: error.status, output: error.output.join("\n")};
}
execute([dirtyCd, effektBuildCommand(backend, effektPath)].join(" && "), runEffekt, onCompileError );
execute([dirtyCd, effektBuildCommand(backend, effektPath, executableName)].join(" && "), runEffekt, onCompileError );

// run pure JS benchmark
const jsExecCmd = [dirtyCd, jsCmd + ` ${amount} ${verifyArgs}`].join(" && ");
Expand All @@ -78,40 +80,45 @@ function executeCommands(commands, isVerify, backend, verbose) {
execute(jsExecCmd, (time) => performance.js = time)
});

const errors = outputs.filter( log => log.error)

logErrors(errors);

const successfullBenchmarks = outputs.filter( log => !log.error)
logSuccesses(successfullBenchmarks);
}

try {
let analysis = outputs.map(mark => ({
name: mark.name,
effekt: analyzeDurations(mark.effekt),
js: analyzeDurations(mark.js)
}))
analysis = analysis.map(perf => ({...perf, ratio: perf.effekt.sum / perf.js.sum}))
console.log("Mini analysis:", analysis.map(mark => ({
name: mark.name,
effekt: mark.effekt.sum,
js: mark.js.sum,
ratio: mark.effekt.sum / mark.js.sum
})))
const outputFile = "fasteffekt_results.json"
console.log(`Verbose analysis saved to ${outputFile}`);
fs.writeFileSync(outputFile, JSON.stringify(analysis, null, 3));
} catch {
let analysis = outputs
.map(mark => {
const loggedErrorForBenchmark = [mark.command,
"error:",mark.effekt.error,
"status:", mark.effekt.status,
"output:", mark.effekt.output];
return (loggedErrorForBenchmark.join("\n"))
});
const errorlog = analysis.join("\n\n");
const outputFile = "fasteffekt_error.txt"
fs.writeFileSync(outputFile, errorlog);
console.error("error occured: not all benchmarks returned readable values. See " + outputFile + " for detailed errors.")
process.exit(1);
}
function logSuccesses(benchmarkRuns ) {
let analysis = benchmarkRuns.map(mark => ({
name: mark.name,
effekt: analyzeDurations(mark.effekt),
js: analyzeDurations(mark.js)
})).map(perf => ({...perf, ratio: perf.effekt.sum / perf.js.sum}))

console.log("Mini analysis:", analysis.map(mark => ({
name: mark.name,
effekt: mark.effekt.sum,
js: mark.js.sum,
ratio: mark.effekt.sum / mark.js.sum
})))
const outputFile = "fasteffekt_results.json"
console.log(`Verbose analysis saved to ${outputFile}`);
fs.writeFileSync(outputFile, JSON.stringify(analysis, null, 3));
}

function logErrors(errors) {
let analysis = errors
.map(mark => {
const loggedErrorForBenchmark = [mark.command,
"error:",mark.effekt.error,
"status:", mark.effekt.status,
"output:", mark.effekt.output];
return (loggedErrorForBenchmark.join("\n"))
});
const errorlog = analysis.join("\n\n");
const outputFile = "fasteffekt_error.txt"
fs.writeFileSync(outputFile, errorlog);
}
/**
* analyze duration array
* @param {string} durations : list of duration times for every benchmark run
Expand Down

0 comments on commit c6d5362

Please sign in to comment.