From 7e72570be2defc58c6f04659a2905b48143d0853 Mon Sep 17 00:00:00 2001 From: Konstantin Chernyshev Date: Wed, 13 Dec 2023 21:57:28 +0100 Subject: [PATCH] feat: collect plugin stage time --- checker/tester/pipeline.py | 11 ++++++++++- checker/tester/tester.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/checker/tester/pipeline.py b/checker/tester/pipeline.py index a8432ce..4ac0fa5 100644 --- a/checker/tester/pipeline.py +++ b/checker/tester/pipeline.py @@ -1,5 +1,6 @@ from __future__ import annotations +import time from dataclasses import dataclass from typing import Any, Type @@ -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: @@ -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') @@ -182,9 +184,12 @@ 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, @@ -192,9 +197,12 @@ def run( 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, @@ -202,6 +210,7 @@ def run( 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 diff --git a/checker/tester/tester.py b/checker/tester/tester.py index 2762bf9..c50c587 100644 --- a/checker/tester/tester.py +++ b/checker/tester/tester.py @@ -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