mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
add trace time metrics
This commit is contained in:
parent
b7b6f78f64
commit
beab51c98c
@ -58,6 +58,8 @@ func (r *RunUnshared) Trace(runner *forkexec.Runner) (result tracer.TraceResult,
|
|||||||
rusage unix.Rusage // wait4 rusage
|
rusage unix.Rusage // wait4 rusage
|
||||||
tle = false
|
tle = false
|
||||||
status = tracer.TraceCodeNormal
|
status = tracer.TraceCodeNormal
|
||||||
|
sTime = time.Now().UnixNano() // start time
|
||||||
|
fTime int64 // finish time for setup
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start the runner
|
// Start the runner
|
||||||
@ -81,10 +83,15 @@ func (r *RunUnshared) Trace(runner *forkexec.Runner) (result tracer.TraceResult,
|
|||||||
// kill all tracee upon return
|
// kill all tracee upon return
|
||||||
killAll(pgid)
|
killAll(pgid)
|
||||||
collectZombie(pgid)
|
collectZombie(pgid)
|
||||||
|
result.TraceStat.SetUpTime = fTime - sTime
|
||||||
|
result.RunningTime = time.Now().UnixNano() - fTime
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
pid, err := unix.Wait4(pgid, &wstatus, unix.WALL, &rusage)
|
pid, err := unix.Wait4(pgid, &wstatus, unix.WALL, &rusage)
|
||||||
|
if fTime == 0 {
|
||||||
|
fTime = time.Now().UnixNano()
|
||||||
|
}
|
||||||
r.println("wait4: ", wstatus)
|
r.println("wait4: ", wstatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, tracer.TraceCodeFatal
|
return result, tracer.TraceCodeFatal
|
||||||
|
|||||||
@ -48,12 +48,19 @@ func (t TraceCode) Error() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TraceStat is the time usages in ns
|
||||||
|
type TraceStat struct {
|
||||||
|
SetUpTime int64
|
||||||
|
RunningTime int64
|
||||||
|
}
|
||||||
|
|
||||||
// TraceResult is the result returned by strat trace
|
// TraceResult is the result returned by strat trace
|
||||||
type TraceResult struct {
|
type TraceResult struct {
|
||||||
UserTime uint64 // used user CPU time (in ms)
|
UserTime uint64 // used user CPU time (in ms)
|
||||||
UserMem uint64 // used user memory (in kb)
|
UserMem uint64 // used user memory (in kb)
|
||||||
ExitCode int // exit code
|
ExitCode int // exit code
|
||||||
TraceStatus TraceCode // the final status for the process
|
TraceStatus TraceCode // the final status for the process
|
||||||
|
TraceStat // collects time for the process
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runner represents the process runner
|
// Runner represents the process runner
|
||||||
|
|||||||
@ -26,6 +26,8 @@ func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult,
|
|||||||
execved = false // store whether the runner process have successfully execvd
|
execved = false // store whether the runner process have successfully execvd
|
||||||
pid int // store pid of wait4 result
|
pid int // store pid of wait4 result
|
||||||
initMem uint64 // initial memory usage (likely due to original process)
|
initMem uint64 // initial memory usage (likely due to original process)
|
||||||
|
sTime = time.Now().UnixNano() // records start time for trace process
|
||||||
|
fTime int64 // records finish time for execve
|
||||||
)
|
)
|
||||||
|
|
||||||
// ptrace is thread based (kernel proc)
|
// ptrace is thread based (kernel proc)
|
||||||
@ -61,6 +63,8 @@ func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult,
|
|||||||
// kill all tracee upon return
|
// kill all tracee upon return
|
||||||
killAll(pgid)
|
killAll(pgid)
|
||||||
collectZombie(pgid)
|
collectZombie(pgid)
|
||||||
|
result.TraceStat.SetUpTime = fTime - sTime
|
||||||
|
result.RunningTime = time.Now().UnixNano() - fTime
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// trace unixs
|
// trace unixs
|
||||||
@ -175,7 +179,10 @@ func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult,
|
|||||||
handler.Debug("ptrace stop fork")
|
handler.Debug("ptrace stop fork")
|
||||||
case unix.PTRACE_EVENT_EXEC:
|
case unix.PTRACE_EVENT_EXEC:
|
||||||
// forked tracee have successfully called execve
|
// forked tracee have successfully called execve
|
||||||
|
if !execved {
|
||||||
|
fTime = time.Now().UnixNano()
|
||||||
execved = true
|
execved = true
|
||||||
|
}
|
||||||
handler.Debug("ptrace stop exec")
|
handler.Debug("ptrace stop exec")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user