Files
weave-scope/probe/process/tree.go
Peter Bourgon b585a362ac Naïve process walker for Darwin
This fixes the regression where process names weren't appearing for
Darwin probes. Makes testing easier.

Also, changes the process walker to operate on value types. There's no
performance advantage to using reference types for something of this
size, and there appeared to be a data race in the Darwin port that
caused nodes to gain and lose process names over time.

Also, restructures how to enable docker scraping. Default false when run
manually, and enabled via --probe.docker true in the scope script.
2015-07-16 12:33:59 +02:00

35 lines
653 B
Go

package process
import (
"fmt"
)
// Tree represents all processes on the machine.
type Tree interface {
GetParent(pid int) (int, error)
}
type tree struct {
processes map[int]Process
}
// NewTree returns a new Tree that can be polled.
func NewTree(walker Walker) (Tree, error) {
pt := tree{processes: map[int]Process{}}
err := walker.Walk(func(p Process) {
pt.processes[p.PID] = p
})
return &pt, err
}
// GetParent returns the pid of the parent process for a given pid
func (pt *tree) GetParent(pid int) (int, error) {
proc, ok := pt.processes[pid]
if !ok {
return -1, fmt.Errorf("PID %d not found", pid)
}
return proc.PPID, nil
}