summaryrefslogtreecommitdiff
path: root/tools/flamebench.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-01-13 13:42:15 -0500
committerGitHub <noreply@github.com>2023-01-13 13:42:15 -0500
commit3d423e114e46f206ad2c6bfa5dfcb22094c5d2f6 (patch)
tree2bc1e25c9703128cd0b0ceccea63f659750226f2 /tools/flamebench.js
parent377f59327344bbb4f37b2eec189ae981a9a9db45 (diff)
chore: small cleanup of scripts in ./tools and run copyright checker in lint.js (#17393)
Diffstat (limited to 'tools/flamebench.js')
-rwxr-xr-xtools/flamebench.js142
1 files changed, 69 insertions, 73 deletions
diff --git a/tools/flamebench.js b/tools/flamebench.js
index e471d2891..5d1fc161d 100755
--- a/tools/flamebench.js
+++ b/tools/flamebench.js
@@ -2,35 +2,49 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { join, ROOT_PATH as ROOT } from "./util.js";
-async function bashOut(subcmd) {
- const { success, stdout } = await new Deno.Command("bash", {
- args: ["-c", subcmd],
- stdout: "piped",
- stderr: "null",
- }).output();
+const { 0: benchName, 1: benchFilter } = Deno.args;
+// Print usage if no bench specified
+if (!benchName) {
+ console.log("flamebench.js <bench_name> [bench_filter]");
+ // Also show available benches
+ console.log("\nAvailable benches:");
+ const benches = await availableBenches();
+ console.log(benches.join("\n"));
+ return Deno.exit(1);
+}
- // Check for failure
- if (!success) {
- throw new Error("subcmd failed");
- }
- // Gather output
- const output = new TextDecoder().decode(stdout);
+// List available benches, hoping we don't have any benches called "ls" :D
+if (benchName === "ls") {
+ const benches = await availableBenches();
+ console.log(benches.join("\n"));
+ return;
+}
- return output.trim();
+// Ensure flamegraph is installed
+if (!await binExists("flamegraph")) {
+ console.log(
+ "flamegraph (https://github.com/flamegraph-rs/flamegraph) not found, please run:",
+ );
+ console.log();
+ console.log("cargo install flamegraph");
+ return Deno.exit(1);
}
-async function bashThrough(subcmd, opts = {}) {
- const { success, code } = await new Deno.Command("bash", {
- ...opts,
- args: ["-c", subcmd],
- stdout: "inherit",
- stderr: "inherit",
- }).output();
+// Build bench with frame pointers
+await bashThrough(
+ `RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
+);
- // Exit process on failure
- if (!success) {
- Deno.exit(code);
- }
+// Get the freshly built bench binary
+const benchBin = await latestBenchBin(benchName);
+
+// Run flamegraph
+const outputFile = join(ROOT, "flamebench.svg");
+await runFlamegraph(benchBin, benchFilter, outputFile);
+
+// Open flamegraph (in your browser / SVG viewer)
+if (await binExists("open")) {
+ await bashThrough(`open ${outputFile}`);
}
async function availableBenches() {
@@ -59,60 +73,42 @@ function runFlamegraph(benchBin, benchFilter, outputFile) {
);
}
-async function binExists(bin) {
- try {
- await bashOut(`which ${bin}`);
- return true;
- } catch (_) {
- return false;
- }
-}
-
-async function main() {
- const { 0: benchName, 1: benchFilter } = Deno.args;
- // Print usage if no bench specified
- if (!benchName) {
- console.log("flamebench.js <bench_name> [bench_filter]");
- // Also show available benches
- console.log("\nAvailable benches:");
- const benches = await availableBenches();
- console.log(benches.join("\n"));
- return Deno.exit(1);
- }
-
- // List available benches, hoping we don't have any benches called "ls" :D
- if (benchName === "ls") {
- const benches = await availableBenches();
- console.log(benches.join("\n"));
- return;
- }
+async function bashOut(subcmd) {
+ const { success, stdout } = await new Deno.Command("bash", {
+ args: ["-c", subcmd],
+ stdout: "piped",
+ stderr: "null",
+ }).output();
- // Ensure flamegraph is installed
- if (!await binExists("flamegraph")) {
- console.log(
- "flamegraph (https://github.com/flamegraph-rs/flamegraph) not found, please run:",
- );
- console.log();
- console.log("cargo install flamegraph");
- return Deno.exit(1);
+ // Check for failure
+ if (!success) {
+ throw new Error("subcmd failed");
}
+ // Gather output
+ const output = new TextDecoder().decode(stdout);
- // Build bench with frame pointers
- await bashThrough(
- `RUSTFLAGS='-C force-frame-pointers=y' cargo build --release --bench ${benchName}`,
- );
+ return output.trim();
+}
- // Get the freshly built bench binary
- const benchBin = await latestBenchBin(benchName);
+async function bashThrough(subcmd, opts = {}) {
+ const { success, code } = await new Deno.Command("bash", {
+ ...opts,
+ args: ["-c", subcmd],
+ stdout: "inherit",
+ stderr: "inherit",
+ }).output();
- // Run flamegraph
- const outputFile = join(ROOT, "flamebench.svg");
- await runFlamegraph(benchBin, benchFilter, outputFile);
+ // Exit process on failure
+ if (!success) {
+ Deno.exit(code);
+ }
+}
- // Open flamegraph (in your browser / SVG viewer)
- if (await binExists("open")) {
- await bashThrough(`open ${outputFile}`);
+async function binExists(bin) {
+ try {
+ await bashOut(`which ${bin}`);
+ return true;
+ } catch (_) {
+ return false;
}
}
-// Run
-await main();