in pkg/profiling/task/manager.go [287:340]
func (m *Manager) StartingWatchTask() error {
// query task
tasks, err := m.profilingClient.QueryTasks(m.ctx, &profiling_v3.EBPFProfilingTaskQuery{
RoverInstanceId: m.instanceID,
LatestUpdateTime: m.lastUpdateTime,
})
if err != nil {
return err
}
if len(tasks.Commands) == 0 {
log.Debugf("no profiling task found need to execute")
return nil
}
// analyze profiling tasks
taskContexts := make([]*Context, 0)
lastUpdateTime := m.lastUpdateTime
for _, cmd := range tasks.Commands {
taskContext, err := m.BuildContextFromCommand(cmd)
if err != nil {
log.Warnf("could not execute task, ignored. %v", err)
continue
}
if taskContext.UpdateTime() > lastUpdateTime {
lastUpdateTime = taskContext.UpdateTime()
}
if !taskContext.CheckTaskRunnable() {
continue
}
taskContexts = append(taskContexts, taskContext)
}
// update last task time
m.lastUpdateTime = lastUpdateTime
if len(taskContexts) == 0 {
return nil
}
taskIDList := make([]string, len(taskContexts))
for inx, c := range taskContexts {
taskIDList[inx] = c.TaskID()
}
log.Infof("received %d profiling task: %v", len(taskContexts), taskIDList)
// start tasks
for _, t := range taskContexts {
m.StartTask(t)
}
return nil
}