From cf5660bfd33d1e809818a0de4cfb0ed27b850f42 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 28 Sep 2015 16:18:53 +0100 Subject: [PATCH] process[linux]: calculate the CreateTime and then convert to microseconds --- process/process_linux.go | 4 ++-- process/process_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index e108518..692329f 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -596,8 +596,8 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32 if err != nil { return "", 0, nil, 0, 0, err } - ctime := (t / uint64(ClockTicks)) + uint64(bootTime)*1000 - createTime := int64(ctime) + ctime := (t / uint64(ClockTicks)) + uint64(bootTime) + createTime := int64(ctime * 1000) // p.Nice = mustParseInt32(fields[18]) // use syscall instead of parse Stat file diff --git a/process/process_test.go b/process/process_test.go index 3d6ee34..854d63c 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -270,9 +270,17 @@ func Test_Process_CreateTime(t *testing.T) { if err != nil { t.Errorf("error %v", err) } + if c < 1420000000 { t.Errorf("process created time is wrong.") } + + gotElapsed := time.Since(time.Unix(int64(c/1000), 0)) + maxElapsed := time.Duration(5 * time.Second) + + if gotElapsed >= maxElapsed { + t.Errorf("this process has not been running for %v", gotElapsed) + } } func Test_Parent(t *testing.T) {