From f80df4bc9b7d122eb2ec9e7c54cd817fbac73e10 Mon Sep 17 00:00:00 2001 From: Sondre Sortland Date: Sun, 15 Sep 2024 19:21:06 +0200 Subject: [PATCH] Add event timestamps and runtime info --- src/ert/analysis/event.py | 6 +++++- src/ert/ensemble_evaluator/event.py | 5 ++++- src/ert/gui/simulation/run_dialog.py | 15 ++++++++++++--- src/ert/run_models/event.py | 9 ++++++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/ert/analysis/event.py b/src/ert/analysis/event.py index dd4acb480e9..5901c9b4520 100644 --- a/src/ert/analysis/event.py +++ b/src/ert/analysis/event.py @@ -2,7 +2,8 @@ import re from collections.abc import Sequence -from dataclasses import dataclass +from dataclasses import dataclass, field +from datetime import datetime from pathlib import Path from typing import Dict, List, Optional, Union, Literal @@ -18,6 +19,7 @@ class AnalysisEvent: class AnalysisStatusEvent(AnalysisEvent): msg: str event_type: Literal['AnalysisStatusEvent'] = 'AnalysisStatusEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass @@ -25,12 +27,14 @@ class AnalysisTimeEvent(AnalysisEvent): remaining_time: float elapsed_time: float event_type: Literal['AnalysisTimeEvent'] = 'AnalysisTimeEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass class AnalysisReportEvent(AnalysisEvent): report: str event_type: Literal['AnalysisReportEvent'] = 'AnalysisReportEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass diff --git a/src/ert/ensemble_evaluator/event.py b/src/ert/ensemble_evaluator/event.py index f5037cf167b..85e5c0664e8 100644 --- a/src/ert/ensemble_evaluator/event.py +++ b/src/ert/ensemble_evaluator/event.py @@ -1,4 +1,5 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field +from datetime import datetime from typing import Dict, Literal, Optional from .snapshot import Snapshot @@ -13,6 +14,7 @@ class _UpdateEvent: realization_count: int status_count: Dict[str, int] iteration: int + timestamp: datetime = field(default_factory=datetime.now) @dataclass @@ -32,3 +34,4 @@ class EndEvent: failed: bool msg: Optional[str] = None event_type: Literal['EndEvent'] = 'EndEvent' + timestamp: datetime = field(default_factory=datetime.now) diff --git a/src/ert/gui/simulation/run_dialog.py b/src/ert/gui/simulation/run_dialog.py index da8b917d331..659dd3de726 100644 --- a/src/ert/gui/simulation/run_dialog.py +++ b/src/ert/gui/simulation/run_dialog.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +from datetime import datetime from pathlib import Path from typing import Optional @@ -221,6 +222,8 @@ def __init__( self._job_label = QLabel(self) self._job_overview = JobOverview(self._snapshot_model, self) + self._start_time: datetime = None + self._end_time: datetime = None self.running_time = QLabel("") self.memory_usage = QLabel("") @@ -397,9 +400,12 @@ def _on_simulation_done(self, failed: bool, msg: str) -> None: @Slot() def _on_ticker(self) -> None: - runtime = 0 - # runtime = self._run_model.get_runtime() - # TODO: This should be based event timestamps + if self._start_time is None: + runtime = 0 + elif self._end_time is None: + runtime = (datetime.now() - self._start_time).total_seconds() + else: + runtime = (self._end_time - self._start_time).total_seconds() self.running_time.setText(format_running_time(runtime)) maximum_memory_usage = self._snapshot_model.root.max_memory_usage @@ -411,7 +417,10 @@ def _on_ticker(self) -> None: @Slot(object) def _on_event(self, event: object) -> None: + if self._start_time is None: + self._start_time = event.timestamp if isinstance(event, EndEvent): + self._end_time = event.timestamp self.simulation_done.emit(event.failed, event.msg) self._ticker.stop() self.done_button.setHidden(False) diff --git a/src/ert/run_models/event.py b/src/ert/run_models/event.py index dd42953a138..839c476b786 100644 --- a/src/ert/run_models/event.py +++ b/src/ert/run_models/event.py @@ -1,6 +1,7 @@ from __future__ import annotations -from dataclasses import dataclass +from dataclasses import dataclass, field +from datetime import datetime from typing import Optional, Literal from uuid import UUID @@ -17,6 +18,7 @@ class RunModelEvent: class RunModelStatusEvent(RunModelEvent): msg: str event_type: Literal['RunModelStatusEvent'] = 'RunModelStatusEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass @@ -24,11 +26,13 @@ class RunModelTimeEvent(RunModelEvent): remaining_time: float elapsed_time: float event_type: Literal['RunModelTimeEvent'] = 'RunModelTimeEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass class RunModelUpdateBeginEvent(RunModelEvent): event_type: Literal['RunModelUpdateBeginEvent'] = 'RunModelUpdateBeginEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass @@ -36,12 +40,14 @@ class RunModelDataEvent(RunModelEvent): name: str data: DataSection event_type: Literal['RunModelDataEvent'] = 'RunModelDataEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass class RunModelUpdateEndEvent(RunModelEvent): data: DataSection event_type: Literal['RunModelUpdateEndEvent'] = 'RunModelUpdateEndEvent' + timestamp: datetime = field(default_factory=datetime.now) @dataclass @@ -49,3 +55,4 @@ class RunModelErrorEvent(RunModelEvent): error_msg: str data: Optional[DataSection] = None event_type: Literal['RunModelErrorEvent'] = 'RunModelErrorEvent' + timestamp: datetime = field(default_factory=datetime.now)