2018-10-11 07:19:15 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2018-10-11 06:11:25 +00:00
|
|
|
const si = require("systeminformation");
|
2018-10-11 06:19:42 +00:00
|
|
|
const mri = require("mri");
|
2018-10-11 06:30:22 +00:00
|
|
|
const sll = require("single-line-log").stdout;
|
|
|
|
const kleur = require("kleur");
|
2018-10-11 07:02:08 +00:00
|
|
|
const fork = require("child_process").fork;
|
2018-10-11 07:10:43 +00:00
|
|
|
const sleep = require("sleep");
|
2018-10-11 06:11:25 +00:00
|
|
|
|
|
|
|
async function readTemp() {
|
|
|
|
const temp = await si.cpuTemperature();
|
2018-10-11 06:30:22 +00:00
|
|
|
return { main: temp.main, cores: temp.cores };
|
2018-10-11 06:11:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 07:10:43 +00:00
|
|
|
function avg(arr) {
|
|
|
|
return arr.reduce((sum, t) => t.main + sum, 0) / arr.length;
|
|
|
|
}
|
|
|
|
|
2018-10-11 06:19:42 +00:00
|
|
|
async function thawMyCarrots(targetTemp) {
|
2018-10-11 06:52:54 +00:00
|
|
|
let temp = await readTemp(),
|
2018-10-11 07:10:43 +00:00
|
|
|
temps = [temp, temp, temp],
|
2018-10-11 07:02:08 +00:00
|
|
|
children = [];
|
2018-10-11 06:52:54 +00:00
|
|
|
|
|
|
|
while (1) {
|
2018-10-11 07:10:43 +00:00
|
|
|
if (avg(temps) < targetTemp) {
|
2018-10-11 07:02:08 +00:00
|
|
|
if (children.length < 10) {
|
|
|
|
children.push(fork("./eat-cpu"));
|
|
|
|
}
|
2018-10-11 07:10:43 +00:00
|
|
|
} else if (avg(temps) > targetTemp) {
|
2018-10-11 07:02:08 +00:00
|
|
|
if (children.length > 0) {
|
|
|
|
children.pop().kill();
|
|
|
|
}
|
2018-10-11 06:52:54 +00:00
|
|
|
}
|
2018-10-11 06:11:25 +00:00
|
|
|
|
2018-10-11 06:30:22 +00:00
|
|
|
temp = await readTemp();
|
2018-10-11 07:10:43 +00:00
|
|
|
temps.shift();
|
|
|
|
temps.push(temp);
|
|
|
|
|
2018-10-11 06:52:54 +00:00
|
|
|
sll(
|
|
|
|
"Current temp",
|
|
|
|
kleur.bold.red(temp.main.toFixed(2)),
|
|
|
|
"\nCores at",
|
|
|
|
kleur.bold.gray(temp.cores),
|
2018-10-11 07:02:08 +00:00
|
|
|
`\nChildren: ${children.length}`
|
2018-10-11 06:52:54 +00:00
|
|
|
);
|
2018-10-11 07:10:43 +00:00
|
|
|
sleep.msleep(500);
|
2018-10-11 06:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 06:19:42 +00:00
|
|
|
const args = process.argv.slice(2),
|
|
|
|
targetTemp = mri(args, {
|
|
|
|
alias: { temp: "t" },
|
|
|
|
default: { temp: 85 }
|
|
|
|
});
|
|
|
|
|
|
|
|
thawMyCarrots(targetTemp.temp);
|