Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e000d93
feat(profiling): add 'threading.RLock' support to the Lock profiler
vlad-scherbich Oct 8, 2025
2395cfc
add RLock tests
vlad-scherbich Oct 9, 2025
66756d9
all TestThreadingLockCollector tests pass; some TestThreadingRLockCol…
vlad-scherbich Oct 9, 2025
818e62a
some still don't pass; most pass; flaky?
vlad-scherbich Oct 9, 2025
22baef3
fix lints
vlad-scherbich Oct 9, 2025
5c6484c
rm unnecessary 'pass'
vlad-scherbich Oct 9, 2025
93ea186
fix test_global_locks test
vlad-scherbich Oct 10, 2025
8fdbd8d
Simplified and improve: fix test_global_locks test
vlad-scherbich Oct 10, 2025
e7e659a
lint fixes
vlad-scherbich Oct 10, 2025
197f883
fix line-number discrepancy for py versions
vlad-scherbich Oct 10, 2025
b465fe2
Add a release note
vlad-scherbich Oct 10, 2025
28dc94b
add e2e test
vlad-scherbich Oct 10, 2025
7ba5c16
fix lint
vlad-scherbich Oct 10, 2025
fa05ae3
move the e2e test file into tests dir
vlad-scherbich Oct 10, 2025
0b47089
adding more tests
vlad-scherbich Oct 13, 2025
1038886
Moving test_user_threads_have_native_id to test_profiler (it doesn't …
vlad-scherbich Oct 13, 2025
6c2461f
Clean up 'test_[r|]lock_gevent_tasks' tests
vlad-scherbich Oct 14, 2025
7d2dcf1
fix tests (import threading)
vlad-scherbich Oct 14, 2025
39bc88f
Update ddtrace/profiling/collector/threading.py
vlad-scherbich Oct 15, 2025
bfe6b84
Update ddtrace/profiling/collector/threading.py
vlad-scherbich Oct 15, 2025
f29be5c
fix tests and rm the e2e test file
vlad-scherbich Oct 15, 2025
1db7591
Merge branch 'main' into vlad/lock-profiler-add-rlock
vlad-scherbich Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ddtrace/profiling/collector/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class _ProfiledThreadingLock(_lock._ProfiledLock):
pass


class _ProfiledThreadingRLock(_lock._ProfiledLock):
pass


class ThreadingLockCollector(_lock.LockCollector):
"""Record threading.Lock usage."""

Expand All @@ -29,6 +33,21 @@ def _set_patch_target(
threading.Lock = value


class ThreadingRLockCollector(_lock.LockCollector):
"""Record threading.RLock usage."""

PROFILED_LOCK_CLASS = _ProfiledThreadingRLock

def _get_patch_target(self) -> typing.Type[threading.RLock]:
return threading.RLock

def _set_patch_target(
self,
value: typing.Any,
) -> None:
threading.RLock = value


# Also patch threading.Thread so echion can track thread lifetimes
def init_stack_v2() -> None:
if config.stack.v2_enabled and stack_v2.is_available:
Expand Down
3 changes: 3 additions & 0 deletions ddtrace/profiling/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from ddtrace.settings.profiling import config_str


# TODO(vlad): add type annotations

LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -223,6 +225,7 @@ def start_collector(collector_class: Type) -> None:

self._collectors_on_import = [
("threading", lambda _: start_collector(threading.ThreadingLockCollector)),
("threading", lambda _: start_collector(threading.ThreadingRLockCollector)),
("asyncio", lambda _: start_collector(asyncio.AsyncioLockCollector)),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
profiling: Add support for ``threading.RLock`` (reentrant lock) profiling. The Lock profiler now tracks both ``threading.Lock`` and ``threading.RLock`` usage, providing comprehensive lock contention visibility for Python applications.
25 changes: 0 additions & 25 deletions tests/profiling/collector/global_locks.py

This file was deleted.

Loading
Loading