|
66 | 66 | from codeflash.code_utils.formatter import format_code, format_generated_code, sort_imports |
67 | 67 | from codeflash.code_utils.git_utils import git_root_dir |
68 | 68 | from codeflash.code_utils.instrument_existing_tests import inject_profiling_into_existing_test |
69 | | -from codeflash.code_utils.line_profile_utils import add_decorator_imports |
| 69 | +from codeflash.code_utils.line_profile_utils import add_decorator_imports, contains_jit_decorator |
70 | 70 | from codeflash.code_utils.static_analysis import get_first_top_level_function_or_method_ast |
71 | 71 | from codeflash.code_utils.time_utils import humanize_runtime |
72 | 72 | from codeflash.context import code_context_extractor |
@@ -2389,6 +2389,23 @@ def get_test_env( |
2389 | 2389 | def line_profiler_step( |
2390 | 2390 | self, code_context: CodeOptimizationContext, original_helper_code: dict[Path, str], candidate_index: int |
2391 | 2391 | ) -> dict: |
| 2392 | + # Check if candidate code contains JIT decorators - line profiler doesn't work with JIT compiled code |
| 2393 | + candidate_fto_code = Path(self.function_to_optimize.file_path).read_text("utf-8") |
| 2394 | + if contains_jit_decorator(candidate_fto_code): |
| 2395 | + logger.info( |
| 2396 | + f"Skipping line profiler for {self.function_to_optimize.function_name} - code contains JIT decorator" |
| 2397 | + ) |
| 2398 | + return {"timings": {}, "unit": 0, "str_out": ""} |
| 2399 | + |
| 2400 | + # Check helper code for JIT decorators |
| 2401 | + for module_abspath in original_helper_code: |
| 2402 | + candidate_helper_code = Path(module_abspath).read_text("utf-8") |
| 2403 | + if contains_jit_decorator(candidate_helper_code): |
| 2404 | + logger.info( |
| 2405 | + f"Skipping line profiler for {self.function_to_optimize.function_name} - helper code contains JIT decorator" |
| 2406 | + ) |
| 2407 | + return {"timings": {}, "unit": 0, "str_out": ""} |
| 2408 | + |
2392 | 2409 | try: |
2393 | 2410 | console.rule() |
2394 | 2411 |
|
|
0 commit comments