summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-22 23:00:03 +0200
committerPaul Buetow <paul@buetow.org>2026-02-22 23:00:03 +0200
commit1666ba49ef9e5b61e14d1a32d2f6e2380064105e (patch)
tree182b5e7b8e3464fefac256c22118312388c41bc9 /internal
parent86a96020fb63cf15ee6d20ec3058a462b5cacd7e (diff)
Fix event comm attribution and reduce integration log noise
Diffstat (limited to 'internal')
-rw-r--r--internal/eventloop.go39
1 files changed, 38 insertions, 1 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 7bfd576..654d0fc 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -40,7 +40,7 @@ type eventLoop struct {
}
func newEventLoop() *eventLoop {
- return &eventLoop{
+ el := &eventLoop{
filter: newEventFilter(),
enterEvs: make(map[uint32]*event.Pair),
pendingHandles: make(map[uint32]string),
@@ -51,6 +51,28 @@ func newEventLoop() *eventLoop {
flamegraph: flamegraph.New(),
done: make(chan struct{}),
}
+ el.seedTrackedPidComm()
+ return el
+}
+
+func (e *eventLoop) seedTrackedPidComm() {
+ pid := flags.Get().PidFilter
+ if pid <= 0 {
+ return
+ }
+ commPath := fmt.Sprintf("/proc/%d/comm", pid)
+ data, err := os.ReadFile(commPath)
+ if err != nil {
+ return
+ }
+ comm := string(data)
+ if len(comm) > 0 && comm[len(comm)-1] == '\n' {
+ comm = comm[:len(comm)-1]
+ }
+ if comm == "" {
+ return
+ }
+ e.comms[uint32(pid)] = comm
}
func (e *eventLoop) stats() string {
@@ -174,6 +196,10 @@ func (e *eventLoop) processRawEvent(raw []byte, ch chan<- *event.Pair) {
func (e *eventLoop) tracepointEntered(enterEv event.Event) {
tid := enterEv.GetTid()
+ // Cache comm as early as possible to reduce races for short-lived processes.
+ if _, ok := e.comms[tid]; !ok {
+ _ = e.comm(tid)
+ }
if !e.filter.commFilterEnable {
e.enterEvs[tid] = event.NewPair(enterEv)
return
@@ -427,6 +453,17 @@ func (e *eventLoop) comm(tid uint32) string {
if comm, ok := e.comms[tid]; ok {
return comm
}
+ commPath := fmt.Sprintf("/proc/%d/comm", tid)
+ if data, err := os.ReadFile(commPath); err == nil {
+ comm := string(data)
+ if len(comm) > 0 && comm[len(comm)-1] == '\n' {
+ comm = comm[:len(comm)-1]
+ }
+ if comm != "" {
+ e.comms[tid] = comm
+ return comm
+ }
+ }
if linkName, err := os.Readlink(fmt.Sprintf("/proc/%d/exe", tid)); err == nil {
linkName = filepath.Base(linkName)
e.comms[tid] = linkName