Added Perf details to profiler control
This commit is contained in:
@@ -536,7 +536,7 @@ class TestTraceCalls:
|
||||
def helper_b():
|
||||
return 2
|
||||
|
||||
@p.trace_calls
|
||||
@p.trace_calls()
|
||||
def main_func():
|
||||
helper_a()
|
||||
helper_b()
|
||||
@@ -561,7 +561,7 @@ class TestTraceCalls:
|
||||
"""Test that trace_calls creates no spans when the profiler is disabled at call time."""
|
||||
p = fresh_profiler
|
||||
|
||||
@p.trace_calls
|
||||
@p.trace_calls()
|
||||
def main_func():
|
||||
return 99
|
||||
|
||||
@@ -576,7 +576,7 @@ class TestTraceCalls:
|
||||
"""Test that trace_calls captures the decorated function's arguments in the root span data."""
|
||||
p = fresh_profiler
|
||||
|
||||
@p.trace_calls
|
||||
@p.trace_calls()
|
||||
def compute(x, y):
|
||||
return x + y
|
||||
|
||||
@@ -588,6 +588,100 @@ class TestTraceCalls:
|
||||
assert main_span.data.get("x") == "3"
|
||||
assert main_span.data.get("y") == "7"
|
||||
|
||||
def test_i_can_use_trace_calls_with_include_filter(self, fresh_profiler):
|
||||
"""Test that only calls from included modules are traced."""
|
||||
import types
|
||||
p = fresh_profiler
|
||||
|
||||
# Simulate a function in a foreign module by overriding __globals__
|
||||
foreign_mod = types.ModuleType("foreignlib")
|
||||
foreign_mod.__name__ = "foreignlib"
|
||||
|
||||
def _foreign_impl():
|
||||
return 99
|
||||
|
||||
foreign_func = types.FunctionType(
|
||||
_foreign_impl.__code__,
|
||||
vars(foreign_mod),
|
||||
"foreign_func",
|
||||
)
|
||||
|
||||
@p.trace_calls()
|
||||
def main_func():
|
||||
foreign_func()
|
||||
return 42
|
||||
|
||||
with p.span("root") as root:
|
||||
main_func()
|
||||
|
||||
main_span = root.children[0]
|
||||
assert main_span.name == "main_func"
|
||||
child_names = [c.name for c in main_span.children]
|
||||
assert "foreign_func" not in child_names, "foreign module must be excluded by default"
|
||||
|
||||
def test_i_can_use_trace_calls_with_custom_include(self, fresh_profiler):
|
||||
"""Test that explicitly listed modules are included even when not the default."""
|
||||
import types
|
||||
p = fresh_profiler
|
||||
|
||||
extra_mod = types.ModuleType("extralib")
|
||||
extra_mod.__name__ = "extralib"
|
||||
|
||||
def _extra_impl():
|
||||
return 0
|
||||
|
||||
extra_func = types.FunctionType(
|
||||
_extra_impl.__code__,
|
||||
vars(extra_mod),
|
||||
"extra_func",
|
||||
)
|
||||
|
||||
current_top = __name__.split('.')[0]
|
||||
|
||||
@p.trace_calls(include=[current_top, "extralib"])
|
||||
def main_func():
|
||||
extra_func()
|
||||
return 42
|
||||
|
||||
with p.span("root") as root:
|
||||
main_func()
|
||||
|
||||
main_span = root.children[0]
|
||||
assert len(main_span.children) == 1, "explicitly included module must be traced"
|
||||
|
||||
def test_i_can_use_trace_calls_with_max_depth(self, fresh_profiler):
|
||||
"""Test that spans beyond max_depth are not recorded."""
|
||||
p = fresh_profiler
|
||||
|
||||
def level3():
|
||||
return 0
|
||||
|
||||
def level2():
|
||||
level3()
|
||||
return 1
|
||||
|
||||
def level1():
|
||||
level2()
|
||||
return 2
|
||||
|
||||
@p.trace_calls(max_depth=2)
|
||||
def main_func():
|
||||
level1()
|
||||
return 42
|
||||
|
||||
with p.span("root") as root:
|
||||
main_func()
|
||||
|
||||
main_span = root.children[0]
|
||||
assert main_span.name == "main_func"
|
||||
assert len(main_span.children) == 1
|
||||
level1_span = main_span.children[0]
|
||||
assert level1_span.name == "level1"
|
||||
assert len(level1_span.children) == 1
|
||||
level2_span = level1_span.children[0]
|
||||
assert level2_span.name == "level2"
|
||||
assert len(level2_span.children) == 0, "level3 must be excluded by max_depth=2"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TestProfilingManager — enable/disable, clear, overhead
|
||||
|
||||
Reference in New Issue
Block a user