add rss to table
This commit is contained in:
parent
bfcf2242ee
commit
357d1601b4
2 changed files with 67 additions and 33 deletions
|
|
@ -14,6 +14,7 @@
|
||||||
---@field signal string?
|
---@field signal string?
|
||||||
---@field tled boolean?
|
---@field tled boolean?
|
||||||
---@field mled boolean?
|
---@field mled boolean?
|
||||||
|
---@field rss_mb number
|
||||||
|
|
||||||
---@class ProblemConstraints
|
---@class ProblemConstraints
|
||||||
---@field timeout_ms number
|
---@field timeout_ms number
|
||||||
|
|
@ -44,6 +45,10 @@ local run_panel_state = {
|
||||||
constraints = nil,
|
constraints = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param platform string
|
||||||
|
---@param contest_id string
|
||||||
|
---@param problem_id string|nil
|
||||||
|
---@return ProblemConstraints|nil
|
||||||
local function load_constraints_from_cache(platform, contest_id, problem_id)
|
local function load_constraints_from_cache(platform, contest_id, problem_id)
|
||||||
cache.load()
|
cache.load()
|
||||||
local timeout_ms, memory_mb = cache.get_constraints(platform, contest_id, problem_id)
|
local timeout_ms, memory_mb = cache.get_constraints(platform, contest_id, problem_id)
|
||||||
|
|
@ -53,6 +58,8 @@ local function load_constraints_from_cache(platform, contest_id, problem_id)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param test_cases TestCase[]
|
||||||
|
---@return RanTestCase[]
|
||||||
local function create_sentinal_panel_data(test_cases)
|
local function create_sentinal_panel_data(test_cases)
|
||||||
local out = {}
|
local out = {}
|
||||||
for i, tc in ipairs(test_cases) do
|
for i, tc in ipairs(test_cases) do
|
||||||
|
|
@ -67,11 +74,18 @@ local function create_sentinal_panel_data(test_cases)
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param language_config LanguageConfig
|
||||||
|
---@param substitutions table<string, string>
|
||||||
|
---@return string[]
|
||||||
local function build_command(language_config, substitutions)
|
local function build_command(language_config, substitutions)
|
||||||
local exec_util = require('cp.runner.execute')._util
|
local exec_util = require('cp.runner.execute')._util
|
||||||
return exec_util.build_command(language_config.test, language_config.executable, substitutions)
|
return exec_util.build_command(language_config.test, language_config.executable, substitutions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param contest_config ContestConfig
|
||||||
|
---@param cp_config cp.Config
|
||||||
|
---@param test_case RanTestCase
|
||||||
|
---@return { status: "pass"|"fail"|"tle"|"mle", actual: string, actual_highlights: Highlight[], error: string, stderr: string, time_ms: number, code: integer, ok: boolean, signal: string, tled: boolean, mled: boolean, rss_mb: number }
|
||||||
local function run_single_test_case(contest_config, cp_config, test_case)
|
local function run_single_test_case(contest_config, cp_config, test_case)
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
local exec = require('cp.runner.execute')
|
local exec = require('cp.runner.execute')
|
||||||
|
|
@ -96,6 +110,7 @@ local function run_single_test_case(contest_config, cp_config, test_case)
|
||||||
error = 'Compilation failed',
|
error = 'Compilation failed',
|
||||||
stderr = clean,
|
stderr = clean,
|
||||||
time_ms = 0,
|
time_ms = 0,
|
||||||
|
rss_mb = 0,
|
||||||
code = cr.code,
|
code = cr.code,
|
||||||
ok = false,
|
ok = false,
|
||||||
signal = nil,
|
signal = nil,
|
||||||
|
|
@ -161,7 +176,7 @@ local function run_single_test_case(contest_config, cp_config, test_case)
|
||||||
status = status,
|
status = status,
|
||||||
actual = out,
|
actual = out,
|
||||||
actual_highlights = highlights,
|
actual_highlights = highlights,
|
||||||
error = (r.code ~= 0 and not ok) and out or nil,
|
error = (r.code ~= 0 and not ok) and out or '',
|
||||||
stderr = '',
|
stderr = '',
|
||||||
time_ms = r.time_ms,
|
time_ms = r.time_ms,
|
||||||
code = r.code,
|
code = r.code,
|
||||||
|
|
@ -169,9 +184,12 @@ local function run_single_test_case(contest_config, cp_config, test_case)
|
||||||
signal = signal,
|
signal = signal,
|
||||||
tled = r.tled or false,
|
tled = r.tled or false,
|
||||||
mled = r.mled or false,
|
mled = r.mled or false,
|
||||||
|
rss_mb = r.peak_mb,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param state table
|
||||||
|
---@return boolean
|
||||||
function M.load_test_cases(state)
|
function M.load_test_cases(state)
|
||||||
local tcs = cache.get_test_cases(
|
local tcs = cache.get_test_cases(
|
||||||
state.get_platform() or '',
|
state.get_platform() or '',
|
||||||
|
|
@ -191,6 +209,10 @@ function M.load_test_cases(state)
|
||||||
return #tcs > 0
|
return #tcs > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param contest_config ContestConfig
|
||||||
|
---@param cp_config cp.Config
|
||||||
|
---@param index number
|
||||||
|
---@return boolean
|
||||||
function M.run_test_case(contest_config, cp_config, index)
|
function M.run_test_case(contest_config, cp_config, index)
|
||||||
local tc = run_panel_state.test_cases[index]
|
local tc = run_panel_state.test_cases[index]
|
||||||
if not tc then
|
if not tc then
|
||||||
|
|
@ -211,10 +233,14 @@ function M.run_test_case(contest_config, cp_config, index)
|
||||||
tc.signal = r.signal
|
tc.signal = r.signal
|
||||||
tc.tled = r.tled
|
tc.tled = r.tled
|
||||||
tc.mled = r.mled
|
tc.mled = r.mled
|
||||||
|
tc.rss_mb = r.rss_mb
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param contest_config ContestConfig
|
||||||
|
---@param cp_config cp.Config
|
||||||
|
---@return RanTestCase[]
|
||||||
function M.run_all_test_cases(contest_config, cp_config)
|
function M.run_all_test_cases(contest_config, cp_config)
|
||||||
local results = {}
|
local results = {}
|
||||||
for i = 1, #run_panel_state.test_cases do
|
for i = 1, #run_panel_state.test_cases do
|
||||||
|
|
@ -224,11 +250,14 @@ function M.run_all_test_cases(contest_config, cp_config)
|
||||||
return results
|
return results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return RunPanelState
|
||||||
function M.get_run_panel_state()
|
function M.get_run_panel_state()
|
||||||
return run_panel_state
|
return run_panel_state
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.handle_compilation_failure(compilation_output)
|
---@param output string|nil
|
||||||
|
---@return nil
|
||||||
|
function M.handle_compilation_failure(output)
|
||||||
local ansi = require('cp.ui.ansi')
|
local ansi = require('cp.ui.ansi')
|
||||||
local config = require('cp.config').setup()
|
local config = require('cp.config').setup()
|
||||||
|
|
||||||
|
|
@ -236,11 +265,11 @@ function M.handle_compilation_failure(compilation_output)
|
||||||
local hl = {}
|
local hl = {}
|
||||||
|
|
||||||
if config.run_panel.ansi then
|
if config.run_panel.ansi then
|
||||||
local p = ansi.parse_ansi_text(compilation_output or '')
|
local p = ansi.parse_ansi_text(output or '')
|
||||||
txt = table.concat(p.lines, '\n')
|
txt = table.concat(p.lines, '\n')
|
||||||
hl = p.highlights
|
hl = p.highlights
|
||||||
else
|
else
|
||||||
txt = (compilation_output or ''):gsub('\027%[[%d;]*[a-zA-Z]', '')
|
txt = (output or ''):gsub('\027%[[%d;]*[a-zA-Z]', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, tc in ipairs(run_panel_state.test_cases) do
|
for _, tc in ipairs(run_panel_state.test_cases) do
|
||||||
|
|
@ -252,7 +281,7 @@ function M.handle_compilation_failure(compilation_output)
|
||||||
tc.time_ms = 0
|
tc.time_ms = 0
|
||||||
tc.code = 1
|
tc.code = 1
|
||||||
tc.ok = false
|
tc.ok = false
|
||||||
tc.signal = nil
|
tc.signal = ''
|
||||||
tc.tled = false
|
tc.tled = false
|
||||||
tc.mled = false
|
tc.mled = false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,16 @@ local function format_exit_code(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compute_cols(test_state)
|
local function compute_cols(test_state)
|
||||||
local w = { num = 5, status = 8, time = 6, timeout = 8, memory = 8, exit = 11 }
|
local w = { num = 5, status = 8, time = 6, timeout = 8, rss = 8, memory = 8, exit = 11 }
|
||||||
|
|
||||||
local timeout_str = ''
|
local timeout_str = '—'
|
||||||
local memory_str = ''
|
local memory_str = '—'
|
||||||
if test_state.constraints then
|
if test_state.constraints then
|
||||||
timeout_str = tostring(test_state.constraints.timeout_ms)
|
timeout_str = tostring(test_state.constraints.timeout_ms)
|
||||||
memory_str = string.format('%.0f', test_state.constraints.memory_mb)
|
memory_str = string.format('%.0f', test_state.constraints.memory_mb)
|
||||||
else
|
|
||||||
timeout_str = '—'
|
|
||||||
memory_str = '—'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.print(test_state)
|
||||||
for i, tc in ipairs(test_state.test_cases) do
|
for i, tc in ipairs(test_state.test_cases) do
|
||||||
local prefix = (i == test_state.current_index) and '>' or ' '
|
local prefix = (i == test_state.current_index) and '>' or ' '
|
||||||
w.num = math.max(w.num, #(' ' .. prefix .. i .. ' '))
|
w.num = math.max(w.num, #(' ' .. prefix .. i .. ' '))
|
||||||
|
|
@ -73,6 +71,8 @@ local function compute_cols(test_state)
|
||||||
local time_str = tc.time_ms and string.format('%.2f', tc.time_ms) or '—'
|
local time_str = tc.time_ms and string.format('%.2f', tc.time_ms) or '—'
|
||||||
w.time = math.max(w.time, #(' ' .. time_str .. ' '))
|
w.time = math.max(w.time, #(' ' .. time_str .. ' '))
|
||||||
w.timeout = math.max(w.timeout, #(' ' .. timeout_str .. ' '))
|
w.timeout = math.max(w.timeout, #(' ' .. timeout_str .. ' '))
|
||||||
|
local rss_str = (tc.rss_mb and string.format('%.0f', tc.rss_mb)) or '—'
|
||||||
|
w.rss = math.max(w.rss, #(' ' .. rss_str .. ' '))
|
||||||
w.memory = math.max(w.memory, #(' ' .. memory_str .. ' '))
|
w.memory = math.max(w.memory, #(' ' .. memory_str .. ' '))
|
||||||
w.exit = math.max(w.exit, #(' ' .. format_exit_code(tc.code) .. ' '))
|
w.exit = math.max(w.exit, #(' ' .. format_exit_code(tc.code) .. ' '))
|
||||||
end
|
end
|
||||||
|
|
@ -81,11 +81,12 @@ local function compute_cols(test_state)
|
||||||
w.status = math.max(w.status, #' Status ')
|
w.status = math.max(w.status, #' Status ')
|
||||||
w.time = math.max(w.time, #' Runtime (ms) ')
|
w.time = math.max(w.time, #' Runtime (ms) ')
|
||||||
w.timeout = math.max(w.timeout, #' Time (ms) ')
|
w.timeout = math.max(w.timeout, #' Time (ms) ')
|
||||||
|
w.rss = math.max(w.rss, #' RSS (MB) ')
|
||||||
w.memory = math.max(w.memory, #' Mem (MB) ')
|
w.memory = math.max(w.memory, #' Mem (MB) ')
|
||||||
w.exit = math.max(w.exit, #' Exit Code ')
|
w.exit = math.max(w.exit, #' Exit Code ')
|
||||||
|
|
||||||
local sum = w.num + w.status + w.time + w.timeout + w.memory + w.exit
|
local sum = w.num + w.status + w.time + w.timeout + w.rss + w.memory + w.exit
|
||||||
local inner = sum + 5
|
local inner = sum + 6
|
||||||
local total = inner + 2
|
local total = inner + 2
|
||||||
return { w = w, sum = sum, inner = inner, total = total }
|
return { w = w, sum = sum, inner = inner, total = total }
|
||||||
end
|
end
|
||||||
|
|
@ -99,15 +100,6 @@ local function center(text, width)
|
||||||
return string.rep(' ', left) .. text .. string.rep(' ', pad - left)
|
return string.rep(' ', left) .. text .. string.rep(' ', pad - left)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function right_align(text, width)
|
|
||||||
local content = (' %s '):format(text)
|
|
||||||
local pad = width - #content
|
|
||||||
if pad <= 0 then
|
|
||||||
return content
|
|
||||||
end
|
|
||||||
return string.rep(' ', pad) .. content
|
|
||||||
end
|
|
||||||
|
|
||||||
local function format_num_column(prefix, idx, width)
|
local function format_num_column(prefix, idx, width)
|
||||||
local num_str = tostring(idx)
|
local num_str = tostring(idx)
|
||||||
local content
|
local content
|
||||||
|
|
@ -136,6 +128,8 @@ local function top_border(c)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
.. string.rep('─', w.timeout)
|
.. string.rep('─', w.timeout)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
|
.. string.rep('─', w.rss)
|
||||||
|
.. '┬'
|
||||||
.. string.rep('─', w.memory)
|
.. string.rep('─', w.memory)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
.. string.rep('─', w.exit)
|
.. string.rep('─', w.exit)
|
||||||
|
|
@ -153,6 +147,8 @@ local function row_sep(c)
|
||||||
.. '┼'
|
.. '┼'
|
||||||
.. string.rep('─', w.timeout)
|
.. string.rep('─', w.timeout)
|
||||||
.. '┼'
|
.. '┼'
|
||||||
|
.. string.rep('─', w.rss)
|
||||||
|
.. '┼'
|
||||||
.. string.rep('─', w.memory)
|
.. string.rep('─', w.memory)
|
||||||
.. '┼'
|
.. '┼'
|
||||||
.. string.rep('─', w.exit)
|
.. string.rep('─', w.exit)
|
||||||
|
|
@ -170,6 +166,8 @@ local function bottom_border(c)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
.. string.rep('─', w.timeout)
|
.. string.rep('─', w.timeout)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
|
.. string.rep('─', w.rss)
|
||||||
|
.. '┴'
|
||||||
.. string.rep('─', w.memory)
|
.. string.rep('─', w.memory)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
.. string.rep('─', w.exit)
|
.. string.rep('─', w.exit)
|
||||||
|
|
@ -187,6 +185,8 @@ local function flat_fence_above(c)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
.. string.rep('─', w.timeout)
|
.. string.rep('─', w.timeout)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
|
.. string.rep('─', w.rss)
|
||||||
|
.. '┴'
|
||||||
.. string.rep('─', w.memory)
|
.. string.rep('─', w.memory)
|
||||||
.. '┴'
|
.. '┴'
|
||||||
.. string.rep('─', w.exit)
|
.. string.rep('─', w.exit)
|
||||||
|
|
@ -204,6 +204,8 @@ local function flat_fence_below(c)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
.. string.rep('─', w.timeout)
|
.. string.rep('─', w.timeout)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
|
.. string.rep('─', w.rss)
|
||||||
|
.. '┬'
|
||||||
.. string.rep('─', w.memory)
|
.. string.rep('─', w.memory)
|
||||||
.. '┬'
|
.. '┬'
|
||||||
.. string.rep('─', w.exit)
|
.. string.rep('─', w.exit)
|
||||||
|
|
@ -225,6 +227,8 @@ local function header_line(c)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. center('Time (ms)', w.timeout)
|
.. center('Time (ms)', w.timeout)
|
||||||
.. '│'
|
.. '│'
|
||||||
|
.. center('RSS (MB)', w.rss)
|
||||||
|
.. '│'
|
||||||
.. center('Mem (MB)', w.memory)
|
.. center('Mem (MB)', w.memory)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. center('Exit Code', w.exit)
|
.. center('Exit Code', w.exit)
|
||||||
|
|
@ -238,33 +242,34 @@ local function data_row(c, idx, tc, is_current, test_state)
|
||||||
local time = tc.time_ms and string.format('%.2f', tc.time_ms) or '—'
|
local time = tc.time_ms and string.format('%.2f', tc.time_ms) or '—'
|
||||||
local exit = format_exit_code(tc.code)
|
local exit = format_exit_code(tc.code)
|
||||||
|
|
||||||
local timeout = ''
|
local timeout = '—'
|
||||||
local memory = ''
|
local memory = '—'
|
||||||
if test_state.constraints then
|
if test_state.constraints then
|
||||||
timeout = tostring(test_state.constraints.timeout_ms)
|
timeout = tostring(test_state.constraints.timeout_ms)
|
||||||
memory = string.format('%.0f', test_state.constraints.memory_mb)
|
memory = string.format('%.0f', test_state.constraints.memory_mb)
|
||||||
else
|
|
||||||
timeout = '—'
|
|
||||||
memory = '—'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local rss = (tc.rss_mb and string.format('%.0f', tc.rss_mb)) or '—'
|
||||||
|
|
||||||
local line = '│'
|
local line = '│'
|
||||||
.. format_num_column(prefix, idx, w.num)
|
.. format_num_column(prefix, idx, w.num)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. right_align(status.text, w.status)
|
.. center(status.text, w.status)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. right_align(time, w.time)
|
.. center(time, w.time)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. right_align(timeout, w.timeout)
|
.. center(timeout, w.timeout)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. right_align(memory, w.memory)
|
.. center(rss, w.rss)
|
||||||
.. '│'
|
.. '│'
|
||||||
.. right_align(exit, w.exit)
|
.. center(memory, w.memory)
|
||||||
|
.. '│'
|
||||||
|
.. center(exit, w.exit)
|
||||||
.. '│'
|
.. '│'
|
||||||
|
|
||||||
local hi
|
local hi
|
||||||
if status.text ~= '' then
|
if status.text ~= '' then
|
||||||
local status_pos = line:find(status.text)
|
local status_pos = line:find(status.text, 1, true)
|
||||||
if status_pos then
|
if status_pos then
|
||||||
hi = {
|
hi = {
|
||||||
col_start = status_pos - 1,
|
col_start = status_pos - 1,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue