Skip to content

Commit

Permalink
process tree improvements
Browse files Browse the repository at this point in the history
 - When discovering the hierarchy of a process, reuse components of
   the tree if they're already on cache, to improve speed and reduce
   mem allocs.
 - When building the tree of a proces, rebuild the tree if the first
   component doesn't have pid 1. Otherwise reuse the tree.
  • Loading branch information
gustavo-iniguez-goya committed Jan 18, 2024
1 parent 379d010 commit 01edd36
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions daemon/procmon/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ func (p *Process) GetParent() {
if p.PPID == 0 {
return
}
it, found := EventsCache.IsInStoreByPID(p.PPID)
if found {
p.Parent = &it.Proc
p.Parent.GetParent()
return
}

// TODO: see how we can reuse this object and the ppid, to save some iterations.
// right now it opens the can of leaks.
p.mu.Lock()
p.Parent = NewProcessEmpty(p.PPID, "")
p.mu.Unlock()
Expand All @@ -51,9 +55,11 @@ func (p *Process) GetParent() {

// BuildTree returns all the parents of this process.
func (p *Process) BuildTree() {
if len(p.Tree) > 0 {
items := len(p.Tree)
if items > 0 && p.Tree[items-1].Value == 1 {
return
}

// Adding this process to the tree, not to loose track of it.
p.Tree = append(p.Tree,
&protocol.StringInt{
Expand Down

0 comments on commit 01edd36

Please sign in to comment.