From 868154b440e70a851b927bffc3e57181c609a04c Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Wed, 4 Dec 2024 06:30:44 -0500 Subject: [PATCH] feat(executor/local): full result state --- internal/executor/local/executor.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/executor/local/executor.go b/internal/executor/local/executor.go index 8e47c4a..2e94fcc 100644 --- a/internal/executor/local/executor.go +++ b/internal/executor/local/executor.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "strings" + "syscall" "time" "github.com/criyle/go-judge/envexec" @@ -52,11 +53,31 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { err = execCmd.Wait() endTime := time.Now() runTime := endTime.Sub(startTime) - + processState := execCmd.ProcessState result := stage.ExecutorResult{ Status: stage.Status(envexec.StatusAccepted), - ExitStatus: 0, + ExitStatus: processState.ExitCode(), Error: "", + Time: func() uint64 { + nanos := processState.UserTime().Nanoseconds() + if nanos < 0 { + return 0 + } + return uint64(nanos) + }(), + Memory: func() uint64 { + usage := processState.SysUsage() + rusage, ok := usage.(*syscall.Rusage) + if !ok { + return 0 + } + maxRssKB := rusage.Maxrss + maxRssBytes := maxRssKB * 1024 + if maxRssBytes < 0 { + return 0 + } + return uint64(maxRssBytes) + }(), RunTime: func() uint64 { nanos := runTime.Nanoseconds() if nanos < 0 { @@ -70,7 +91,6 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { if err != nil { if exitErr, ok := err.(*exec.ExitError); ok { - result.ExitStatus = exitErr.ExitCode() result.Status = stage.Status(envexec.StatusNonzeroExitStatus) result.Error = exitErr.Error() } else {