This commit is contained in:
Всеволод 2024-06-25 17:17:32 +08:00 committed by GitHub
commit 5eb05be030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 9 deletions

1
TODO.md Normal file
View File

@ -0,0 +1 @@
1. ~~add time format line (https://www.man7.org/linux/man-pages/man1/time.1.html#top_of_page)~~

View File

@ -13,7 +13,7 @@ RUN apt-get update && \
libncurses6 libncurses5 libedit-dev libseccomp-dev rename procps python3 \
libreadline-dev libblas-dev liblapack-dev libpcre3-dev libarpack2-dev \
libfftw3-dev libglpk-dev libqhull-dev libqrupdate-dev libsuitesparse-dev \
libsundials-dev libpcre2-dev && \
libsundials-dev libpcre2-dev time && \
rm -rf /var/lib/apt/lists/*
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

View File

@ -154,6 +154,13 @@ class Job {
Math.ceil(timeout / 1000),
];
const time_format = [
'-f',
// https://www.man7.org/linux/man-pages/man1/time.1.html#top_of_page
// elapsed user system memory
'%es %Us %Ss %MKb',
]
if (memory_limit >= 0) {
prlimit.push('--as=' + memory_limit);
}
@ -163,6 +170,8 @@ class Job {
...timeout_call,
...prlimit,
...nonetwork,
'time',
...time_format,
'bash',
file,
...args,
@ -172,6 +181,8 @@ class Job {
var stderr = '';
var output = '';
var start_time = new Date().getTime();
const proc = cp.spawn(proc_call[0], proc_call.splice(1), {
env: {
...this.runtime.env_vars,
@ -265,14 +276,48 @@ class Job {
proc.on('close', (code, signal) => {
this.close_cleanup();
resolve({ stdout, stderr, code, signal, output });
if (stderr.length > 0) {
var stats = stderr.trim().split('\n').slice(-1).join('\n').split(' ');
stderr = stderr.trim().split('\n').slice(0, -1).join('\n');
output = output.trim().split('\n').slice(0, -1).join('\n');
stats = {
'elapsed_time': stats[0],
'cpu_time': stats[1] + ' / ' + stats[2],
'max_mem': stats[3],
}
}
var end_time = new Date().getTime();
var exec_time = end_time - start_time;
this.logger.debug(`Stats:`, stats);
resolve({ stdout, stderr, code, signal, output, stats, exec_time });
});
proc.on('error', err => {
this.exit_cleanup();
this.close_cleanup();
reject({ error: err, stdout, stderr, output });
if (stderr.length > 0) {
var stats = stderr.trim().split('\n').slice(-1).join('\n').split(' ');
stderr = stderr.trim().split('\n').slice(0, -1).join('\n');
output = output.trim().split('\n').slice(0, -1).join('\n');
stats = {
'elapsed_time': stats[0],
'cpu_time': stats[1] + ' / ' + stats[2],
'max_mem': stats[3],
}
}
var end_time = new Date().getTime();
var exec_time = end_time - start_time;
this.logger.debug(`Stats:`, stats);
reject({ error: err, stdout, stderr, output, stats, exec_time });
});
});
}

View File

@ -12,13 +12,14 @@ services:
volumes:
- ./data/piston/packages:/piston/packages
environment:
- PISTON_REPO_URL=http://repo:8000/index
- PISTON_REPO_URL=https://github.com/engineer-man/piston/releases/download/pkgs/index
tmpfs:
- /piston/jobs:exec,uid=1000,gid=1000,mode=711
repo: # Local testing of packages
repo:
# Local testing of packages
build: repo
container_name: piston_repo
command: ['--no-build'] # Don't build anything
command: [ '--no-build' ] # Don't build anything
volumes:
- .:/piston