Implement CreateTime for darwin. Parses elapsed time and converts this to epoch time.

This commit is contained in:
Tom Elliott 2016-08-20 23:12:29 -04:00
parent 2eb8f8bff8
commit 3855e7ba0e
1 changed files with 29 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"syscall"
"time"
"unsafe"
"github.com/shirou/gopsutil/cpu"
@ -105,7 +106,34 @@ func (p *Process) CmdlineSlice() ([]string, error) {
return r[0], err
}
func (p *Process) CreateTime() (int64, error) {
return 0, common.ErrNotImplementedError
r, err := callPs("etime", p.Pid, false)
if err != nil {
return 0, err
}
elapsedSegments := strings.Split(r[0][0], ":")
var elapsedDurations []time.Duration
for i := len(elapsedSegments) - 1; i >= 0; i-- {
p, err := strconv.ParseInt(elapsedSegments[i], 10, 0)
if err != nil {
return 0, err
}
elapsedDurations = append(elapsedDurations, time.Duration(p))
}
var elapsed time.Duration = time.Duration(elapsedDurations[0]) * time.Second
if len(elapsedDurations) > 1 {
elapsed += time.Duration(elapsedDurations[1]) * time.Minute
}
if len(elapsedDurations) > 2 {
elapsed += time.Duration(elapsedDurations[2]) * time.Hour
}
if len(elapsedDurations) > 3 {
elapsed += time.Duration(elapsedDurations[3]) * time.Hour * 24
}
start := time.Now().Add(-elapsed)
return start.Unix() * 1000, nil
}
func (p *Process) Cwd() (string, error) {
return "", common.ErrNotImplementedError