diff --git a/codeflash/api/cfapi.py b/codeflash/api/cfapi.py index 37edcf793..67ca749c2 100644 --- a/codeflash/api/cfapi.py +++ b/codeflash/api/cfapi.py @@ -171,6 +171,8 @@ def suggest_changes( replay_tests: str = "", concolic_tests: str = "", optimization_review: str = "", + original_line_profiler: str = "", + optimized_line_profiler: str = "", ) -> Response: """Suggest changes to a pull request. @@ -182,6 +184,8 @@ def suggest_changes( :param file_changes: A dictionary of file changes. :param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc. :param generated_tests: The generated tests. + :param original_line_profiler: Line profiler results for original code (markdown format). + :param optimized_line_profiler: Line profiler results for optimized code (markdown format). :return: The response object. """ payload = { @@ -198,6 +202,13 @@ def suggest_changes( "concolicTests": concolic_tests, "optimizationReview": optimization_review, # impact keyword left for legacy reasons, touches js/ts code } + + # Add line profiler data if available + if original_line_profiler: + payload["originalLineProfiler"] = original_line_profiler + if optimized_line_profiler: + payload["optimizedLineProfiler"] = optimized_line_profiler + return make_cfapi_request(endpoint="/suggest-pr-changes", method="POST", payload=payload) @@ -214,6 +225,8 @@ def create_pr( replay_tests: str = "", concolic_tests: str = "", optimization_review: str = "", + original_line_profiler: str = "", + optimized_line_profiler: str = "", ) -> Response: """Create a pull request, targeting the specified branch. (usually 'main'). @@ -223,6 +236,8 @@ def create_pr( :param file_changes: A dictionary of file changes. :param pr_comment: The pull request comment object, containing the optimization explanation, best runtime, etc. :param generated_tests: The generated tests. + :param original_line_profiler: Line profiler results for original code (markdown format). + :param optimized_line_profiler: Line profiler results for optimized code (markdown format). :return: The response object. """ # convert Path objects to strings @@ -240,6 +255,13 @@ def create_pr( "concolicTests": concolic_tests, "optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase } + + # Add line profiler data if available + if original_line_profiler: + payload["originalLineProfiler"] = original_line_profiler + if optimized_line_profiler: + payload["optimizedLineProfiler"] = optimized_line_profiler + return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload) @@ -269,6 +291,8 @@ def create_staging( concolic_tests: str, root_dir: Path, optimization_review: str = "", + original_line_profiler: str = "", + optimized_line_profiler: str = "", ) -> Response: """Create a staging pull request, targeting the specified branch. (usually 'staging'). @@ -279,6 +303,8 @@ def create_staging( :param generated_original_test_source: Generated tests for the original function. :param function_trace_id: Unique identifier for this optimization trace. :param coverage_message: Coverage report or summary. + :param original_line_profiler: Line profiler results for original code (markdown format). + :param optimized_line_profiler: Line profiler results for optimized code (markdown format). :return: The response object from the backend. """ relative_path = explanation.file_path.relative_to(root_dir).as_posix() @@ -312,6 +338,12 @@ def create_staging( "optimizationReview": optimization_review, # Impact keyword left for legacy reasons, it touches js/ts codebase } + # Add line profiler data if available + if original_line_profiler: + payload["originalLineProfiler"] = original_line_profiler + if optimized_line_profiler: + payload["optimizedLineProfiler"] = optimized_line_profiler + return make_cfapi_request(endpoint="/create-staging", method="POST", payload=payload) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index 697061b9c..6fd178a36 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -1999,6 +1999,8 @@ def process_review( "coverage_message": coverage_message, "replay_tests": replay_tests, "concolic_tests": concolic_tests, + "original_line_profiler": original_code_baseline.line_profile_results.get("str_out", ""), + "optimized_line_profiler": best_optimization.line_profiler_test_results.get("str_out", ""), } raise_pr = not self.args.no_pr diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index f888f710a..baf65e8da 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -186,6 +186,8 @@ def check_create_pr( root_dir: Path, git_remote: Optional[str] = None, optimization_review: str = "", + original_line_profiler: str = "", + optimized_line_profiler: str = "", ) -> None: pr_number: Optional[int] = env_utils.get_pr_number() git_repo = git.Repo(search_parent_directories=True) @@ -230,6 +232,8 @@ def check_create_pr( replay_tests=replay_tests, concolic_tests=concolic_tests, optimization_review=optimization_review, + original_line_profiler=original_line_profiler, + optimized_line_profiler=optimized_line_profiler, ) if response.ok: logger.info(f"Suggestions were successfully made to PR #{pr_number}") @@ -282,6 +286,8 @@ def check_create_pr( replay_tests=replay_tests, concolic_tests=concolic_tests, optimization_review=optimization_review, + original_line_profiler=original_line_profiler, + optimized_line_profiler=optimized_line_profiler, ) if response.ok: pr_id = response.text