From 2984accfa15c604a9aadfcd5c338330e121cd225 Mon Sep 17 00:00:00 2001 From: jay park Date: Sun, 13 Sep 2015 13:05:09 +0900 Subject: [PATCH] return error when CPUTimes fails on callPs, modify comments on ReadLines --- common/common.go | 2 +- process/process_darwin.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/common.go b/common/common.go index a795361..efefbf0 100644 --- a/common/common.go +++ b/common/common.go @@ -17,7 +17,7 @@ import ( var NotImplementedError = errors.New("not implemented yet") -// ReadLines reads contents from file and splits them by new line. +// ReadLines reads contents from a file and splits them by new lines. // A convenience wrapper to ReadLinesOffsetN(filename, 0, -1). func ReadLines(filename string) ([]string, error) { return ReadLinesOffsetN(filename, 0, -1) diff --git a/process/process_darwin.go b/process/process_darwin.go index 2a49ead..d979337 100644 --- a/process/process_darwin.go +++ b/process/process_darwin.go @@ -215,6 +215,10 @@ func convertCpuTimes(s string) (ret float64, err error) { func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error) { r, err := callPs("utime,stime", p.Pid, false) + if err != nil { + return nil, err + } + utime, err := convertCpuTimes(r[0][0]) if err != nil { return nil, err