feat(runner): mle
This commit is contained in:
parent
5fdb522095
commit
0061161a90
1 changed files with 20 additions and 8 deletions
|
|
@ -63,7 +63,7 @@ function M.compile(language_config, substitutions)
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parse_and_strip_time_v(output, memory_mb)
|
local function parse_and_strip_time_v(output)
|
||||||
local lines = vim.split(output or '', '\n', { plain = true })
|
local lines = vim.split(output or '', '\n', { plain = true })
|
||||||
|
|
||||||
local timing_idx
|
local timing_idx
|
||||||
|
|
@ -81,14 +81,11 @@ local function parse_and_strip_time_v(output, memory_mb)
|
||||||
k = k - 1
|
k = k - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local peak_mb, mled = 0, false
|
local peak_mb = 0
|
||||||
for j = timing_idx, #lines do
|
for j = timing_idx, #lines do
|
||||||
local kb = lines[j]:match('Maximum resident set size %(kbytes%):%s*(%d+)')
|
local kb = lines[j]:match('Maximum resident set size %(kbytes%):%s*(%d+)')
|
||||||
if kb then
|
if kb then
|
||||||
peak_mb = tonumber(kb) / 1024.0
|
peak_mb = tonumber(kb) / 1024.0
|
||||||
if memory_mb and memory_mb > 0 and peak_mb > memory_mb then
|
|
||||||
mled = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -100,7 +97,7 @@ local function parse_and_strip_time_v(output, memory_mb)
|
||||||
table.remove(lines, #lines)
|
table.remove(lines, #lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(lines, '\n'), peak_mb, mled
|
return table.concat(lines, '\n'), peak_mb
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run(cmd, stdin, timeout_ms, memory_mb)
|
function M.run(cmd, stdin, timeout_ms, memory_mb)
|
||||||
|
|
@ -125,7 +122,7 @@ function M.run(cmd, stdin, timeout_ms, memory_mb)
|
||||||
|
|
||||||
local code = r.code or 0
|
local code = r.code or 0
|
||||||
local raw = r.stdout or ''
|
local raw = r.stdout or ''
|
||||||
local cleaned, peak_mb, mled = parse_and_strip_time_v(raw, memory_mb)
|
local cleaned, peak_mb = parse_and_strip_time_v(raw)
|
||||||
local tled = (code == 124)
|
local tled = (code == 124)
|
||||||
|
|
||||||
local signal = nil
|
local signal = nil
|
||||||
|
|
@ -133,8 +130,23 @@ function M.run(cmd, stdin, timeout_ms, memory_mb)
|
||||||
signal = constants.signal_codes[code]
|
signal = constants.signal_codes[code]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lower = (cleaned or ''):lower()
|
||||||
|
local oom_hint = lower:find('std::bad_alloc', 1, true)
|
||||||
|
or lower:find('cannot allocate memory', 1, true)
|
||||||
|
or lower:find('enomem', 1, true)
|
||||||
|
|
||||||
|
local near_cap = false
|
||||||
|
if memory_mb and memory_mb > 0 then
|
||||||
|
near_cap = (peak_mb >= (0.90 * memory_mb))
|
||||||
|
end
|
||||||
|
|
||||||
|
local mled = false
|
||||||
|
if peak_mb >= memory_mb or (code ~= 0 and not tled) and (near_cap or oom_hint) or code == 137 then
|
||||||
|
mled = true
|
||||||
|
end
|
||||||
|
|
||||||
if tled then
|
if tled then
|
||||||
logger.log(('Execution timed out in %.1fms.'):format(dt), vim.log.levels.WARN)
|
logger.log(('Execution timed out in %.1fms.'):format(dt))
|
||||||
elseif mled then
|
elseif mled then
|
||||||
logger.log(('Execution memory limit exceeded in %.1fms.'):format(dt))
|
logger.log(('Execution memory limit exceeded in %.1fms.'):format(dt))
|
||||||
elseif code ~= 0 then
|
elseif code ~= 0 then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue