Skip to content

Commit

Permalink
Delayed ProcessManager.pidToProcessInfo cleanup
Browse files Browse the repository at this point in the history
Uses ProcessedUntil mechanism to guarantee that process metadata
is not discarded before all relevant trace events have been
processed.
  • Loading branch information
christos68k committed Jan 22, 2025
1 parent 5317c8f commit 5629d4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions processmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ func (pm *ProcessManager) ProcessedUntil(traceCaptureKTime times.KTime) {
if pidExitKTime > traceCaptureKTime {
continue
}

delete(pm.pidToProcessInfo, pid)

for _, instance := range pm.interpreters[pid] {
if err := instance.Detach(pm.ebpf, pid); err != nil {
log.Errorf("Failed to handle interpreted process exit for PID %d: %v",
Expand Down
14 changes: 6 additions & 8 deletions processmanager/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,19 @@ func (pm *ProcessManager) synchronizeMappings(pr process.Process,
// fast enough and this particular pid is reused again by the system.
// NOTE: Exported only for tracer.
func (pm *ProcessManager) ProcessPIDExit(pid libpf.PID) {
exitKTime := times.GetKTime()

log.Debugf("- PID: %v", pid)
defer pm.ebpf.RemoveReportedPID(pid)

pm.mu.Lock()
defer pm.mu.Unlock()

exitKTime := times.GetKTime()
if pm.interpreterTracerEnabled {
if len(pm.interpreters[pid]) > 0 {
pm.exitEvents[pid] = exitKTime
}
}

info, ok := pm.pidToProcessInfo[pid]
if ok || (pm.interpreterTracerEnabled &&
len(pm.interpreters[pid]) > 0) {
pm.exitEvents[pid] = exitKTime
}
if !ok {
log.Debugf("Skip process exit handling for unknown PID %d", pid)
return
Expand All @@ -545,7 +544,6 @@ func (pm *ProcessManager) ProcessPIDExit(pid libpf.PID) {
address, pid, err)
}
}
delete(pm.pidToProcessInfo, pid)
}

func (pm *ProcessManager) SynchronizeProcess(pr process.Process) {
Expand Down

0 comments on commit 5629d4b

Please sign in to comment.