Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
decrease command execution overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-paulo-parity committed Jul 13, 2021
1 parent 11b9240 commit d75f3e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
*.pem
.env
git
log.txt
runner_stdout.txt
runner_exitcode.txt
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ After it's running, the logs will be to the systemd journal:

`sudo journalctl -u benchbot.service`

As well as to `./log.txt`.

# Github Settings

## Permissions
Expand Down
43 changes: 14 additions & 29 deletions bench.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require("fs")
const cp = require("child_process")
const path = require("path")

Expand All @@ -8,6 +9,10 @@ function errorResult(message, error) {
let cwd = process.cwd();
console.log(`process cwd: ${cwd}`);

const wrapCmd = path.join(__dirname, "wrap_cmd.sh")
const runnerOutput = path.join(__dirname, "runner_stdout.txt")
const runnerExitCode = path.join(__dirname, "runner_exitcode.txt")

const Mutex = require('async-mutex').Mutex;
const mutex = new Mutex();
var shell = require('shelljs');
Expand All @@ -29,41 +34,21 @@ function BenchContext(app, config) {
try {
if (shouldLogOutput) {
console.log(`<=== Start command output (cwd: ${process.cwd()})`)
cp.execFileSync("/bin/dash", ["-c", `${cmd} | tee ${runnerOutput}`], { stdio: "inherit" })
stdout = fs.readFileSync(runnerOutput).toString()
} else {
stdout = cp.execSync(cmd, { stdio: "pipe", shell: true }).toString()
}

await new Promise(function (resolve) {
const proc = cp.spawn("/bin/bash", ["-c", cmd], { stdio: "pipe" })

proc.stdout.on("data", function (data) {
data = data.toString()

if (data && shouldLogOutput) {
console.log(data.trim())
}

stdout += data
})

proc.stderr.on("data", function (data) {
data = data.toString()

if (data && shouldLogOutput) {
console.log(data.trim())
}

stderr += data
})

proc.on("close", function (code) {
error = !!code
resolve()
})
})
} catch (err) {
error = true
if (err.code) {
app.log(`Command ${cmd} failed with error code ${error.code}`);
stdout = err.stdout.toString()

stderr = err.stderr.toString()
if (stderr) {
app.log(`stderr: ${stderr.trim()}`);
}
} else {
app.log.error("Caught exception in command execution")
app.log.error(err)
Expand Down
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ main() {
source ~/.cargo/env && \
cd "$install_location" && \
yarn && \
yarn start 2>&1 | tee -a log.txt
yarn start 2>&1
}

follow_service_logs() {
Expand Down

0 comments on commit d75f3e2

Please sign in to comment.