Skip to content

Conversation

@vlad-scherbich
Copy link
Contributor

@vlad-scherbich vlad-scherbich commented Dec 8, 2025

https://datadoghq.atlassian.net/browse/PROF-12724

note
this PR implements profiling the time to acquire Condition's underlying lock. While this data is somewhat useful on its own (more contention data better than less?), it would be more valuable to profile how long a Condition was waited on before signaling, etc. This would require ddup API changes, and new backend/UI work to display the new data type. As such, this rich implementation will be pushed to Q1 (?) 2026.
end note

Description

Adds profiling support for asyncio.Condition to the Python Lock profiler. This extends the lock profiling capability to include condition variables in asynchronous applications.

Motivation

asyncio.Condition is a synchronization primitive that allows tasks to wait for a specific condition. Profiling Condition usage helps identify:

  • Contention points where tasks are waiting on conditions
  • Long wait times in producer/consumer patterns
  • Potential bottlenecks in async coordination logic

Changes

  1. New Collector: Added AsyncioConditionCollector in ddtrace/profiling/collector/asyncio.py.
  2. Internal Lock Detection: asyncio.Condition also creates an internal asyncio.Lock, and since we now have a handful of lock types following the same pattern, the is_internal logic was generalized by adding a INTERNAL_MODULE_FILE class attribute to LockCollector.

Testing

  • Added TestAsyncioConditionCollector with test_condition_wait_notify test
  • Inherits base tests from BaseAsyncioLockCollectorTest

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/Added-support-for-profiling-of-asyncio.BoundedSemaphore-objects-to-the-Python-Lock-profiler-5bf06391b0b047f1.yaml  @DataDog/apm-python
releasenotes/notes/Added-support-for-profiling-of-asyncio.Condition-objects-to-the-Python-Lock-profiler-26eee0eb-4831-4c.yaml  @DataDog/apm-python
releasenotes/notes/Added-support-for-profiling-of-asyncio.Semaphore-objects-to-the-Python-Lock-profiler-193fd8150d084ea6.yaml  @DataDog/apm-python
ddtrace/profiling/collector/_lock.py                                    @DataDog/profiling-python
ddtrace/profiling/collector/asyncio.py                                  @DataDog/profiling-python
ddtrace/profiling/profiler.py                                           @DataDog/profiling-python
tests/profiling/collector/test_asyncio.py                               @DataDog/profiling-python
tests/profiling/test_profiler.py                                        @DataDog/profiling-python

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 251 ± 3 ms.

The average import time from base is: 254 ± 2 ms.

The import time difference between this PR and base is: -3.3 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.728 ms (1.09%)
ddtrace 1.370 ms (0.55%)
ddtrace._logger 0.684 ms (0.27%)
ddtrace.internal.telemetry 0.684 ms (0.27%)
ddtrace.internal.telemetry.writer 0.684 ms (0.27%)
ddtrace.internal.utils.version 0.684 ms (0.27%)
ddtrace.version 0.684 ms (0.27%)
ddtrace.internal._unpatched 0.029 ms (0.01%)
json 0.029 ms (0.01%)
json.decoder 0.029 ms (0.01%)
re 0.029 ms (0.01%)
enum 0.029 ms (0.01%)
types 0.029 ms (0.01%)
ddtrace.bootstrap.sitecustomize 1.358 ms (0.54%)
ddtrace.bootstrap.preload 1.358 ms (0.54%)
ddtrace.internal.remoteconfig.client 0.649 ms (0.26%)

@vlad-scherbich vlad-scherbich changed the title Vlad/lockprof asyncio condition feat(profiling): profile asyncio.Condition primitives with Python Lock profiler Dec 8, 2025
@vlad-scherbich vlad-scherbich force-pushed the vlad/lockprof-asyncio-condition branch from 57f1703 to f333100 Compare December 8, 2025 15:11
@vlad-scherbich vlad-scherbich force-pushed the vlad/lockprof-asyncio-condition branch from f333100 to 79bceeb Compare December 10, 2025 17:35
@vlad-scherbich vlad-scherbich marked this pull request as ready for review December 10, 2025 17:35
@vlad-scherbich vlad-scherbich requested review from a team as code owners December 10, 2025 17:35
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These release notes can all be combined into one file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants