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

Commit

Permalink
Merge pull request #77 from paritytech/shawntabrizi-rustup-update
Browse files Browse the repository at this point in the history
Add `rustup update` command
  • Loading branch information
shawntabrizi authored Jan 1, 2022
2 parents 5f5a7de + 0c0237f commit ae19f1b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
77 changes: 56 additions & 21 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,25 @@ var PolkadotRuntimeBenchmarkConfigs = {
"--output=./runtime/westend/src/weights/{output_file}",
].join(" "),
},
rococo: {
title: "Runtime Rococo Pallet",
benchCommand: [
"cargo run --quiet --release",
"--features=runtime-benchmarks",
"--",
"benchmark",
"--chain=rococo-dev",
"--steps=50",
"--repeat=20",
"--pallet={pallet_name}",
'--extrinsic="*"',
"--execution=wasm",
"--wasm-execution=compiled",
"--heap-pages=4096",
"--header=./file_header.txt",
"--output=./runtime/rococo/src/weights/{output_file}",
].join(" "),
},
rococo: {
title: "Runtime Rococo Pallet",
benchCommand: [
"cargo run --quiet --release",
"--features=runtime-benchmarks",
"--",
"benchmark",
"--chain=rococo-dev",
"--steps=50",
"--repeat=20",
"--pallet={pallet_name}",
'--extrinsic="*"',
"--execution=wasm",
"--wasm-execution=compiled",
"--heap-pages=4096",
"--header=./file_header.txt",
"--output=./runtime/rococo/src/weights/{output_file}",
].join(" "),
},
custom: {
title: "Runtime Custom",
benchCommand:
Expand Down Expand Up @@ -508,8 +508,7 @@ function benchmarkRuntime(app, config) {
const outputFile = benchCommand.match(/--output(?:=|\s+)(".+?"|\S+)/)[1]
var { stdout, stderr } = benchContext.runTask(
benchCommand,
`Running for branch ${config.branch}, ${
outputFile ? `outputFile: ${outputFile}` : ""
`Running for branch ${config.branch}, ${outputFile ? `outputFile: ${outputFile}` : ""
}: ${benchCommand}`,
)
let extraInfo = ""
Expand Down Expand Up @@ -572,7 +571,43 @@ function benchmarkRuntime(app, config) {
})
}

function benchRustup(app, config) {
app.log("Waiting our turn to run benchRustup...")

return mutex.runExclusive(async function () {
try {

// right now only `rustup update` is supported.
if (config.extra != "update") {
return errorResult(`Invalid "rustup" command. Only "update" is supported.`)
}

const collector = new libCollector.Collector()
var benchContext = new BenchContext(app, config)

let benchCommand = "rustup update";
let title = "Rustup Update";

var { stderr, error, stdout } = benchContext.runTask(
benchCommand,
`Executing "rustup update"...`,
)
if (error) return errorResult(stderr)

return {
title,
output: stdout ? stdout : stderr,
extraInfo: "",
benchCommand
}
} catch (error) {
return errorResult("Caught exception in benchRustup", error)
}
})
}

module.exports = {
benchBranch: benchBranch,
benchmarkRuntime: benchmarkRuntime,
benchRustup: benchRustup,
}
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = require("assert")
const fs = require("fs")
const shell = require("shelljs")

var { benchBranch, benchmarkRuntime } = require("./bench")
var { benchBranch, benchmarkRuntime, benchRustup } = require("./bench")

const githubCommentLimitLength = 65536
const githubCommentLimitTruncateMessage = "<truncated>..."
Expand Down Expand Up @@ -145,6 +145,8 @@ module.exports = (app) => {
let report
if (action == "runtime" || action == "xcm") {
report = await benchmarkRuntime(app, config)
} else if (action == "rustup") {
report = await benchRustup(app, config)
} else {
report = await benchBranch(app, config)
}
Expand All @@ -160,9 +162,8 @@ module.exports = (app) => {
app.log.error(report.error)
}

const output = `${report.message}${
report.error ? `: ${report.error.toString()}` : ""
}`
const output = `${report.message}${report.error ? `: ${report.error.toString()}` : ""
}`

await context.octokit.issues.updateComment({
owner,
Expand All @@ -179,6 +180,8 @@ module.exports = (app) => {
const bodyPrefix = `
Benchmark **${title}** for branch "${branch}" with command ${benchCommand}
Toolchain: ${toolchain}
<details>
<summary>Results</summary>
Expand All @@ -199,7 +202,7 @@ Benchmark **${title}** for branch "${branch}" with command ${benchCommand}
output = `${output.slice(
0,
githubCommentLimitLength -
(githubCommentLimitTruncateMessage.length + formattingLength),
(githubCommentLimitTruncateMessage.length + formattingLength),
)}${githubCommentLimitTruncateMessage}`
}

Expand Down

0 comments on commit ae19f1b

Please sign in to comment.