Skip to content

Commit 28b7bd2

Browse files
committed
Revert "cleanup CI fail"
This reverts commit 6dc844e.
1 parent 6dc844e commit 28b7bd2

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

codeflash/benchmarking/function_ranker.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
34
from typing import TYPE_CHECKING
45

56
from codeflash.cli_cmds.console import console, logger
@@ -8,8 +9,6 @@
89
from codeflash.tracing.profile_stats import ProfileStats
910

1011
if TYPE_CHECKING:
11-
from pathlib import Path
12-
1312
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
1413

1514

@@ -82,14 +81,47 @@ def load_function_stats(self) -> None:
8281
self._function_stats = {}
8382

8483
def _get_function_stats(self, function_to_optimize: FunctionToOptimize) -> dict | None:
85-
file_path = function_to_optimize.file_path.as_posix()
86-
key1 = f"{file_path}:{function_to_optimize.qualified_name}"
87-
key2 = f"{file_path}:{function_to_optimize.function_name}"
88-
89-
stats = self._function_stats.get(key1)
90-
if stats is not None:
91-
return stats
92-
return self._function_stats.get(key2)
84+
# Get all possible path variations
85+
original_path = function_to_optimize.file_path.as_posix()
86+
resolved_path = function_to_optimize.file_path.resolve().as_posix()
87+
88+
# Try to get relative path from current working directory
89+
try:
90+
cwd_relative = function_to_optimize.file_path.relative_to(Path.cwd()).as_posix()
91+
except ValueError:
92+
cwd_relative = original_path
93+
94+
# Try to get relative path from trace file directory
95+
try:
96+
trace_dir = self.trace_file_path.parent
97+
trace_relative = function_to_optimize.file_path.relative_to(trace_dir).as_posix()
98+
except ValueError:
99+
trace_relative = original_path
100+
101+
# All possible path variants to try
102+
path_variants = [original_path, resolved_path, cwd_relative, trace_relative]
103+
104+
for file_path in path_variants:
105+
key1 = f"{file_path}:{function_to_optimize.qualified_name}"
106+
key2 = f"{file_path}:{function_to_optimize.function_name}"
107+
108+
stats = self._function_stats.get(key1)
109+
if stats is not None:
110+
return stats
111+
stats = self._function_stats.get(key2)
112+
if stats is not None:
113+
return stats
114+
115+
# Try fuzzy matching as last resort - match by function name and filename
116+
target_filename = function_to_optimize.file_path.name
117+
for key, stats in self._function_stats.items():
118+
if stats.get("function_name") == function_to_optimize.function_name and (
119+
key.endswith(f"/{target_filename}") or target_filename in key
120+
):
121+
return stats
122+
123+
logger.debug(f"Could not find stats for function {function_to_optimize.function_name} in {original_path}")
124+
return None
93125

94126
def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float:
95127
stats = self._get_function_stats(function_to_optimize)

tests/test_function_ranker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def trace_file():
1414

1515
@pytest.fixture
1616
def workload_functions():
17-
workloads_file = (Path(__file__).parent.parent / "code_to_optimize/code_directories/simple_tracer_e2e/workload.py").resolve()
17+
workloads_file = Path(__file__).parent.parent / "code_to_optimize/code_directories/simple_tracer_e2e/workload.py"
1818
functions_dict = find_all_functions_in_file(workloads_file)
1919
all_functions = []
2020
for functions_list in functions_dict.values():

0 commit comments

Comments
 (0)