Skip to content

Commit e03797c

Browse files
committed
stats
1 parent 28b7bd2 commit e03797c

File tree

1 file changed

+5
-34
lines changed

1 file changed

+5
-34
lines changed

codeflash/benchmarking/function_ranker.py

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

3-
from pathlib import Path
43
from typing import TYPE_CHECKING
54

65
from codeflash.cli_cmds.console import console, logger
@@ -9,6 +8,8 @@
98
from codeflash.tracing.profile_stats import ProfileStats
109

1110
if TYPE_CHECKING:
11+
from pathlib import Path
12+
1213
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
1314

1415

@@ -81,46 +82,16 @@ def load_function_stats(self) -> None:
8182
self._function_stats = {}
8283

8384
def _get_function_stats(self, function_to_optimize: FunctionToOptimize) -> dict | None:
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
11685
target_filename = function_to_optimize.file_path.name
11786
for key, stats in self._function_stats.items():
11887
if stats.get("function_name") == function_to_optimize.function_name and (
11988
key.endswith(f"/{target_filename}") or target_filename in key
12089
):
12190
return stats
12291

123-
logger.debug(f"Could not find stats for function {function_to_optimize.function_name} in {original_path}")
92+
logger.debug(
93+
f"Could not find stats for function {function_to_optimize.function_name} in file {target_filename}"
94+
)
12495
return None
12596

12697
def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float:

0 commit comments

Comments
 (0)