Skip to content

Commit

Permalink
Merge pull request #3094 from weaveworks/remove-getchildren
Browse files Browse the repository at this point in the history
Remove unused process tree function GetChildren()
  • Loading branch information
rade authored Feb 26, 2018
2 parents a6ac665 + c06429b commit adc46e8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 32 deletions.
4 changes: 0 additions & 4 deletions probe/docker/tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ func (m *mockProcessTree) GetParent(pid int) (int, error) {
return parent, nil
}

func (m *mockProcessTree) GetChildren(int) ([]int, error) {
panic("Not implemented")
}

func TestTagger(t *testing.T) {
mtime.NowForce(time.Now())
defer mtime.NowReset()
Expand Down
28 changes: 0 additions & 28 deletions probe/process/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
// Tree represents all processes on the machine.
type Tree interface {
GetParent(pid int) (int, error)
GetChildren(pid int) ([]int, error)
}

type tree struct {
Expand All @@ -33,30 +32,3 @@ func (pt *tree) GetParent(pid int) (int, error) {

return proc.PPID, nil
}

// GetChildren
func (pt *tree) GetChildren(pid int) ([]int, error) {
_, ok := pt.processes[pid]
if !ok {
return []int{}, fmt.Errorf("PID %d not found", pid)
}

var isChild func(id int) bool
isChild = func(id int) bool {
p, ok := pt.processes[id]
if !ok || p.PPID == 0 {
return false
} else if p.PPID == pid {
return true
}
return isChild(p.PPID)
}

children := []int{pid}
for id := range pt.processes {
if isChild(id) {
children = append(children, id)
}
}
return children, nil
}

0 comments on commit adc46e8

Please sign in to comment.