in pkg/profiling/task/oncpu/runner.go [211:266]
func (r *Runner) FlushData() ([]*v3.EBPFProfilingData, error) {
if r.bpf == nil {
return nil, nil
}
var stack Event
var counter uint32
iterate := r.bpf.Counts.Iterate()
stacks := r.bpf.Stacks
result := make([]*v3.EBPFProfilingData, 0)
stackSymbols := make([]uint64, 100)
for iterate.Next(&stack, &counter) {
metadatas := make([]*v3.EBPFProfilingStackMetadata, 0)
// kernel stack
if d := r.base.GenerateProfilingData(r.kernelProfiling, stack.KernelStackID, stacks,
v3.EBPFProfilingStackType_PROCESS_KERNEL_SPACE, stackSymbols); d != nil {
metadatas = append(metadatas, d)
}
// user stack
if d := r.base.GenerateProfilingData(r.processProfiling, stack.UserStackID, stacks,
v3.EBPFProfilingStackType_PROCESS_USER_SPACE, stackSymbols); d != nil {
metadatas = append(metadatas, d)
}
if len(metadatas) == 0 {
continue
}
// update the counters in memory
dumpCount := int32(counter)
existCounter := r.stackCounter[stack]
if existCounter > 0 {
dumpCount -= int32(existCounter)
}
r.stackCounter[stack] = counter
if dumpCount <= 0 {
continue
}
result = append(result, &v3.EBPFProfilingData{
Profiling: &v3.EBPFProfilingData_OnCPU{
OnCPU: &v3.EBPFOnCPUProfiling{
Stacks: metadatas,
DumpCount: dumpCount,
},
},
})
}
// close the flush data notify if exists
if r.flushDataNotify != nil {
r.flushDataNotify()
}
return result, nil
}