1
+ const path = require ( 'path' ) ;
1
2
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' ) ;
2
7
3
8
function size ( s , base = 1 ) {
4
9
s *= base ;
@@ -13,15 +18,58 @@ function size(s, base = 1) {
13
18
14
19
const cache = { } ;
15
20
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
+
16
59
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 ( [
18
65
systeminformation . cpu ( ) ,
19
66
systeminformation . mem ( ) ,
20
67
systeminformation . osInfo ( ) ,
21
68
systeminformation . currentLoad ( ) ,
22
69
systeminformation . cpuFlags ( ) ,
23
70
systeminformation . cpuTemperature ( ) ,
24
71
systeminformation . battery ( ) ,
72
+ stackSize ( ) ,
25
73
] ) ;
26
74
const cpu = `${ Cpu . manufacturer } ${ Cpu . brand } ` ;
27
75
const memory = `${ size ( Memory . active ) } /${ size ( Memory . total ) } ` ;
@@ -31,13 +79,14 @@ async function get() {
31
79
let battery ;
32
80
if ( ! Battery . hasbattery ) battery = 'No battery' ;
33
81
else battery = `${ Battery . type } ${ Battery . model } ${ Battery . percent } %${ Battery . ischarging ? ' Charging' : '' } ` ;
34
- const _id = OsInfo . serial ;
82
+ const mid = OsInfo . serial ;
35
83
cache . cpu = cpu ;
36
84
cache . osinfo = osinfo ;
37
85
cache . flags = flags ;
38
- cache . _id = _id ;
86
+ cache . mid = mid ;
87
+ cache . stack = stack ;
39
88
return {
40
- _id , cpu, memory, osinfo, load, flags, CpuTemp, battery,
89
+ mid , cpu, memory, osinfo, load, flags, CpuTemp, battery, stack ,
41
90
} ;
42
91
}
43
92
@@ -49,20 +98,20 @@ async function update() {
49
98
systeminformation . battery ( ) ,
50
99
] ) ;
51
100
const {
52
- _id , cpu, osinfo, flags,
101
+ mid , cpu, osinfo, flags, stack ,
53
102
} = cache ;
54
103
const memory = `${ size ( Memory . active ) } /${ size ( Memory . total ) } ` ;
55
104
const load = `${ CurrentLoad . avgload } ` ;
56
105
let battery ;
57
106
if ( ! Battery . hasbattery ) battery = 'No battery' ;
58
107
else battery = `${ Battery . type } ${ Battery . model } ${ Battery . percent } %${ Battery . ischarging ? ' Charging' : '' } ` ;
59
108
return [
60
- _id ,
109
+ mid ,
61
110
{
62
111
memory, load, battery, CpuTemp,
63
112
} ,
64
113
{
65
- _id , cpu, memory, osinfo, load, flags, battery, CpuTemp,
114
+ mid , cpu, memory, osinfo, load, flags, battery, CpuTemp, stack ,
66
115
} ,
67
116
] ;
68
117
}
0 commit comments