Implement Threads() for Linux

pull/428/head
Leonid Podolny 8 years ago
parent 1ba77cdb3d
commit 7ad3836ad3

@ -268,8 +268,8 @@ func (p *Process) NumThreads() (int32, error) {
}
return int32(len(r)), nil
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
func (p *Process) Threads() ([]int32, error) {
ret := make([]int32, 0)
return ret, common.ErrNotImplementedError
}

@ -95,7 +95,7 @@ func (p *Process) NumFDs() (int32, error) {
func (p *Process) NumThreads() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Threads() (map[string]string, error) {
func (p *Process) Threads() ([]int32, error) {
return nil, common.ErrNotImplementedError
}
func (p *Process) Times() (*cpu.TimesStat, error) {

@ -204,8 +204,8 @@ func (p *Process) NumThreads() (int32, error) {
return k.Numthreads, nil
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
func (p *Process) Threads() ([]int32, error) {
ret := make([]int32, 0)
return ret, common.ErrNotImplementedError
}
func (p *Process) Times() (*cpu.TimesStat, error) {

@ -293,9 +293,9 @@ func (p *Process) NumThreads() (int32, error) {
// Threads returns a map of threads
//
// Notice: Not implemented yet. always returns empty map.
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
return ret, nil
func (p *Process) Threads() ([]int32, error) {
taskPath := common.HostProc(strconv.Itoa(int(p.Pid)), "task")
return readPidsFromDir(taskPath)
}
// Times returns CPU times of the process.
@ -991,9 +991,13 @@ func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, uint32,
// Pids returns a slice of process ID list which are running now.
func Pids() ([]int32, error) {
return readPidsFromDir(common.HostProc())
}
func readPidsFromDir(path string) ([]int32, error) {
var ret []int32
d, err := os.Open(common.HostProc())
d, err := os.Open(path)
if err != nil {
return nil, err
}

@ -194,8 +194,8 @@ func (p *Process) NumThreads() (int32, error) {
/* not supported, just return 1 */
return 1, nil
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
func (p *Process) Threads() ([]int32, error) {
ret := make([]int32, 0)
return ret, common.ErrNotImplementedError
}
func (p *Process) Times() (*cpu.TimesStat, error) {

@ -273,8 +273,8 @@ func (p *Process) NumThreads() (int32, error) {
}
return int32(dst[0].ThreadCount), nil
}
func (p *Process) Threads() (map[string]string, error) {
ret := make(map[string]string, 0)
func (p *Process) Threads() ([]int32, error) {
ret := make([]int32, 0)
return ret, common.ErrNotImplementedError
}
func (p *Process) Times() (*cpu.TimesStat, error) {

Loading…
Cancel
Save