Skip to content
This repository was archived by the owner on Nov 8, 2020. It is now read-only.

Commit 067f6f8

Browse files
committed
栈空间大小上报
1 parent a9e9638 commit 067f6f8

File tree

5 files changed

+80
-13
lines changed

5 files changed

+80
-13
lines changed

examples/langs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
ccWithoutO2:
2+
type: compiler
3+
compile: /usr/bin/g++ -Wall -o ${name} foo.cc
4+
code_file: foo.cc
5+
execute: ${dir}/${name}
16
c:
27
type: compiler
38
compile: /usr/bin/gcc -O2 -Wall -std=c99 -o ${name} foo.c -lm

judger/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { LANGS_FILE, LANGS } = require('./config');
1010
let _langs = {};
1111
try {
1212
if (LANGS) _langs = LANGS;
13-
_langs = yaml.safeLoad(fs.readFileSync(LANGS_FILE));
13+
else _langs = yaml.safeLoad(fs.readFileSync(LANGS_FILE));
1414
} catch (e) {
1515
log.error('Invalidate Language file %s', LANGS_FILE);
1616
log.error(e);

judger/hosts/hydro.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ class JudgeTask {
2727
async handle() {
2828
try {
2929
this.stat.handle = new Date();
30-
this.pid = this.request.pid;
31-
this.rid = this.request.rid;
30+
this.pid = (this.request.pid || 'unknown').toString();
31+
this.rid = this.request.rid.toString();
32+
this.domainId = this.request.domainId;
3233
this.lang = this.request.lang;
3334
this.code = this.request.code;
3435
this.data = this.request.data;
36+
this.config = this.request.config;
3537
this.next = this.getNext(this);
3638
this.end = this.getEnd(this.session, this.rid);
3739
this.tmpdir = path.resolve(TEMP_DIR, 'tmp', this.host, this.rid);
@@ -124,7 +126,7 @@ class JudgeTask {
124126
}
125127
}
126128

127-
module.exports = class AxiosInstance {
129+
class Hydro {
128130
constructor(config) {
129131
this.config = config;
130132
this.config.detail = this.config.detail || true;
@@ -249,4 +251,7 @@ module.exports = class AxiosInstance {
249251
fs.writeFileSync(path.join(filePath, 'version'), version);
250252
return filePath;
251253
}
252-
};
254+
}
255+
256+
Hydro.JudgeTask = JudgeTask;
257+
module.exports = Hydro;

judger/sysinfo.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
const path = require('path');
12
const systeminformation = require('systeminformation');
3+
const { judge } = require('./judger/run');
4+
const { TEMP_DIR } = require('./config');
5+
const { mkdirp, rmdir } = require('./utils');
6+
const tmpfs = require('./tmpfs');
27

38
function size(s, base = 1) {
49
s *= base;
@@ -13,15 +18,58 @@ function size(s, base = 1) {
1318

1419
const cache = {};
1520

21+
async function stackSize() {
22+
let output = '';
23+
const context = {
24+
lang: 'ccWithoutO2',
25+
code: `
26+
#include <iostream>
27+
using namespace std;
28+
int i=1;
29+
int main(){
30+
char a[1048576]={'1'};
31+
cout<<" "<<i<<flush;
32+
i++;
33+
if (i>256) return 0;
34+
main();
35+
}`,
36+
config: {
37+
time: 3000,
38+
memory: 256,
39+
},
40+
stat: {},
41+
clean: [],
42+
next: () => { },
43+
end: (data) => {
44+
if (data.stdout) output = data.stdout;
45+
},
46+
};
47+
context.tmpdir = path.resolve(TEMP_DIR, 'tmp', 'sysinfo');
48+
mkdirp(context.tmpdir);
49+
tmpfs.mount(context.tmpdir, '64m');
50+
await judge(context).catch((e) => console.error(e));
51+
// eslint-disable-next-line no-await-in-loop
52+
for (const clean of context.clean) await clean().catch();
53+
tmpfs.umount(context.tmpdir);
54+
await rmdir(context.tmpdir);
55+
const a = output.split(' ');
56+
return parseInt(a[a.length - 1]);
57+
}
58+
1659
async function get() {
17-
const [Cpu, Memory, OsInfo, CurrentLoad, CpuFlags, CpuTemp, Battery] = await Promise.all([
60+
const [
61+
Cpu, Memory, OsInfo,
62+
CurrentLoad, CpuFlags, CpuTemp,
63+
Battery, stack,
64+
] = await Promise.all([
1865
systeminformation.cpu(),
1966
systeminformation.mem(),
2067
systeminformation.osInfo(),
2168
systeminformation.currentLoad(),
2269
systeminformation.cpuFlags(),
2370
systeminformation.cpuTemperature(),
2471
systeminformation.battery(),
72+
stackSize(),
2573
]);
2674
const cpu = `${Cpu.manufacturer} ${Cpu.brand}`;
2775
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
@@ -31,13 +79,14 @@ async function get() {
3179
let battery;
3280
if (!Battery.hasbattery) battery = 'No battery';
3381
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`;
34-
const _id = OsInfo.serial;
82+
const mid = OsInfo.serial;
3583
cache.cpu = cpu;
3684
cache.osinfo = osinfo;
3785
cache.flags = flags;
38-
cache._id = _id;
86+
cache.mid = mid;
87+
cache.stack = stack;
3988
return {
40-
_id, cpu, memory, osinfo, load, flags, CpuTemp, battery,
89+
mid, cpu, memory, osinfo, load, flags, CpuTemp, battery, stack,
4190
};
4291
}
4392

@@ -49,20 +98,20 @@ async function update() {
4998
systeminformation.battery(),
5099
]);
51100
const {
52-
_id, cpu, osinfo, flags,
101+
mid, cpu, osinfo, flags, stack,
53102
} = cache;
54103
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
55104
const load = `${CurrentLoad.avgload}`;
56105
let battery;
57106
if (!Battery.hasbattery) battery = 'No battery';
58107
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`;
59108
return [
60-
_id,
109+
mid,
61110
{
62111
memory, load, battery, CpuTemp,
63112
},
64113
{
65-
_id, cpu, memory, osinfo, load, flags, battery, CpuTemp,
114+
mid, cpu, memory, osinfo, load, flags, battery, CpuTemp, stack,
66115
},
67116
];
68117
}

module/service.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ async function postInit() {
1515
const { STATUS_COMPILE_ERROR, STATUS_SYSTEM_ERROR } = require('../judger/status');
1616
const readCases = require('../judger/cases');
1717
const judger = require('../judger/judger');
18+
const sysinfo = require('../judger/sysinfo');
1819

1920
const fsp = fs.promises;
2021
const { problem, file, task } = global.Hydro.model;
21-
const { judge } = global.Hydro.handler;
22+
const { judge, misc } = global.Hydro.handler;
23+
24+
const info = await sysinfo.get();
25+
misc.updateStatus(info);
26+
setInterval(async () => {
27+
const [mid, info] = await sysinfo.update();
28+
misc.updateStatus({ mid, ...info });
29+
}, 1200000);
2230

2331
async function processData(folder) {
2432
let files = await fsp.readdir(folder);

0 commit comments

Comments
 (0)