Skip to content

Commit

Permalink
feat: collect plugin stage time
Browse files Browse the repository at this point in the history
  • Loading branch information
k4black committed Dec 13, 2023
1 parent 4043cbd commit 7e72570
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion checker/tester/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import time
from dataclasses import dataclass
from typing import Any, Type

Expand Down Expand Up @@ -35,6 +36,7 @@ class PipelineStageResult:
failed: bool
skipped: bool
percentage: float = 0.0
elapsed_time: float | None = None
output: str = ''

def __str__(self) -> str:
Expand Down Expand Up @@ -135,7 +137,7 @@ def run(
resolved_args = parameters_resolver.resolve(pipeline_stage.args, extra_context=extra_context)
resolved_run_if = parameters_resolver.resolve_single_string(pipeline_stage.run_if, extra_context=extra_context) if pipeline_stage.run_if else None

print_info(f'-> Running "{pipeline_stage.name}" stage:', color='orange')
print_info(f'--> Running "{pipeline_stage.name}" stage:', color='orange')
if self.verbose:
print_info(f' run_if: {pipeline_stage.run_if}', color='grey')
print_info(f' resolved_run_if: {resolved_run_if}', color='grey')
Expand Down Expand Up @@ -182,26 +184,33 @@ def run(
continue

# run the plugin with executor
_start_time = time.perf_counter()
try:
output = plugin.run(resolved_args, verbose=self.verbose)
_end_time = time.perf_counter()
print_info(output or '[empty output]')
print_info(f'> elapsed time: {_end_time-_start_time:.2f}s', color='grey')
print_info('ok!', color='green')
pipeline_stage_results.append(PipelineStageResult(
name=pipeline_stage.name,
failed=False,
skipped=False,
output=output,
percentage=1.0, # TODO: get percentage from plugin
elapsed_time=_end_time-_start_time,
))
except ExecutionFailedError as e:
_end_time = time.perf_counter()
print_info(e.output or '[empty output]')
print_info(f'> elapsed time: {_end_time-_start_time:.2f}s', color='grey')
print_info('error!', color='red')
pipeline_stage_results.append(PipelineStageResult(
name=pipeline_stage.name,
failed=True,
skipped=False,
output=e.output or '',
percentage=0.0, # TODO: get percentage from plugin
elapsed_time=_end_time-_start_time,
))
if pipeline_stage.fail == PipelineStageConfig.FailType.FAST:
skip_the_rest = True
Expand Down
2 changes: 1 addition & 1 deletion checker/tester/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..configs import CheckerTestingConfig
from ..configs.checker import CheckerStructureConfig, CheckerConfig
from ..course import Course, FileSystemTask
from ..exceptions import ExecutionFailedError, ExecutionTimeoutError, RunFailedError, TestingError
from ..exceptions import ExecutionFailedError, TestingError
from .pipeline import PipelineRunner, GlobalPipelineVariables, TaskPipelineVariables, PipelineResult
from ..plugins import load_plugins
from ..utils import print_info, print_header_info, print_separator
Expand Down

0 comments on commit 7e72570

Please sign in to comment.