package daemon

import (
	"sync"
	"time"
)

// RunStat keeps the statistics of the running process
type RunStat struct {
	sync.RWMutex
	LastStartTime      time.Time     `json:"last_start_time"`
	LastEndTime        time.Time     `json:"last_end_time"`
	LastUpTime         time.Duration `json:"last_up_time"`
	LastUserTime       time.Duration `json:"last_user_time"`
	LastSysTime        time.Duration `json:"last_sys_time"`
	LastTerminateState ProcessState  `json:"last_terminate_time"`
	LastExitErr        string        `json:"last_exit_err"`
	StartTime          time.Time     `json:"start_time"`
	RunCount           uint32        `json:"run_count"`
	StoppedCount       uint32        `json:"stopped_count"`
	ExitedCount        uint32        `json:"exited_count"`
	KilledCount        uint32        `json:"killed_count"`
	Pid                int           `json:"pid"`
}

// GetRunningStat return a RunStat Object containing the statistics of the daemon runtime
func (d *Daemon) GetRunningStat() *RunStat {
	d.runStat.Lock()
	defer d.runStat.Unlock()
	return &RunStat{
		LastStartTime:      d.runStat.LastStartTime,
		LastEndTime:        d.runStat.LastEndTime,
		LastUpTime:         d.runStat.LastUpTime,
		LastUserTime:       d.runStat.LastUserTime,
		LastSysTime:        d.runStat.LastSysTime,
		LastTerminateState: d.runStat.LastTerminateState,
		LastExitErr:        d.runStat.LastExitErr,
		StartTime:          d.runStat.StartTime,
		RunCount:           d.runStat.RunCount,
		StoppedCount:       d.runStat.StoppedCount,
		ExitedCount:        d.runStat.ExitedCount,
		KilledCount:        d.runStat.KilledCount,
		Pid:                d.runStat.Pid,
	}
}
