Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more machine info #38

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/actions/build-rspack/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ outputs:
runs:
using: composite
steps:
- shell: bash
run: |
npm install -g [email protected]
echo "Corepack version: $(corepack --version)"
corepack enable
- shell: bash
run: pnpm --version
- shell: bash
run: pnpm install --prefer-frozen-lockfile --prefer-offline
- name: Build Rspack JS
shell: bash
run: >-
Expand Down
20 changes: 18 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,24 @@ if (!command || command === "build") {

if (!command || command === "bench") {
if (isGitHubActions) {
await $`lscpu -e=CPU,MHZ`;
await $`echo "CPU Usage: "$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]"%"`;
await $`echo "===== System Information ====="`;
await $`uname -a`;
await $`cat /etc/os-release`;
await $`uname -r`;
await $`uptime`;

await $`echo "===== Resource Usage ====="`;
await $`top -b -n1 | head -n10`;
await $`vmstat`;
await $`df -h`;
await $`free -h`;

await $`echo "===== Hardware Information ====="`;
await $`lscpu`;
await $`lsblk`;

await $`echo "===== Environment Variables ====="`;
await $`printenv`;
}

const shardPair = shard.split("/").map(t => parseInt(t, 10));
Expand Down
44 changes: 13 additions & 31 deletions bin/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { readFile, writeFile, readdir, mkdir, copyFile } from "fs/promises";
import { existsSync } from "fs";
import { resolve, join } from "path";
import { fileURLToPath } from "url";
import { runCommand, dirExist, formatDate } from "../lib/utils.js";
import { $, cd } from "zx";
import { dirExist, formatDate } from "../lib/utils.js";

const [, , token] = process.argv;
const GITHUB_ACTOR = process.env.GITHUB_ACTOR;
Expand All @@ -16,12 +17,7 @@ const rspackDir = process.env.RSPACK_DIR || resolve(rootDir, ".rspack");
const dateDir = resolve(dataDir, date);

async function getCommitSHA() {
let commitSHA;
await runCommand("git", ["rev-parse", "HEAD"], {
onData(stdout) {
commitSHA = stdout.toString().trim();
}
});
const commitSHA = (await $`git rev-parse HEAD`).toString().trim();
console.log("Current Commit SHA", commitSHA);
return commitSHA;
}
Expand All @@ -40,22 +36,13 @@ async function appendRspackBuildInfo() {

(async () => {
if (!(await dirExist(dataDir))) {
await runCommand("git", [
"clone",
"--branch",
"data",
"--single-branch",
"--depth",
"1",
repoUrl,
".data"
]);
await $`git clone --branch data --single-branch --depth 1 ${repoUrl} .data`;
}

process.chdir(dataDir);
await runCommand("git", ["remote", "set-url", "origin", repoUrl]);
await runCommand("git", ["reset", "--hard", "origin/data"]);
await runCommand("git", ["pull", "--rebase"]);
cd(dataDir);
await $`git remote set-url origin ${repoUrl}`;
await $`git reset --hard origin/data`;
await $`git pull --rebase`;

console.log("== copy output files ==");
const indexFile = resolve(dataDir, "index.txt");
Expand All @@ -77,23 +64,18 @@ async function appendRspackBuildInfo() {
await writeFile(indexFile, Array.from(files, f => `${f}\n`).join("") + "\n");

console.log("== update build-info.json ==");
process.chdir(rspackDir);
cd(rspackDir);
await appendRspackBuildInfo();
process.chdir(dataDir);
cd(dataDir);

console.log("== commit ==");
await runCommand("git", [
"add",
`${date}/*.json`,
"index.txt",
"build-info.json"
]);
await $`git add ${date}/*.json index.txt build-info.json`;
try {
await runCommand("git", ["commit", "-m", `"add ${date} results"`]);
await $`git commit -m "add ${date} results"`;
} catch {}

console.log("== push ==");
await runCommand("git", ["push"]);
await $`git push`;
})().catch(err => {
process.exitCode = 1;
console.error(err.stack);
Expand Down
59 changes: 28 additions & 31 deletions lib/scenarios/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import path from "path";
import { readFile, unlink, writeFile } from "fs/promises";
import { fileURLToPath } from "url";
import actionsCore from "@actions/core";
import { isGitHubActions, runCommand } from "../utils.js";
import { $, cd } from "zx";
import { isGitHubActions } from "../utils.js";
import {
getDirSizes,
calcStatistics,
Expand Down Expand Up @@ -41,27 +42,29 @@ async function runRspack(ctx) {
data[name] = (data[name] || 0) + +valueStr;
}
};
let remainingLine = "";
await runCommand(
const p = $.spawn(
path.join(rootDir, "node_modules/@rspack/cli/bin/rspack"),
ctx.rspackArgs,
{
verbose: false,
onData: function (chunk) {
const lines = (remainingLine + chunk).split("\n");
remainingLine = lines.pop();
lines.forEach(processLine);
}
shell: true,
stdio: ["ignore", "pipe", "ignore"]
}
);

let remainingLine = "";
p.stdout.on("data", chunk => {
const lines = (remainingLine + chunk).split("\n");
remainingLine = lines.pop();
lines.forEach(processLine);
});
const exitCode = await new Promise(resolve => p.once("exit", resolve));
data.exec = Date.now() - start;
await promise;
if (dataSetCounter > 1) {
for (const key of Object.keys(data)) {
data[key] /= dataSetCounter;
}
}
if (exitCode !== 0) throw new Error(`Build failed with ${exitCode}`);
data["dist size"] = await getDirSizes("dist");
return data;
}
Expand All @@ -70,7 +73,7 @@ export function getScenario(caseName) {
return {
async setup() {
const caseDir = path.resolve(rootDir, "cases", caseName);
process.chdir(caseDir);
cd(caseDir);
const configFilePath = path.resolve(caseDir, "rspack.config.js");
const config = await readFile(configFilePath);
const hmrConfig = await getHmrConfig(path.resolve(caseDir, "hmr.js"));
Expand Down Expand Up @@ -105,25 +108,19 @@ module.exports.plugins.push(new (require("../../lib/scenarios/build-plugin.cjs")
const rspackDir =
process.env.RSPACK_DIR || path.resolve(rootDir, ".rspack");
console.log("Create Rspack package link");
await runCommand("mkdir", [
"-p",
path.resolve(rootDir, "node_modules/@rspack")
]);
await runCommand("ln", [
"-nsf",
path.resolve(rspackDir, "packages/rspack"),
path.resolve(rootDir, "node_modules/@rspack/core")
]);
await runCommand("ln", [
"-nsf",
path.resolve(rspackDir, "packages/rspack-cli"),
path.resolve(rootDir, "node_modules/@rspack/cli")
]);
await runCommand("ln", [
"-nsf",
path.resolve(rspackDir, "packages/rspack-plugin-react-refresh"),
path.resolve(rootDir, "node_modules/@rspack/plugin-react-refresh")
]);
await $`mkdir -p ${path.resolve(rootDir, "node_modules/@rspack")}`;
await $`ln -nsf ${path.resolve(
rspackDir,
"packages/rspack"
)} ${path.resolve(rootDir, "node_modules/@rspack/core")}`;
await $`ln -nsf ${path.resolve(
rspackDir,
"packages/rspack-cli"
)} ${path.resolve(rootDir, "node_modules/@rspack/cli")}`;
await $`ln -nsf ${path.resolve(
rspackDir,
"packages/rspack-plugin-react-refresh"
)} ${path.resolve(rootDir, "node_modules/@rspack/plugin-react-refresh")}`;
},
async warmup(ctx) {
console.log("Run Rspack with args:", ctx.rspackArgs);
Expand Down Expand Up @@ -155,7 +152,7 @@ module.exports.plugins.push(new (require("../../lib/scenarios/build-plugin.cjs")
return writeFile(path, content);
})
);
process.chdir(rootDir);
cd(rootDir);
}
};
}
27 changes: 0 additions & 27 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { spawn } from "child_process";
import { stat } from "fs/promises";

export async function useAddons(addons, stage, ...args) {
Expand All @@ -7,32 +6,6 @@ export async function useAddons(addons, stage, ...args) {
}
}

export async function runCommand(
command,
args,
{ verbose = true, env, onData } = {}
) {
const hasOnData = typeof onData === "function";
const stdio = verbose ? "inherit" : "ignore";
const p = spawn(command, args, {
shell: true,
stdio: [stdio, hasOnData ? "pipe" : stdio, "inherit"],
env: env
? {
...process.env,
...env
}
: undefined
});
if (hasOnData) {
p.stdout.on("data", onData);
}

const exitCode = await new Promise(resolve => p.once("exit", resolve));
if (exitCode !== 0)
throw new Error(`${command} ${args.join(" ")} failed with ${exitCode}`);
}

export function getType(metric) {
if (metric.endsWith(" memory")) return "memory";
if (metric.endsWith(" size")) return "size";
Expand Down
Loading