Skip to content

Commit 022060a

Browse files
committed
Fix the profiling cannot found process issue
1 parent 32a0c5e commit 022060a

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Release Notes.
1313
* Fix errors when compiling C source files into eBPF bytecode on a system with Linux headers version 6.2 or higher.
1414
* Fixed `ip_list_rcv` probe is not exist in older linux kernel.
1515
* Fix concurrent map operation in the access log module.
16+
* Fix the profiling cannot found process issue.
1617

1718
#### Documentation
1819

pkg/process/finders/manager.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ type ProcessManager struct {
4848
type ProcessManagerWithFinder struct {
4949
*ProcessManager
5050
finderType api.ProcessDetectType
51-
52-
lastSync []api.DetectedProcess
5351
}
5452

5553
func NewProcessManager(ctx context.Context, moduleManager *module.Manager,
@@ -121,20 +119,10 @@ func (p *ProcessManagerWithFinder) GetModuleManager() *module.Manager {
121119

122120
func (p *ProcessManagerWithFinder) SyncAllProcessInFinder(processes []api.DetectedProcess) {
123121
p.storage.SyncAllProcessInFinder(p.finderType, processes)
124-
p.lastSync = processes
125122
}
126123

127124
func (p *ProcessManagerWithFinder) AddDetectedProcess(processes []api.DetectedProcess) {
128-
if len(p.lastSync) == 0 {
129-
p.SyncAllProcessInFinder(processes)
130-
p.lastSync = processes
131-
return
132-
}
133-
// fetch existing process, add the new processes, finally, re-sync
134-
detectedProcesses := make([]api.DetectedProcess, 0, len(processes)+len(p.lastSync))
135-
detectedProcesses = append(detectedProcesses, p.lastSync...)
136-
detectedProcesses = append(detectedProcesses, processes...)
137-
p.SyncAllProcessInFinder(detectedProcesses)
125+
p.storage.AddNewProcessInFinder(p.finderType, processes)
138126
}
139127

140128
func (m *ProcessManager) GetAllProcesses() []api.ProcessInterface {

pkg/process/finders/storage.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,34 @@ func (s *ProcessStorage) processesReport(waitReportProcesses []*ProcessContext)
237237
return nil
238238
}
239239

240+
func (s *ProcessStorage) AddNewProcessInFinder(finder api.ProcessDetectType, processes []api.DetectedProcess) {
241+
s.mutex.Lock()
242+
defer s.mutex.Unlock()
243+
244+
addProcessBuilder := s.newProcessEventBuilder(ProcessOperateAdd)
245+
for _, newProcess := range processes {
246+
if newProcess == nil {
247+
continue
248+
}
249+
founded := false
250+
for _, existingProcess := range s.processes[finder] {
251+
if existingProcess.Pid() == existingProcess.Pid() && existingProcess.Entity().SameWith(existingProcess.Entity()) {
252+
founded = true
253+
break
254+
}
255+
}
256+
257+
// if not found in existing processes, need to add this process
258+
if !founded {
259+
processContext := s.constructNewProcessContext(finder, newProcess)
260+
addProcessBuilder.AddProcess(newProcess.Pid(), processContext)
261+
s.processes[finder] = append(s.processes[finder], processContext)
262+
log.Infof("detected new process by add process: pid: %d, entity: %s", newProcess.Pid(), newProcess.Entity())
263+
}
264+
}
265+
addProcessBuilder.Send()
266+
}
267+
240268
func (s *ProcessStorage) SyncAllProcessInFinder(finder api.ProcessDetectType, processes []api.DetectedProcess) {
241269
s.mutex.Lock()
242270
defer s.mutex.Unlock()
@@ -269,7 +297,7 @@ func (s *ProcessStorage) SyncAllProcessInFinder(finder api.ProcessDetectType, pr
269297
processContext := s.constructNewProcessContext(finder, syncProcess)
270298
newProcesses = append(newProcesses, processContext)
271299
addProcessBuilder.AddProcess(syncProcess.Pid(), newProcesses[len(newProcesses)-1])
272-
log.Infof("detected new process: pid: %d, entity: %s", syncProcess.Pid(), syncProcess.Entity())
300+
log.Infof("detected new process by sync all: pid: %d, entity: %s", syncProcess.Pid(), syncProcess.Entity())
273301
}
274302
}
275303
addProcessBuilder.Send()

pkg/profiling/task/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func (m *Manager) StartingWatchTask() error {
294294
return err
295295
}
296296
if len(tasks.Commands) == 0 {
297+
log.Debugf("no profiling task found need to execute")
297298
return nil
298299
}
299300

pkg/tools/buffer/buffer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (r *Buffer) FirstSocketBuffer() SocketDataBuffer {
253253
}
254254

255255
func (r *Buffer) LastSocketBuffer() SocketDataBuffer {
256-
if r.dataEvents.Len() == 0 {
256+
if r.dataEvents == nil || r.dataEvents.Len() == 0 {
257257
return nil
258258
}
259259
return r.dataEvents.Back().Value.(SocketDataBuffer)
@@ -285,7 +285,7 @@ func CombineSlices(validated bool, buffers ...*Buffer) *Buffer {
285285
dataEvents := list.New()
286286
detailEvents := list.New()
287287
for _, b := range buffers {
288-
if b == nil {
288+
if b == nil || b.head == nil {
289289
continue
290290
}
291291
if b.head.bufIndex > 0 {

0 commit comments

Comments
 (0)