Skip to content

Commit 11c7d2b

Browse files
Show debug info of free space in tests (#3161)
1 parent 46079f5 commit 11c7d2b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.ci/validate_notebooks.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,37 @@ def get_pip_package_version(package, text_input: str, missing_return: str) -> st
198198
version = missing_return
199199
return version
200200

201+
def get_dir_size(path: Path) -> int:
202+
total = 0
203+
try:
204+
if not path.exists():
205+
return 0
206+
if path.is_file():
207+
return path.stat().st_size
208+
for entry in path.rglob('*'):
209+
if entry.is_file():
210+
total += entry.stat().st_size
211+
except Exception:
212+
pass
213+
return total
214+
215+
216+
def print_disk_usage(label: str, notebook_dir: Path):
217+
try:
218+
# Free disk space
219+
total, used, free = shutil.disk_usage(notebook_dir.absolute().anchor)
220+
221+
# Notebook dir size
222+
nb_dir_size = get_dir_size(notebook_dir)
223+
224+
# Cache dir size
225+
cache_dir = Path.home() / ".cache"
226+
cache_size = get_dir_size(cache_dir)
227+
228+
print(f"DEBUG [{label}] Free Space: {free} | Notebook Dir: {nb_dir_size} | ~/.cache: {cache_size}", flush=True)
229+
except Exception as e:
230+
print(f"Error checking disk usage: {e}")
231+
201232

202233
def run_test(notebook_path: Path, root, timeout=7200, keep_artifacts=False, report_dir=".") -> Optional[tuple[str, int, float, str, str]]:
203234
os.environ["HUGGINGFACE_HUB_CACHE"] = str(notebook_path.parent)
@@ -215,6 +246,7 @@ def run_test(notebook_path: Path, root, timeout=7200, keep_artifacts=False, repo
215246
return result
216247

217248
with cd(notebook_path.parent):
249+
print_disk_usage("BEFORE", Path("."))
218250
files_before_test = sorted(Path(".").iterdir())
219251
ov_version_before = get_pip_package_version("openvino", "OpenVINO before notebook execution", "OpenVINO is missing")
220252
get_pip_package_version("openvino_tokenizers", "OpenVINO Tokenizers before notebook execution", "OpenVINO Tokenizers is missing")
@@ -237,6 +269,7 @@ def run_test(notebook_path: Path, root, timeout=7200, keep_artifacts=False, repo
237269
except subprocess.TimeoutExpired:
238270
retcode = -42
239271
duration = time.perf_counter() - start
272+
240273
ov_version_after = get_pip_package_version("openvino", "OpenVINO after notebook execution", "OpenVINO is missing")
241274
get_pip_package_version("openvino_tokenizers", "OpenVINO Tokenizers after notebook execution", "OpenVINO Tokenizers is missing")
242275
get_pip_package_version("openvino_genai", "OpenVINO GenAI after notebook execution", "OpenVINO GenAI is missing")
@@ -245,6 +278,7 @@ def run_test(notebook_path: Path, root, timeout=7200, keep_artifacts=False, repo
245278
if not keep_artifacts:
246279
clean_test_artifacts(files_before_test, sorted(Path(".").iterdir()))
247280
collect_python_packages(report_dir / (patched_notebook.stem + "_env_after.txt"))
281+
print_disk_usage("AFTER", Path("."))
248282

249283
return result
250284

0 commit comments

Comments
 (0)