|
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 |
@@ -2412,6 +2412,23 @@ def get_test_env( |
2412 | 2412 | def line_profiler_step( |
2413 | 2413 | self, code_context: CodeOptimizationContext, original_helper_code: dict[Path, str], candidate_index: int |
2414 | 2414 | ) -> dict: |
| 2415 | + # Check if candidate code contains JIT decorators - line profiler doesn't work with JIT compiled code |
| 2416 | + candidate_fto_code = Path(self.function_to_optimize.file_path).read_text("utf-8") |
| 2417 | + if contains_jit_decorator(candidate_fto_code): |
| 2418 | + logger.info( |
| 2419 | + f"Skipping line profiler for {self.function_to_optimize.function_name} - code contains JIT decorator" |
| 2420 | + ) |
| 2421 | + return {"timings": {}, "unit": 0, "str_out": ""} |
| 2422 | + |
| 2423 | + # Check helper code for JIT decorators |
| 2424 | + for module_abspath in original_helper_code: |
| 2425 | + candidate_helper_code = Path(module_abspath).read_text("utf-8") |
| 2426 | + if contains_jit_decorator(candidate_helper_code): |
| 2427 | + logger.info( |
| 2428 | + f"Skipping line profiler for {self.function_to_optimize.function_name} - helper code contains JIT decorator" |
| 2429 | + ) |
| 2430 | + return {"timings": {}, "unit": 0, "str_out": ""} |
| 2431 | + |
2415 | 2432 | try: |
2416 | 2433 | console.rule() |
2417 | 2434 |
|
|
0 commit comments