add trace time metrics

This commit is contained in:
criyle 2019-07-14 18:48:32 -07:00
parent b7b6f78f64
commit beab51c98c
3 changed files with 29 additions and 8 deletions

View File

@ -58,6 +58,8 @@ func (r *RunUnshared) Trace(runner *forkexec.Runner) (result tracer.TraceResult,
rusage unix.Rusage // wait4 rusage
tle = false
status = tracer.TraceCodeNormal
sTime = time.Now().UnixNano() // start time
fTime int64 // finish time for setup
)
// Start the runner
@ -81,10 +83,15 @@ func (r *RunUnshared) Trace(runner *forkexec.Runner) (result tracer.TraceResult,
// kill all tracee upon return
killAll(pgid)
collectZombie(pgid)
result.TraceStat.SetUpTime = fTime - sTime
result.RunningTime = time.Now().UnixNano() - fTime
}()
for {
pid, err := unix.Wait4(pgid, &wstatus, unix.WALL, &rusage)
if fTime == 0 {
fTime = time.Now().UnixNano()
}
r.println("wait4: ", wstatus)
if err != nil {
return result, tracer.TraceCodeFatal

View File

@ -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
type TraceResult struct {
UserTime uint64 // used user CPU time (in ms)
UserMem uint64 // used user memory (in kb)
ExitCode int // exit code
TraceStatus TraceCode // the final status for the process
TraceStat // collects time for the process
}
// Runner represents the process runner

View File

@ -19,13 +19,15 @@ const (
// exec tracee
func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult, err error) {
var (
wstatus unix.WaitStatus // wait4 wait status
rusage unix.Rusage // wait4 rusage
tle bool // whether the timmer triggered due to timeout
traced = make(map[int]bool) // store all process that have set ptrace options
execved = false // store whether the runner process have successfully execvd
pid int // store pid of wait4 result
initMem uint64 // initial memory usage (likely due to original process)
wstatus unix.WaitStatus // wait4 wait status
rusage unix.Rusage // wait4 rusage
tle bool // whether the timmer triggered due to timeout
traced = make(map[int]bool) // store all process that have set ptrace options
execved = false // store whether the runner process have successfully execvd
pid int // store pid of wait4 result
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)
@ -61,6 +63,8 @@ func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult,
// kill all tracee upon return
killAll(pgid)
collectZombie(pgid)
result.TraceStat.SetUpTime = fTime - sTime
result.RunningTime = time.Now().UnixNano() - fTime
}()
// trace unixs
@ -175,7 +179,10 @@ func Trace(handler Handler, runner Runner, limits ResLimit) (result TraceResult,
handler.Debug("ptrace stop fork")
case unix.PTRACE_EVENT_EXEC:
// forked tracee have successfully called execve
execved = true
if !execved {
fTime = time.Now().UnixNano()
execved = true
}
handler.Debug("ptrace stop exec")
default: