Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions processmanager/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func (pm *ProcessManager) updatePidInformation(pid libpf.PID, m *Mapping) (bool,
processName = string(name)
}
info = &processInfo{
name: processName,
executable: exePath,
meta: ProcessMeta{Name: processName, Executable: exePath},
mappings: make(map[libpf.Address]*Mapping),
mappingsByFileID: make(map[host.FileID]map[libpf.Address]*Mapping),
tsdInfo: nil,
Expand Down Expand Up @@ -651,29 +650,14 @@ func (pm *ProcessManager) CleanupPIDs() {
}
}

// NameForPID returns the process name for given PID.
// If the PID is not tracked it returns the empty string.
func (pm *ProcessManager) NameForPID(pid libpf.PID) string {
// MetaForPID returns the process metadata for given PID.
func (pm *ProcessManager) MetaForPID(pid libpf.PID) ProcessMeta {
pm.mu.RLock()
defer pm.mu.RUnlock()
if procInfo, ok := pm.pidToProcessInfo[pid]; ok {
return procInfo.name
return procInfo.meta
}
return ""
}

// ExePathForPID returns the full executable path for given PID.
// If the PID is not tracked or belongs to a kernel worker,
// it returns the empty string.
func (pm *ProcessManager) ExePathForPID(pid libpf.PID) string {
var executable string

pm.mu.RLock()
defer pm.mu.RUnlock()
if procInfo, ok := pm.pidToProcessInfo[pid]; ok {
executable = procInfo.executable
}
return executable
return ProcessMeta{}
}

// findMappingForTrace locates the mapping for a given host trace.
Expand Down
14 changes: 10 additions & 4 deletions processmanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ func (m *Mapping) GetOnDiskFileIdentifier() util.OnDiskFileIdentifier {
}
}

// ProcessMeta contains metadata about a tracked process.
type ProcessMeta struct {
// process name retrieved from /proc/PID/comm
Name string
// executable path retrieved from /proc/PID/exe
Executable string
}

// processInfo contains information about the executable mappings
// and Thread Specific Data of a process.
type processInfo struct {
// process name retrieved from /proc/PID/comm
name string
// executable path retrieved from /proc/PID/exe
executable string
// process metadata, fixed for process lifetime (read-only)
meta ProcessMeta
// executable mappings keyed by start address.
mappings map[libpf.Address]*Mapping
// executable mappings keyed by host file ID.
Expand Down
5 changes: 3 additions & 2 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,11 @@ func (t *Tracer) loadBpfTrace(raw []byte, cpu int) *host.Trace {
}

pid := libpf.PID(ptr.pid)
procMeta := t.processManager.MetaForPID(pid)
trace := &host.Trace{
Comm: C.GoString((*C.char)(unsafe.Pointer(&ptr.comm))),
ExecutablePath: t.processManager.ExePathForPID(pid),
ProcessName: t.processManager.NameForPID(pid),
ExecutablePath: procMeta.Executable,
ProcessName: procMeta.Name,
APMTraceID: *(*libpf.APMTraceID)(unsafe.Pointer(&ptr.apm_trace_id)),
APMTransactionID: *(*libpf.APMTransactionID)(unsafe.Pointer(&ptr.apm_transaction_id)),
PID: pid,
Expand Down