1313
1414from ddtrace import ext
1515from ddtrace .internal .datadog .profiling import ddup
16- from ddtrace .profiling .collector import threading as collector_threading
16+ from ddtrace .profiling .collector .threading import ThreadingLockCollector
17+ from ddtrace .profiling .collector .threading import ThreadingRLockCollector
1718from tests .profiling .collector import pprof_utils
1819from tests .profiling .collector import test_collector
1920from tests .profiling .collector .lock_utils import get_lock_linenos
2021from tests .profiling .collector .lock_utils import init_linenos
2122
2223
23- # Module-level globals for testing global lock profiling
24- _test_global_lock = None
25- _test_global_bar_instance = None
26-
27-
28- # Type aliases for supported classes
29- LockClass = Union [Type [threading .Lock ], Type [threading .RLock ]]
30- CollectorClass = Union [
31- Type [collector_threading .ThreadingLockCollector ], Type [collector_threading .ThreadingRLockCollector ]
32- ]
33-
34-
3524# Type aliases for supported classes
3625LockClass = Union [Type [threading .Lock ], Type [threading .RLock ]]
3726CollectorClass = Union [
38- Type [collector_threading . ThreadingLockCollector ], Type [collector_threading . ThreadingRLockCollector ]
27+ Type [ThreadingLockCollector ], Type [ThreadingRLockCollector ]
3928]
4029
4130# Module-level globals for testing global lock profiling
@@ -65,25 +54,50 @@ def bar(self) -> None:
6554 self .foo .foo ()
6655
6756
68- def test_repr () -> None :
69- test_collector ._test_repr (
70- collector_threading .ThreadingLockCollector ,
71- "ThreadingLockCollector(status=<ServiceStatus.STOPPED: 'stopped'>, "
72- "capture_pct=1.0, nframes=64, "
73- "endpoint_collection_enabled=True, tracer=None)" ,
74- )
75-
76-
77- def test_patch () -> None :
78- lock = threading .Lock
79- collector = collector_threading .ThreadingLockCollector ()
57+ @pytest .mark .parametrize (
58+ "collector_class,expected_repr" ,
59+ [
60+ (
61+ ThreadingLockCollector ,
62+ "ThreadingLockCollector(status=<ServiceStatus.STOPPED: 'stopped'>, "
63+ "capture_pct=1.0, nframes=64, "
64+ "endpoint_collection_enabled=True, tracer=None)" ,
65+ ),
66+ (
67+ ThreadingRLockCollector ,
68+ "ThreadingRLockCollector(status=<ServiceStatus.STOPPED: 'stopped'>, "
69+ "capture_pct=1.0, nframes=64, "
70+ "endpoint_collection_enabled=True, tracer=None)" ,
71+ ),
72+ ],
73+ )
74+ def test_repr (
75+ collector_class : CollectorClass ,
76+ expected_repr : str ,
77+ ) -> None :
78+ test_collector ._test_repr (collector_class , expected_repr )
79+
80+
81+ @pytest .mark .parametrize (
82+ "lock_class,collector_class" ,
83+ [
84+ (threading .Lock , ThreadingLockCollector ),
85+ (threading .RLock , ThreadingRLockCollector ),
86+ ],
87+ )
88+ def test_patch (
89+ lock_class : LockClass ,
90+ collector_class : CollectorClass ,
91+ ) -> None :
92+ lock = lock_class
93+ collector = collector_class ()
8094 collector .start ()
8195 assert lock == collector ._original
8296 # wrapt makes this true
83- assert lock == threading . Lock
97+ assert lock == lock_class
8498 collector .stop ()
85- assert lock == threading . Lock
86- assert collector ._original == threading . Lock
99+ assert lock == lock_class
100+ assert collector ._original == lock_class
87101
88102
89103@pytest .mark .skipif (not sys .platform .startswith ("linux" ), reason = "only works on linux" )
@@ -143,7 +157,7 @@ def test_wrapt_disable_extensions() -> None:
143157
144158 from ddtrace .internal .datadog .profiling import ddup
145159 from ddtrace .profiling .collector import _lock
146- from ddtrace .profiling .collector import threading as collector_threading
160+ from ddtrace .profiling .collector . threading import ThreadingLockCollector
147161 from tests .profiling .collector import pprof_utils
148162 from tests .profiling .collector .lock_utils import get_lock_linenos
149163 from tests .profiling .collector .lock_utils import init_linenos
@@ -165,7 +179,7 @@ def test_wrapt_disable_extensions() -> None:
165179 assert os .environ .get ("WRAPT_DISABLE_EXTENSIONS" )
166180 assert _lock .WRAPT_C_EXT is False
167181
168- with collector_threading . ThreadingLockCollector (capture_pct = 100 ):
182+ with ThreadingLockCollector (capture_pct = 100 ):
169183 th_lock = threading .Lock () # !CREATE! test_wrapt_disable_extensions
170184 with th_lock : # !ACQUIRE! !RELEASE! test_wrapt_disable_extensions
171185 pass
@@ -214,7 +228,7 @@ def test_lock_gevent_tasks() -> None:
214228 import threading
215229
216230 from ddtrace .internal .datadog .profiling import ddup
217- from ddtrace .profiling .collector import threading as collector_threading
231+ from ddtrace .profiling .collector . threading import ThreadingLockCollector
218232 from tests .profiling .collector import pprof_utils
219233 from tests .profiling .collector .lock_utils import get_lock_linenos
220234 from tests .profiling .collector .lock_utils import init_linenos
@@ -235,7 +249,7 @@ def play_with_lock() -> None:
235249 lock .acquire () # !ACQUIRE! test_lock_gevent_tasks
236250 lock .release () # !RELEASE! test_lock_gevent_tasks
237251
238- with collector_threading . ThreadingLockCollector (capture_pct = 100 ):
252+ with ThreadingLockCollector (capture_pct = 100 ):
239253 t = threading .Thread (name = "foobar" , target = play_with_lock )
240254 t .start ()
241255 t .join ()
@@ -324,7 +338,7 @@ def teardown_method(self, method: Any) -> None:
324338
325339 def test_wrapper (self ) -> None :
326340 # TODO: change to collector_class
327- collector = collector_threading . ThreadingLockCollector ()
341+ collector = ThreadingLockCollector ()
328342 with collector :
329343
330344 class Foobar (object ):
@@ -919,8 +933,8 @@ class TestThreadingLockCollector(BaseThreadingLockCollectorTest):
919933 """Test threading.Lock profiling"""
920934
921935 @property
922- def collector_class (self ) -> Type [collector_threading . ThreadingLockCollector ]:
923- return collector_threading . ThreadingLockCollector
936+ def collector_class (self ) -> Type [ThreadingLockCollector ]:
937+ return ThreadingLockCollector
924938
925939 @property
926940 def lock_class (self ) -> Type [threading .Lock ]:
@@ -931,8 +945,8 @@ class TestThreadingRLockCollector(BaseThreadingLockCollectorTest):
931945 """Test threading.RLock profiling"""
932946
933947 @property
934- def collector_class (self ) -> Type [collector_threading . ThreadingRLockCollector ]:
935- return collector_threading . ThreadingRLockCollector
948+ def collector_class (self ) -> Type [ThreadingRLockCollector ]:
949+ return ThreadingRLockCollector
936950
937951 @property
938952 def lock_class (self ) -> Type [threading .RLock ]:
0 commit comments