mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-09-26 23:19:11 +08:00
Compare commits
2 Commits
c316900c2c
...
ea0b084794
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ea0b084794 | ||
![]() |
98f24cf60a |
@ -430,26 +430,39 @@ func start() (*runner.Result, error) {
|
||||
cpu, err := cg.CPUUsage()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cgroup cpu: %v", err)
|
||||
} else {
|
||||
rt.Time = time.Duration(cpu)
|
||||
}
|
||||
// max memory usage may not exist in cgroup v2
|
||||
memory, err := cg.MemoryMaxUsage()
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, fmt.Errorf("cgroup memory: %v", err)
|
||||
} else if err == nil {
|
||||
rt.Memory = runner.Size(memory)
|
||||
}
|
||||
procPeak, err := cg.ProcessPeak()
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, fmt.Errorf("cgroup pid: %v", err)
|
||||
}
|
||||
debug("cgroup: cpu: ", cpu, " memory: ", memory, " procPeak: ", procPeak)
|
||||
rt.Time = time.Duration(cpu)
|
||||
if memory > 0 {
|
||||
rt.Memory = runner.Size(memory)
|
||||
}
|
||||
if procPeak > 0 {
|
||||
} else if err == nil {
|
||||
rt.ProcPeak = procPeak
|
||||
}
|
||||
debug("cgroup: cpu: ", cpu, " memory: ", memory, " procPeak: ", procPeak)
|
||||
debug("cgroup:", rt)
|
||||
}
|
||||
if rt.Status == runner.StatusTimeLimitExceeded || rt.Status == runner.StatusNormal {
|
||||
if rt.Time > limit.TimeLimit {
|
||||
rt.Status = runner.StatusTimeLimitExceeded
|
||||
} else {
|
||||
rt.Status = runner.StatusNormal
|
||||
}
|
||||
}
|
||||
if rt.Status == runner.StatusMemoryLimitExceeded || rt.Status == runner.StatusNormal {
|
||||
if rt.Memory > limit.MemoryLimit {
|
||||
rt.Status = runner.StatusMemoryLimitExceeded
|
||||
} else {
|
||||
rt.Status = runner.StatusNormal
|
||||
}
|
||||
}
|
||||
return &rt, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user