diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py index 1be7b97..a9ec404 100644 --- a/compilesketches/compilesketches.py +++ b/compilesketches/compilesketches.py @@ -1,4 +1,5 @@ import atexit +import time import contextlib import enum import json @@ -893,9 +894,11 @@ def compile_sketch(self, sketch_path, clean_build_cache): if clean_build_cache: for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"): shutil.rmtree(path=cache_path) - + start_time = time.monotonic() compilation_data = self.run_arduino_cli_command( command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False) + diff_time = time.monotonic() - start_time + # Group compilation output to make the log easy to read # https://github.com/actions/toolkit/blob/master/docs/commands.md#group-and-ungroup-log-lines print("::group::Compiling sketch:", path_relative_to_workspace(path=sketch_path)) @@ -909,6 +912,14 @@ class CompilationResult: if not CompilationResult.success: print("::error::Compilation failed") + else: + time_summary = "" + if diff_time > 60: + if diff_time > 360: + time_summary += f"{int(diff_time / 360)}h " + time_summary += f"{int(diff_time / 60) % 60}m " + time_summary += f"{int(diff_time) % 60}s" + print("Compilation time elapsed:", time_summary) return CompilationResult() diff --git a/compilesketches/tests/test_compilesketches.py b/compilesketches/tests/test_compilesketches.py index 8074f2f..60b713d 100644 --- a/compilesketches/tests/test_compilesketches.py +++ b/compilesketches/tests/test_compilesketches.py @@ -1439,6 +1439,8 @@ class CompilationData: ) if not expected_success: expected_stdout += "\n::error::Compilation failed" + else: + expected_stdout += "\nCompilation time elapsed: 0s" assert capsys.readouterr().out.strip() == expected_stdout assert compilation_result.sketch == sketch_path