Skip to content

Commit

Permalink
Use normal casing and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Sep 5, 2024
1 parent 567816a commit 273b2b0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
14 changes: 2 additions & 12 deletions src/ert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
26 changes: 15 additions & 11 deletions src/ert/gui/simulation/experiment_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"] = (
Expand All @@ -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"] = (
Expand All @@ -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)
8 changes: 4 additions & 4 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/ert/shared/status/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math
import os
import resource
import sys


def byte_with_unit(byte_count: float) -> str:
Expand Down Expand Up @@ -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
29 changes: 28 additions & 1 deletion tests/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit 273b2b0

Please sign in to comment.