|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from pathlib import Path |
4 | 3 | from typing import TYPE_CHECKING |
5 | 4 |
|
6 | 5 | from codeflash.cli_cmds.console import console, logger |
|
9 | 8 | from codeflash.tracing.profile_stats import ProfileStats |
10 | 9 |
|
11 | 10 | if TYPE_CHECKING: |
| 11 | + from pathlib import Path |
| 12 | + |
12 | 13 | from codeflash.discovery.functions_to_optimize import FunctionToOptimize |
13 | 14 |
|
14 | 15 |
|
@@ -81,46 +82,16 @@ def load_function_stats(self) -> None: |
81 | 82 | self._function_stats = {} |
82 | 83 |
|
83 | 84 | 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 |
116 | 85 | target_filename = function_to_optimize.file_path.name |
117 | 86 | for key, stats in self._function_stats.items(): |
118 | 87 | if stats.get("function_name") == function_to_optimize.function_name and ( |
119 | 88 | key.endswith(f"/{target_filename}") or target_filename in key |
120 | 89 | ): |
121 | 90 | return stats |
122 | 91 |
|
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 | + ) |
124 | 95 | return None |
125 | 96 |
|
126 | 97 | def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float: |
|
0 commit comments