machineSlots
uses node:os
How many slots the machine has: how much work (a suite, a Vitest project of test definitions, checking, a build)
every tcm on it runs at once, together. TCM_SLOTS (or TCM_SUITE_SLOTS, its name before), or defaultSlots
for this machine.
import { defaultSlots } from "#codebase/tcmts/cli/budget"; import { spawnSync } from "node:child_process"; import os from "node:os"; export function machineSlots(): number { for (const name of ["TCM_SLOTS", "TCM_SUITE_SLOTS"]) { const given = Number(process.env[name]); if (process.env[name] && Number.isInteger(given) && given > 0) return given; } const cpus = os.availableParallelism(); let performance = cpus; if (process.platform === "darwin") { const r = spawnSync("sysctl", ["-n", "hw.perflevel0.logicalcpu"], { encoding: "utf8" }); const n = Number(r.stdout?.trim()); if (r.status === 0 && n > 0) performance = n; } return defaultSlots(cpus, performance, os.totalmem()); }