Skip to content

Commit f91d192

Browse files
authored
output compilation time for each sketch (#61)
1 parent a570356 commit f91d192

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compilesketches/compilesketches.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import atexit
2+
import time
23
import contextlib
34
import enum
45
import json
@@ -893,9 +894,11 @@ def compile_sketch(self, sketch_path, clean_build_cache):
893894
if clean_build_cache:
894895
for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):
895896
shutil.rmtree(path=cache_path)
896-
897+
start_time = time.monotonic()
897898
compilation_data = self.run_arduino_cli_command(
898899
command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False)
900+
diff_time = time.monotonic() - start_time
901+
899902
# Group compilation output to make the log easy to read
900903
# https://github.com/actions/toolkit/blob/master/docs/commands.md#group-and-ungroup-log-lines
901904
print("::group::Compiling sketch:", path_relative_to_workspace(path=sketch_path))
@@ -909,6 +912,14 @@ class CompilationResult:
909912

910913
if not CompilationResult.success:
911914
print("::error::Compilation failed")
915+
else:
916+
time_summary = ""
917+
if diff_time > 60:
918+
if diff_time > 360:
919+
time_summary += f"{int(diff_time / 360)}h "
920+
time_summary += f"{int(diff_time / 60) % 60}m "
921+
time_summary += f"{int(diff_time) % 60}s"
922+
print("Compilation time elapsed:", time_summary)
912923

913924
return CompilationResult()
914925

compilesketches/tests/test_compilesketches.py

+2
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,8 @@ class CompilationData:
14391439
)
14401440
if not expected_success:
14411441
expected_stdout += "\n::error::Compilation failed"
1442+
else:
1443+
expected_stdout += "\nCompilation time elapsed: 0s"
14421444
assert capsys.readouterr().out.strip() == expected_stdout
14431445

14441446
assert compilation_result.sketch == sketch_path

0 commit comments

Comments
 (0)