Skip to content

Commit 3926499

Browse files
tylfinP403n1x87
authored andcommitted
fix(debugger): reduce code origin startup time
Start with a benchmark to measure opportunities for improvements refs: DEBUG-4605
1 parent 2f7da21 commit 3926499

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

riotfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
657657
"httpretty": latest,
658658
"typing-extensions": latest,
659659
"pytest-asyncio": latest,
660+
"pytest-benchmark": latest,
660661
},
661662
pys=select_pys(),
662663
),

tests/debugging/origin/test_span.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import partial
22
from pathlib import Path
3+
import time
34
import typing as t
45

56
import pytest
@@ -169,3 +170,44 @@ def entry_call():
169170
assert _exit.get_tag("_dd.code_origin.type") is None
170171
assert _exit.get_tag("_dd.code_origin.frames.0.file") is None
171172
assert _exit.get_tag("_dd.code_origin.frames.0.line") is None
173+
174+
175+
def test_instrument_view_benchmark(benchmark):
176+
"""Benchmark instrument_view performance when wrapping functions."""
177+
MockSpanCodeOriginProcessorEntry.enable()
178+
179+
try:
180+
181+
def setup():
182+
"""Create a unique function to wrap for each iteration."""
183+
184+
# Create a more realistic view function similar to Flask views
185+
# with decorators, imports, and more complex code
186+
def realistic_view(request_arg, *args, **kwargs):
187+
"""A realistic view function with actual code."""
188+
import json
189+
import os
190+
191+
data = {"status": "ok", "items": []}
192+
for i in range(10):
193+
item = {
194+
"id": i,
195+
"name": f"item_{i}",
196+
"value": i * 100,
197+
}
198+
data["items"].append(item)
199+
200+
result = json.dumps(data)
201+
return result
202+
203+
return (realistic_view,), {}
204+
205+
# Benchmark the wrapping operation
206+
benchmark.pedantic(
207+
MockSpanCodeOriginProcessorEntry.instrument_view,
208+
setup=setup,
209+
rounds=100,
210+
)
211+
212+
finally:
213+
MockSpanCodeOriginProcessorEntry.disable()

0 commit comments

Comments
 (0)