in skywalking/profile/profile_context.py [0:0]
def profiling(self, context: ProfileTaskExecutionContext):
max_sleep_period = context.task.thread_dump_period
while not self._stop_event.is_set():
current_loop_start_time = current_milli_time()
profilers = self._task_execution_context.profiling_segment_slots
for profiler in profilers: # type: ThreadProfiler
if profiler is None or isinstance(profiler, GreenletProfiler):
continue
if profiler.profile_status.get() is ProfileStatus.PENDING:
profiler.start_profiling_if_need()
elif profiler.profile_status.get() is ProfileStatus.PROFILING:
snapshot = profiler.build_snapshot()
if snapshot is not None:
agent.add_profiling_snapshot(snapshot)
else:
# tell execution context current tracing thread dump failed, stop it
context.stop_tracing_profile(profiler.trace_context)
need_sleep = (current_loop_start_time + max_sleep_period) - current_milli_time()
if not need_sleep > 0:
need_sleep = max_sleep_period
# convert to float second
time.sleep(need_sleep / 1000)