Skip to content

Commit 71bb922

Browse files
committed
fix(proctree): exec event already brings data
Populate Process TaskInfo with data from sched_process_exec event. Without it, the ProcessTree when set as source=events will contain entries with no relevant data.
1 parent 0ed6a1a commit 71bb922

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

pkg/ebpf/processor_proctree.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,17 @@ func (t *Tracee) procTreeExecProcessor(event *trace.Event) error {
174174
return err
175175
}
176176

177-
execFeed.TimeStamp = uint64(event.Timestamp)
178-
execFeed.TaskHash = utils.HashTaskID(uint32(event.HostThreadID), uint64(event.ThreadStartTime))
179-
execFeed.ParentHash = 0 // regular pipeline does not have parent hash
180-
execFeed.LeaderHash = 0 // regular pipeline does not have leader hash
177+
execFeed.TimeStamp = uint64(event.Timestamp) // already normalized at decode stage
178+
execFeed.StartTime = uint64(event.ThreadStartTime) // already normalized at decode stage
179+
execFeed.TaskHash = event.ThreadEntityId // already computed at decode stage
180+
execFeed.ParentHash = event.ParentEntityId // already computed at decode stage
181+
execFeed.LeaderHash = event.ProcessEntityId // already computed at decode stage
182+
execFeed.Pid = int32(event.ProcessID)
183+
execFeed.Tid = int32(event.ThreadID)
184+
execFeed.PPid = int32(event.ParentProcessID)
185+
execFeed.HostPid = int32(event.HostProcessID)
186+
execFeed.HostTid = int32(event.HostThreadID)
187+
execFeed.HostPPid = int32(event.HostParentProcessID)
181188

182189
return t.processTree.FeedFromExec(execFeed)
183190
}

pkg/proctree/proctree_feed.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,19 @@ func (pt *ProcessTree) FeedFromFork(feed *ForkFeed) error {
204204

205205
type ExecFeed struct {
206206
TimeStamp uint64
207+
StartTime uint64
207208
Inode uint64
208209
Ctime uint64
209210
CmdPath string
210211
PathName string
211212
Interp string
212213
StdinPath string
214+
Pid int32
215+
Tid int32
216+
PPid int32
217+
HostPid int32
218+
HostTid int32
219+
HostPPid int32
213220
TaskHash uint32
214221
ParentHash uint32
215222
LeaderHash uint32
@@ -258,10 +265,26 @@ func (pt *ProcessTree) FeedFromExec(feed *ExecFeed) error {
258265
execTimestamp := traceetime.NsSinceEpochToTime(feed.TimeStamp)
259266
basename := filepath.Base(feed.CmdPath)
260267
comm := string([]byte(basename[:min(len(basename), COMM_LEN)]))
261-
process.GetInfo().SetNameAt(
262-
comm,
263-
execTimestamp,
264-
)
268+
269+
// NOTE: override all the fields of the taskInfoFeed, to avoid any previous data.
270+
taskFeed := pt.GetTaskInfoFeedFromPool()
271+
272+
taskFeed.StartTimeNS = feed.StartTime
273+
taskFeed.ExitTimeNS = 0
274+
taskFeed.Name = comm
275+
taskFeed.NsTid = feed.Tid
276+
taskFeed.NsPid = feed.Pid
277+
taskFeed.NsPPid = feed.PPid
278+
taskFeed.Tid = feed.HostTid
279+
taskFeed.Pid = feed.HostPid
280+
taskFeed.PPid = feed.HostPPid
281+
taskFeed.Uid = math.MaxUint32
282+
taskFeed.Gid = math.MaxUint32
283+
284+
process.GetInfo().SetFeedAt(taskFeed, execTimestamp)
285+
286+
// Release the feed back to the pool as soon as it is not needed anymore
287+
pt.PutTaskInfoFeedInPool(taskFeed)
265288

266289
// NOTE: override all the fields of the fileInfoFeed, to avoid any previous data.
267290
fileInfoFeed := pt.GetFileInfoFeedFromPool()

0 commit comments

Comments
 (0)