in skywalking/profile/profile_context.py [0:0]
def attempt_profiling(self, trace_context: SpanContext, segment_id: str, first_span_opname: str) -> \
ProfileStatusReference:
"""
check have available slot to profile and add it
"""
# check has available slot
using_slot_cnt = self._current_profiling_cnt.get()
if using_slot_cnt >= config.agent_profile_max_parallel:
return ProfileStatusReference.create_with_none()
# check first operation name matches
if not self.task.first_span_op_name == first_span_opname:
return ProfileStatusReference.create_with_none()
# if out limit started profiling count then stop add profiling
if self._total_started_profiling_cnt.get() > self.task.max_sampling_count:
return ProfileStatusReference.create_with_none()
# try to occupy slot
if not self._current_profiling_cnt.compare_and_set(using_slot_cnt,
using_slot_cnt + 1):
return ProfileStatusReference.create_with_none()
if THREAD_MODEL == 'greenlet':
curr = greenlet.getcurrent()
thread_profiler = GreenletProfiler(
trace_context=trace_context,
segment_id=segment_id,
profiling_thread=curr,
profile_context=self,
)
thread_profiler.start_profiling(self)
else:
# default is thread
thread_profiler = ThreadProfiler(
trace_context=trace_context,
segment_id=segment_id,
profiling_thread=current_thread(),
profile_context=self,
)
slot_length = self.profiling_segment_slots.length()
for idx in range(slot_length):
# occupy slot success
if self.profiling_segment_slots.compare_and_set(idx, None, thread_profiler):
return thread_profiler.profile_status
return ProfileStatusReference.create_with_none()