Skip to content

Commit

Permalink
Add disk space status to gui
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Nov 26, 2024
1 parent 7b3e18f commit 642876f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from ert.run_models.event import RunModelDataEvent, RunModelErrorEvent
from ert.shared.status.utils import (
byte_with_unit,
disk_space_status,
file_has_content,
format_running_time,
)
Expand Down Expand Up @@ -195,6 +196,8 @@ def __init__(
self._ticker = QTimer(self)
self._ticker.timeout.connect(self._on_ticker)

self.run_path_mp = run_model.run_paths._runpath_format

self._total_progress_label = QLabel(
_TOTAL_PROGRESS_TEMPLATE.format(
total_progress=0, iteration_label="Starting..."
Expand All @@ -220,6 +223,7 @@ def __init__(

self.running_time = QLabel("")
self.memory_usage = QLabel("")
self.disk_space = QLabel("")

self.kill_button = QPushButton("Terminate experiment")
self.restart_button = QPushButton("Rerun failed")
Expand All @@ -245,6 +249,8 @@ def __init__(
button_layout.addStretch()
button_layout.addWidget(self.memory_usage)
button_layout.addStretch()
button_layout.addWidget(self.disk_space)
button_layout.addStretch()
button_layout.addWidget(self.copy_debug_info_button)
button_layout.addWidget(self.kill_button)
button_layout.addWidget(self.restart_button)
Expand Down Expand Up @@ -418,6 +424,10 @@ def _on_ticker(self) -> None:
self.running_time.setText(format_running_time(runtime))

maximum_memory_usage = self._snapshot_model.root.max_memory_usage
disk_usage = disk_space_status(self.run_path_mp)

if disk_usage:
self.disk_space.setText(f"Disk space used runpath: {disk_usage:.2f}%")

if maximum_memory_usage:
self.memory_usage.setText(
Expand Down
21 changes: 21 additions & 0 deletions src/ert/shared/status/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import contextlib
import math
import os
import resource
import shutil
import sys
from pathlib import Path


def byte_with_unit(byte_count: float) -> str:
Expand Down Expand Up @@ -82,3 +85,21 @@ def get_ert_memory_usage() -> int:
rss_scale = 1000

return usage.ru_maxrss // rss_scale


def disk_space_status(runpath: str):

Check failure on line 90 in src/ert/shared/status/utils.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a return type annotation
with contextlib.suppress(Exception):
mount_dir = _get_mount_directory(runpath)
print(mount_dir)
total_space, used_space, free_space = shutil.disk_usage(mount_dir)
percentage_used = used_space / total_space
return percentage_used


def _get_mount_directory(runpath: str) -> Path:
path = Path(runpath).absolute()

while not path.is_mount():
path = path.parent

return path

0 comments on commit 642876f

Please sign in to comment.