Skip to content

Commit

Permalink
output compilation time for each sketch (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 authored Apr 18, 2022
1 parent a570356 commit f91d192
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion compilesketches/compilesketches.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import atexit
import time
import contextlib
import enum
import json
Expand Down Expand Up @@ -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))
Expand All @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions compilesketches/tests/test_compilesketches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f91d192

Please sign in to comment.