Skip to content

Commit 8904877

Browse files
replace inline frame collections with one-time globals definition
1 parent 45d4eee commit 8904877

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

ddtrace/profiling/collector/_lock.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
from ddtrace.trace import Tracer
3030

3131

32+
ACQUIRE_RELEASE_CO_NAMES: List[str] = ["_acquire", "_release"]
33+
ENTER_EXIT_CO_NAMES: List[str] = ["acquire", "release", "__enter__", "__exit__", "__aenter__", "__aexit__"]
34+
35+
3236
def _current_thread() -> Tuple[int, str]:
3337
thread_id: int = _thread.get_ident()
3438
return thread_id, _threading.get_thread_name(thread_id)
@@ -233,26 +237,16 @@ def _maybe_update_self_name(self) -> None:
233237
# 3: caller frame
234238
if config.enable_asserts:
235239
frame: FrameType = sys._getframe(1)
236-
# TODO: replace dict with list
237-
if frame.f_code.co_name not in {"_acquire", "_release"}:
240+
if frame.f_code.co_name not in ACQUIRE_RELEASE_CO_NAMES:
238241
raise AssertionError("Unexpected frame %s" % frame.f_code.co_name)
242+
239243
frame = sys._getframe(2)
240-
if frame.f_code.co_name not in {
241-
"acquire",
242-
"release",
243-
"__enter__",
244-
"__exit__",
245-
"__aenter__",
246-
"__aexit__",
247-
}:
244+
if frame.f_code.co_name not in ENTER_EXIT_CO_NAMES:
248245
raise AssertionError("Unexpected frame %s" % frame.f_code.co_name)
249-
frame = sys._getframe(3)
250246

251247
# First, look at the local variables of the caller frame, and then the global variables
252-
self._self_name = self._find_self_name(frame.f_locals) or self._find_self_name(frame.f_globals)
253-
254-
if not self._self_name:
255-
self._self_name = ""
248+
frame = sys._getframe(3)
249+
self._self_name = self._find_self_name(frame.f_locals) or self._find_self_name(frame.f_globals) or ""
256250

257251

258252
class FunctionWrapper(wrapt.FunctionWrapper):

0 commit comments

Comments
 (0)