From 273b2b07e3f2aa7f7ecc1df3e1eccac2e6129817 Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Thu, 5 Sep 2024 13:22:41 +0200 Subject: [PATCH] Use normal casing and add test --- src/ert/__main__.py | 14 ++------- src/ert/gui/simulation/experiment_panel.py | 26 ++++++++++------- src/ert/gui/simulation/run_dialog.py | 8 ++--- src/ert/shared/status/utils.py | 13 +++++++++ .../gui/simulation/test_run_dialog.py | 29 ++++++++++++++++++- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/ert/__main__.py b/src/ert/__main__.py index 3a26b42dbdc..11f3e29c4c2 100755 --- a/src/ert/__main__.py +++ b/src/ert/__main__.py @@ -614,17 +614,7 @@ def ert_parser(parser: Optional[ArgumentParser], args: Sequence[str]) -> Namespa def log_process_usage() -> None: try: usage = resource.getrusage(resource.RUSAGE_SELF) - - if sys.platform == "darwin": - # macOS apparently outputs the maxrss value as bytes rather than - # kilobytes as on Linux. - # - # https://stackoverflow.com/questions/59913657/strange-values-of-get-rusage-maxrss-on-macos-and-linux - rss_scale = 1000 - else: - rss_scale = 1 - - maxrss = usage.ru_maxrss // rss_scale + max_rss = ert.shared.status.utils.get_ert_memory_usage() usage_dict: Dict[str, Union[int, float]] = { "User time": usage.ru_utime, @@ -635,7 +625,7 @@ def log_process_usage() -> None: "Socket messages Received": usage.ru_msgrcv, "Signals received": usage.ru_nsignals, "Swaps": usage.ru_nswap, - "Peak memory use (KB)": maxrss, + "Peak memory use (KB)": max_rss, } logger.info(f"Ert process usage: {usage_dict}") except Exception as exc: diff --git a/src/ert/gui/simulation/experiment_panel.py b/src/ert/gui/simulation/experiment_panel.py index 94c1b721bbc..9e0a251b557 100644 --- a/src/ert/gui/simulation/experiment_panel.py +++ b/src/ert/gui/simulation/experiment_panel.py @@ -26,7 +26,11 @@ from ert.gui.ertnotifier import ErtNotifier from ert.run_models import BaseRunModel, StatusEvents, create_model -from ert.shared.status.utils import byte_with_unit, format_running_time +from ert.shared.status.utils import ( + byte_with_unit, + format_running_time, + get_ert_memory_usage, +) from .combobox_with_description import QComboBoxWithDescription from .ensemble_experiment_panel import EnsembleExperimentPanel @@ -315,7 +319,6 @@ def validationStatusChanged(self) -> None: ) def populate_clipboard_debug_info(self) -> None: - output = "" kv = {"**Platform**": "", ":-----": ":-----"} kv["Date"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") kv["OS"] = ( @@ -325,17 +328,17 @@ def populate_clipboard_debug_info(self) -> None: for e in ["KOMODO_RELEASE"]: if e in os.environ: - kv[e.capitalize()] = os.environ[e] + kv["Komodo release"] = os.environ[e] - kv["Python Version"] = platform.python_version() + kv["Python version"] = platform.python_version() kv["**Ensemble**"] = "" - kv["Queue"] = self.config.queue_config.queue_system.name - kv["Simulation Mode"] = self.get_current_experiment_type().name() + kv["Queue"] = self.config.queue_config.queue_system.name.capitalize() + kv["Simulation mode"] = self.get_current_experiment_type().name() kv["Config file"] = self._config_file - kv["Ensemble Path"] = self.config.ens_path - kv["Ensemble Size"] = str(self._model.ensemble_size) - kv["Max Running"] = str(self.config.queue_config.queue_options.max_running) + kv["Ensemble path"] = self.config.ens_path + kv["Ensemble size"] = str(self._model.ensemble_size) + kv["Max running"] = str(self.config.queue_config.queue_options.max_running) kv["**Status**"] = "" kv["Running time"] = ( @@ -345,11 +348,12 @@ def populate_clipboard_debug_info(self) -> None: for status, count in self._model.get_current_status().items(): kv[status] = str(count) - kv["Max Memory Consumption"] = byte_with_unit( + kv["Ert max memory"] = byte_with_unit(get_ert_memory_usage()) + kv["Forward model max memory"] = byte_with_unit( self._model.get_memory_consumption() ) - output += create_md_table(kv, output) + output = create_md_table(kv, "") clipboard = QApplication.clipboard() if clipboard: clipboard.setText(output) diff --git a/src/ert/gui/simulation/run_dialog.py b/src/ert/gui/simulation/run_dialog.py index dbbe0ed4817..a9ae712dae5 100644 --- a/src/ert/gui/simulation/run_dialog.py +++ b/src/ert/gui/simulation/run_dialog.py @@ -235,9 +235,9 @@ def __init__( self.done_button.setHidden(True) self.restart_button = QPushButton("Restart") self.restart_button.setHidden(True) - self.copy_debug_info = QPushButton("Debug Info") - self.copy_debug_info.setToolTip("Copies useful information to clipboard") - self.copy_debug_info.clicked.connect(self.produce_clipboard_debug_info) + self.copy_debug_info_button = QPushButton("Debug Info") + self.copy_debug_info_button.setToolTip("Copies useful information to clipboard") + self.copy_debug_info_button.clicked.connect(self.produce_clipboard_debug_info) size = 20 spin_movie = QMovie("img:loading.gif") @@ -256,7 +256,7 @@ def __init__( button_layout.addStretch() button_layout.addWidget(self.memory_usage) button_layout.addStretch() - button_layout.addWidget(self.copy_debug_info) + button_layout.addWidget(self.copy_debug_info_button) button_layout.addWidget(self.plot_button) button_layout.addWidget(self.kill_button) button_layout.addWidget(self.done_button) diff --git a/src/ert/shared/status/utils.py b/src/ert/shared/status/utils.py index 0836e695390..99c905f542e 100644 --- a/src/ert/shared/status/utils.py +++ b/src/ert/shared/status/utils.py @@ -1,5 +1,7 @@ import math import os +import resource +import sys def byte_with_unit(byte_count: float) -> str: @@ -69,3 +71,14 @@ def file_has_content(file_path: str) -> bool: if file_path_exists: return os.path.getsize(file_path) > 0 return False + + +def get_ert_memory_usage() -> int: + usage = resource.getrusage(resource.RUSAGE_SELF) + rss_scale = 1 + if sys.platform == "darwin": + # macOS apparently outputs the maxrss value as bytes rather than kilobytes as on Linux. + # https://stackoverflow.com/questions/59913657/strange-values-of-get-rusage-maxrss-on-macos-and-linux + rss_scale = 1000 + + return usage.ru_maxrss // rss_scale diff --git a/tests/unit_tests/gui/simulation/test_run_dialog.py b/tests/unit_tests/gui/simulation/test_run_dialog.py index 964453d3623..ae0a63d7b1b 100644 --- a/tests/unit_tests/gui/simulation/test_run_dialog.py +++ b/tests/unit_tests/gui/simulation/test_run_dialog.py @@ -6,7 +6,7 @@ from pytestqt.qtbot import QtBot from qtpy import QtWidgets from qtpy.QtCore import Qt, QTimer -from qtpy.QtWidgets import QComboBox, QToolButton, QWidget +from qtpy.QtWidgets import QApplication, QComboBox, QToolButton, QWidget import ert from ert.config import ErtConfig @@ -553,6 +553,33 @@ def handle_error_dialog(run_dialog): qtbot.waitUntil(run_dialog.done_button.isVisible, timeout=200000) +@pytest.mark.usefixtures("use_tmpdir") +def test_that_debug_info_button_provides_data_in_clipboard(qtbot: QtBot, storage): + config_file = "minimal_config.ert" + with open(config_file, "w", encoding="utf-8") as f: + f.write("NUM_REALIZATIONS 1") + args_mock = Mock() + args_mock.config = config_file + + ert_config = ErtConfig.from_file(config_file) + with StorageService.init_service( + project=os.path.abspath(ert_config.ens_path), + ): + gui = _setup_main_window(ert_config, args_mock, GUILogHandler(), storage) + qtbot.addWidget(gui) + + run_experiment = gui.findChild(QToolButton, name="run_experiment") + qtbot.mouseClick(run_experiment, Qt.LeftButton) + + run_dialog = wait_for_child(gui, qtbot, RunDialog) + qtbot.mouseClick(run_dialog.copy_debug_info_button, Qt.LeftButton) + + clipboard_text = QApplication.clipboard().text() + + for keyword in ["Single realization test-run", "Local", r"minimal\_config.ert"]: + assert keyword in clipboard_text + + def test_that_stdout_and_stderr_buttons_react_to_file_content( snake_oil_case_storage: ErtConfig, qtbot: QtBot ):