Skip to content

Commit 7f1c7e5

Browse files
committed
rename callpattern
1 parent 5ee0995 commit 7f1c7e5

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

src/vivarium_profiling/tools/extraction.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Data extraction utilities for benchmark profiling results.
22
33
This module provides configurable extraction of profiling metrics from cProfile
4-
stats files and memory profiler output. The extraction is driven by CallPattern
5-
objects that map logical names to regex patterns for matching function calls.
4+
stats files and memory profiler output. The extraction is driven by
5+
FunctionCallConfiguration objects that map logical names to regex patterns for
6+
matching function calls.
67
"""
78

89
from __future__ import annotations
@@ -17,7 +18,7 @@
1718

1819

1920
@dataclass
20-
class CallPattern:
21+
class FunctionCallConfiguration:
2122
"""Configuration for extracting metrics for a specific function from cProfile stats.
2223
2324
Attributes
@@ -88,8 +89,10 @@ def columns(self) -> list[str]:
8889
return cols
8990

9091

91-
def bottleneck_config(name: str, filename: str, function_name: str) -> CallPattern:
92-
"""Create a CallPattern for a bottleneck function (extracts all 3 metrics).
92+
def bottleneck_config(
93+
name: str, filename: str, function_name: str
94+
) -> FunctionCallConfiguration:
95+
"""Create a FunctionCallConfiguration for a bottleneck function (extracts all 3 metrics).
9396
9497
Parameters
9598
----------
@@ -102,10 +105,10 @@ def bottleneck_config(name: str, filename: str, function_name: str) -> CallPatte
102105
103106
Returns
104107
-------
105-
CallPattern configured for bottleneck extraction.
108+
FunctionCallConfiguration configured for bottleneck extraction.
106109
107110
"""
108-
return CallPattern(
111+
return FunctionCallConfiguration(
109112
name=name,
110113
filename=filename,
111114
function_name=function_name,
@@ -115,8 +118,10 @@ def bottleneck_config(name: str, filename: str, function_name: str) -> CallPatte
115118
)
116119

117120

118-
def phase_config(name: str, filename: str = "/vivarium/framework/engine.py") -> CallPattern:
119-
"""Create a CallPattern for a simulation phase (extracts cumtime only).
121+
def phase_config(
122+
name: str, filename: str = "/vivarium/framework/engine.py"
123+
) -> FunctionCallConfiguration:
124+
"""Create a FunctionCallConfiguration for a simulation phase (extracts cumtime only).
120125
121126
Parameters
122127
----------
@@ -127,10 +132,10 @@ def phase_config(name: str, filename: str = "/vivarium/framework/engine.py") ->
127132
128133
Returns
129134
-------
130-
CallPattern configured for phase extraction.
135+
FunctionCallConfiguration configured for phase extraction.
131136
132137
"""
133-
return CallPattern(
138+
return FunctionCallConfiguration(
134139
name=name,
135140
filename=filename,
136141
function_name=name,
@@ -177,11 +182,11 @@ class ExtractionConfig:
177182
Attributes
178183
----------
179184
patterns
180-
List of CallPattern objects defining what metrics to extract.
185+
List of FunctionCallConfiguration objects defining what metrics to extract.
181186
182187
"""
183188

184-
def __init__(self, patterns: list[CallPattern] | None = None):
189+
def __init__(self, patterns: list[FunctionCallConfiguration] | None = None):
185190
if patterns is None:
186191
patterns = DEFAULT_BOTTLENECKS + DEFAULT_PHASES
187192
self.patterns = patterns

tests/test_extraction.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"""Unit tests for extraction utilities."""
22

33
from vivarium_profiling.tools.extraction import (
4-
CallPattern,
54
ExtractionConfig,
5+
FunctionCallConfiguration,
66
bottleneck_config,
77
extract_runtime,
88
parse_function_metrics,
99
phase_config,
1010
)
1111

1212

13-
class TestCallPattern:
14-
"""Tests for CallPattern dataclass."""
13+
class TestFunctionCallConfiguration:
14+
"""Tests for FunctionCallConfiguration dataclass."""
1515

16-
def test_call_pattern_defaults(self):
17-
"""Test CallPattern with default extraction flags."""
18-
pattern = CallPattern(name="test_func", filename="test.py", function_name="test_func")
16+
def test_function_call_configuration_defaults(self):
17+
"""Test FunctionCallConfiguration with default extraction flags."""
18+
pattern = FunctionCallConfiguration(
19+
name="test_func", filename="test.py", function_name="test_func"
20+
)
1921

2022
assert pattern.name == "test_func"
2123
assert pattern.filename == "test.py"
@@ -29,9 +31,9 @@ def test_call_pattern_defaults(self):
2931
assert pattern.ncalls_col == "test_func_ncalls"
3032
assert pattern.columns == ["test_func_cumtime"]
3133

32-
def test_call_pattern_all_extracts(self):
33-
"""Test CallPattern with all extraction flags enabled."""
34-
pattern = CallPattern(
34+
def test_function_call_configuration_all_extracts(self):
35+
"""Test FunctionCallConfiguration with all extraction flags enabled."""
36+
pattern = FunctionCallConfiguration(
3537
name="bottleneck",
3638
filename="test.py",
3739
function_name="bottleneck",
@@ -47,9 +49,9 @@ def test_call_pattern_all_extracts(self):
4749
"bottleneck_ncalls",
4850
]
4951

50-
def test_call_pattern_custom_templates(self):
51-
"""Test CallPattern with custom column templates."""
52-
pattern = CallPattern(
52+
def test_function_call_configuration_custom_templates(self):
53+
"""Test FunctionCallConfiguration with custom column templates."""
54+
pattern = FunctionCallConfiguration(
5355
name="phase",
5456
filename="engine.py",
5557
function_name="phase",
@@ -76,7 +78,7 @@ def test_extraction_config_defaults(self):
7678
def test_extraction_config_custom_patterns(self):
7779
"""Test ExtractionConfig with custom patterns."""
7880
patterns = [
79-
CallPattern("func1", "test.py", "func1"),
81+
FunctionCallConfiguration("func1", "test.py", "func1"),
8082
bottleneck_config("func2", "test.py", "func2"),
8183
]
8284
config = ExtractionConfig(patterns=patterns)
@@ -87,16 +89,18 @@ def test_extraction_config_custom_patterns(self):
8789
def test_metric_columns(self):
8890
"""Test metric_columns property."""
8991
patterns = [
90-
CallPattern("a", "test.py", "a", extract_cumtime=True, extract_percall=True),
91-
CallPattern("b", "test.py", "b", extract_cumtime=True),
92+
FunctionCallConfiguration(
93+
"a", "test.py", "a", extract_cumtime=True, extract_percall=True
94+
),
95+
FunctionCallConfiguration("b", "test.py", "b", extract_cumtime=True),
9296
]
9397
config = ExtractionConfig(patterns=patterns)
9498

9599
assert config.metric_columns == ["a_cumtime", "a_percall", "b_cumtime"]
96100

97101
def test_results_columns(self):
98102
"""Test results_columns includes base columns."""
99-
patterns = [CallPattern("test", "test.py", "test")]
103+
patterns = [FunctionCallConfiguration("test", "test.py", "test")]
100104
config = ExtractionConfig(patterns=patterns)
101105

102106
cols = config.results_columns
@@ -181,7 +185,7 @@ def test_extract_metrics_default_patterns(self, sample_stats_file):
181185
def test_extract_metrics_custom_patterns(self, sample_stats_file):
182186
"""Test extracting metrics with custom patterns."""
183187
patterns = [
184-
CallPattern(
188+
FunctionCallConfiguration(
185189
"custom_func",
186190
"some/custom/module.py",
187191
"custom_function",
@@ -202,7 +206,7 @@ def test_extract_metrics_custom_patterns(self, sample_stats_file):
202206

203207
def test_extract_metrics_missing_patterns(self, sample_stats_file):
204208
"""Test extracting metrics when patterns don't match."""
205-
patterns = [CallPattern("missing", "nonexistent.py", "missing")]
209+
patterns = [FunctionCallConfiguration("missing", "nonexistent.py", "missing")]
206210
config = ExtractionConfig(patterns=patterns)
207211
metrics = config.extract_metrics(sample_stats_file)
208212

0 commit comments

Comments
 (0)