Skip to content

Commit ddc90e3

Browse files
committed
new: disk usage profiling
1 parent 064415e commit ddc90e3

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

dyana/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from dyana.tracer.tracee import Tracer
1313
from dyana.view import (
1414
view_disk_events,
15+
view_disk_usage,
1516
view_extra,
1617
view_gpus,
1718
view_header,
@@ -106,6 +107,7 @@ def summary(trace_path: pathlib.Path = typer.Option(help="Path to the trace file
106107
view_header(trace)
107108
view_ram(trace["run"])
108109
view_gpus(trace["run"])
110+
view_disk_usage(trace["run"])
109111

110112
view_process_executions(trace)
111113
view_network_events(trace)

dyana/loaders/base/dyana.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import resource
2+
import shutil
23
import sys
34
import typing as t
45
from contextlib import contextmanager
@@ -8,6 +9,7 @@
89
class Profiler:
910
def __init__(self, gpu: bool = False):
1011
self._errors: dict[str, str] = {}
12+
self._disk: dict[str, int] = {"start": get_disk_usage()}
1113
self._ram: dict[str, int] = {"start": get_peak_rss()}
1214
self._gpu: dict[str, list[dict[str, t.Any]]] = {"start": get_gpu_usage()} if gpu else {}
1315
self._imports_at_start = get_current_imports()
@@ -18,6 +20,9 @@ def track_memory(self, event: str) -> None:
1820
if self._gpu:
1921
self._gpu[event] = get_gpu_usage()
2022

23+
def track_disk(self, event: str) -> None:
24+
self._disk[event] = get_disk_usage()
25+
2126
def track_error(self, event: str, error: str) -> None:
2227
self._errors[event] = error
2328

@@ -30,6 +35,7 @@ def as_dict(self) -> dict[str, t.Any]:
3035

3136
as_dict: dict[str, t.Any] = {
3237
"ram": self._ram,
38+
"disk": self._disk,
3339
"errors": self._errors,
3440
"extra": {"imports": imported},
3541
} | self._additionals
@@ -63,6 +69,14 @@ def capture_output() -> t.Generator[tuple[StringIO, StringIO], None, None]:
6369
sys.stderr = old_stderr
6470

6571

72+
def get_disk_usage() -> int:
73+
"""
74+
Get the disk usage.
75+
"""
76+
_, used, _ = shutil.disk_usage("/")
77+
return used
78+
79+
6680
def get_peak_rss() -> int:
6781
"""
6882
Get the peak RSS memory usage of the current process.

dyana/loaders/loader.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Run(BaseModel):
3232
errors: dict[str, str] | None = None
3333
ram: dict[str, int] | None = None
3434
gpu: dict[str, list[GpuDeviceUsage]] | None = None
35+
disk: dict[str, int] | None = None
3536
stdout: str | None = None
3637
stderr: str | None = None
3738
exit_code: int | None = None
@@ -103,8 +104,8 @@ def __init__(
103104
print(
104105
f":whale: [bold]loader[/]: using image [green]{self.image.tags[0]}[/] [dim]({self.image.id})[/] ({self.platform})"
105106
)
106-
else:
107-
print(f":whale: [bold]loader[/]: using image [green]{self.image.tags[0]}[/] [dim]({self.image.id})[/]")
107+
# else:
108+
# print(f":whale: [bold]loader[/]: using image [green]{self.image.tags[0]}[/] [dim]({self.image.id})[/]")
108109

109110
def _reader_thread(self) -> None:
110111
if not self.container:
@@ -161,13 +162,15 @@ def run(self, allow_network: bool = False, allow_gpus: bool = True, allow_volume
161162
else:
162163
arguments.append(arg.value)
163164

164-
if allow_network:
165-
print(
166-
":popcorn: [bold]loader[/]: [yellow]warning: allowing bridged network access to the model container[/]"
167-
)
165+
if self.settings and self.settings.network:
166+
allow_network = True
167+
print(":popcorn: [bold]loader[/]: [yellow]required bridged network access[/]")
168+
169+
elif allow_network:
170+
print(":popcorn: [bold]loader[/]: [yellow]warning: allowing bridged network access to the container[/]")
168171

169172
if allow_volume_write:
170-
print(":popcorn: [bold]loader[/]: [yellow]warning: allowing volume write to the model container[/]")
173+
print(":popcorn: [bold]loader[/]: [yellow]warning: allowing volume write to the container[/]")
171174

172175
if arguments:
173176
print(f":popcorn: [bold]loader[/]: executing with arguments [dim]{arguments}[/] ...")

dyana/loaders/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class LoaderSettings(BaseModel):
1919
description: str
2020
build_args: dict[str, str] | None = None
2121
args: list[LoaderArgument] | None = None
22+
network: bool | None = False
2223

2324
def _parse_arg_name_from(self, name: str, args: list[str]) -> str | None:
2425
found_pre = False

dyana/view.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ def view_gpus(run: dict[str, t.Any]) -> None:
131131
print()
132132

133133

134+
def view_disk_usage(run: dict[str, t.Any]) -> None:
135+
disk = run["disk"]
136+
if disk:
137+
print("[bold yellow]Disk Usage:[/]")
138+
disk_stages = list(disk.keys())
139+
prev_stage = None
140+
for stage in disk_stages:
141+
if prev_stage is None:
142+
print(f" * {stage} : {sizeof_fmt(disk[stage])}")
143+
else:
144+
print(f" * {stage} : {delta_fmt(disk[prev_stage], disk[stage])}")
145+
prev_stage = stage
146+
147+
print()
148+
149+
134150
def view_process_executions(trace: dict[str, t.Any]) -> None:
135151
proc_execs = [event for event in trace["events"] if event["eventName"] == "sched_process_exec"]
136152
visualized = []

0 commit comments

Comments
 (0)