-
Notifications
You must be signed in to change notification settings - Fork 506
refactor(profiling): drop bytecode-lib dependency from _asyncio.py
#17995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vlad-scherbich
wants to merge
16
commits into
main
Choose a base branch
from
vlad/prof-replace-bytecode-dependency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+701
−10
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
14137b7
rewrite tracing's 'wrap' that's depending on 'bytecode' lib with a lo…
vlad-scherbich 2327302
added new unit tests
vlad-scherbich a452054
fix tests
vlad-scherbich 01b4bd6
fix(profiling): preserve coroutine semantics when wrapping async-def …
vlad-scherbich b21e146
fix(profiling): preserve function identity in _wrap to instrument pre…
vlad-scherbich 672f9ce
test: replace weak module-import sanity check with deterministic iden…
vlad-scherbich 1fd7eb3
test: add behavioural test for pre-cached create_task reference (uvlo…
vlad-scherbich 6a01376
test: drop overlapping asyncio-wrapping tests (25 -> 15)
vlad-scherbich 2520510
test: extract profiler-setup boilerplate into _asyncio_wrap_helpers
vlad-scherbich 1ae2a9c
refactor(profiling): replace exec-based trampoline with code.replace(…
vlad-scherbich d1ed59c
fix(profiling): preserve signature metadata via __wrapped__ in identi…
vlad-scherbich 94ffa0f
test(profiling): cover inspect.signature preservation; assert stack.i…
vlad-scherbich 348bb66
use template.__code__.replace
vlad-scherbich f964247
refactor(profiling): collapse trampoline+dispatcher into one function…
vlad-scherbich 019a670
refactor(profiling): compact comments and tighten types in _wrap
vlad-scherbich ebb1828
test(profiling): finish type annotations on inner async helpers
vlad-scherbich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Subprocess-body helpers for the asyncio-wrap tests. | ||
|
|
||
| ``@pytest.mark.subprocess`` extracts only the test function's body and | ||
| executes it as a standalone script (see ``FunctionDefFinder`` in | ||
| ``tests/conftest.py``). Module-level definitions in the test file are | ||
| therefore invisible to the subprocess. Helpers must live in a separate | ||
| importable module — which this file is. | ||
|
|
||
| Imported as ``from tests.profiling.collector._asyncio_wrap_helpers import ...`` | ||
| inside each subprocess test body. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from contextlib import contextmanager | ||
| from typing import Any | ||
| from typing import Callable | ||
| from typing import Iterator | ||
|
|
||
|
|
||
| @contextmanager | ||
| def started_profiler() -> Iterator[Any]: | ||
| """Context manager that starts the profiler on entry and stops it on | ||
| exit, even on assertion failure. Yields the Profiler instance. | ||
| """ | ||
| from ddtrace.profiling import profiler | ||
|
|
||
| p = profiler.Profiler() | ||
| p.start() | ||
| try: | ||
| yield p | ||
| finally: | ||
| p.stop() | ||
|
|
||
|
|
||
| @contextmanager | ||
| def captured_link_calls(attr: str) -> Iterator[list[int]]: | ||
| """Replace ``ddtrace.internal.datadog.profiling.stack.<attr>`` with a | ||
| recorder that captures the child task id of each call, yielding the | ||
| growing list. Restores the original on exit. | ||
|
|
||
| ``attr`` is one of ``"link_tasks"`` / ``"weak_link_tasks"`` / | ||
| ``"track_asyncio_loop"`` — anything with a ``(_, second_arg)`` shape | ||
| where the second arg is the thing we want to identify by id. | ||
|
|
||
| Raises ``AssertionError`` (with ``stack.failure_msg``) if the native | ||
| stack extension is unavailable — surfaces the root cause clearly | ||
| rather than an opaque ``AttributeError`` on ``getattr(stack, attr)``. | ||
| """ | ||
| from ddtrace.internal.datadog.profiling import stack | ||
|
|
||
| assert stack.is_available, stack.failure_msg | ||
|
|
||
| original: Callable[..., Any] = getattr(stack, attr) | ||
| recorded: list[int] = [] | ||
|
vlad-scherbich marked this conversation as resolved.
|
||
|
|
||
| def recorder(first: Any, second: Any) -> Any: | ||
| recorded.append(id(second)) | ||
| return original(first, second) | ||
|
|
||
| setattr(stack, attr, recorder) | ||
| try: | ||
| yield recorded | ||
| finally: | ||
| setattr(stack, attr, original) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.