mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
gate: the summary even when memory.csv cannot be written, the slope up to the stop (review)
`summary` wrote memory.csv before summary.json, so a memory.csv open in another program left no summary and exit 1. A file it cannot write or remove is now said on stderr, `series` is null and summary.json is written. The private bytes' slope counted the memory lines written while the title ends after the stop request; it now covers the world up to the stop, as the frame rates do. New tests: the 2 s window and the empty cells of memory.csv, its LF line ends, the slope with lines after the stop and with fewer than 3 lines in the world, and a memory.csv that cannot be written. The census sentence's contract is one key over the whole part WAITS reads, the ", " between its two numbers too. The docs name every video memory line the peak counts (the swap chain made, its buffers made again, a budget change of 256 MB or more) and when the slope and `series` are null.
This commit is contained in:
@ -66,7 +66,7 @@ Times are seconds since the run started. The summary holds numbers, switch names
|
||||
| `times.world_s` | Seconds from `world_at_s` to the stop request |
|
||||
| `fps` | From the presents, after the first 60 s in the world: frames, median, p5, frame p95 (ms), median of the last 60 s (`end_median`), the first second with fewer than 2 frames, from 60 s in the world on too (`under_2_at_s`), the longest gap with no frame presented from the world on (`longest_present_gap_s`, `longest_gap_at_s`; on purpose from the world on: a freeze on pipeline compiles comes right after arrival, and 10 s with no frame is what a player sees), draws a frame. Without the present lines (a build without diagnostics), the median and p5 come from the frame lines, with a warning |
|
||||
| `pipelines` | Waits that ran out (`missed_waits`), the most pipelines being made at once |
|
||||
| `memory` | Peaks over the whole run, from the runtime's memory line and video memory line (every 5 s; builds with diagnostics only, otherwise `source` is null): the process's private bytes and when (`private_max_mb`, `private_max_at_s`), the most of them in physical memory, the least the PC had left to commit and when, the card's video memory in use at its most and when, with the budget the system gave then (`vram_in_use_max_mb`, `vram_max_at_s`, `vram_budget_at_max_mb`), the seconds spent over that budget, and the most of the PC's memory shared with the card in use. The video memory is what the system counts for this process, less than a tool like `nvidia-smi` shows for the whole card. `stop_limits` holds the memory stop's limits from `run.json` (null from a gate without the memory stop). Also, from the runtime's census line, the reaper thread's queue at its longest and when (`reaper_queue_max`, `reaper_queue_max_at_s`) and the most objects let go that wait for their submissions (`waiting_objects_max`); how fast the private bytes grew in the world in MB a minute (`private_mb_per_min_in_world`, a least-squares slope: on a short run it is the loading's climb, on a long one a pile-up's slope); and `series`, the name of `memory.csv` (null without memory lines). The video memory peak and the time over the budget count every video memory line, the ones the runtime writes when it makes the swap chain too. `memory.csv` has only the one nearest each memory line, so the summary's peak can come from a line with no row there |
|
||||
| `memory` | Peaks over the whole run, from the runtime's memory line and video memory line (every 5 s; builds with diagnostics only, otherwise `source` is null): the process's private bytes and when (`private_max_mb`, `private_max_at_s`), the most of them in physical memory, the least the PC had left to commit and when, the card's video memory in use at its most and when, with the budget the system gave then (`vram_in_use_max_mb`, `vram_max_at_s`, `vram_budget_at_max_mb`), the seconds spent over that budget, and the most of the PC's memory shared with the card in use. The video memory is what the system counts for this process, less than a tool like `nvidia-smi` shows for the whole card. `stop_limits` holds the memory stop's limits from `run.json` (null from a gate without the memory stop). Also, from the runtime's census line, the reaper thread's queue at its longest and when (`reaper_queue_max`, `reaper_queue_max_at_s`) and the most objects let go that wait for their submissions (`waiting_objects_max`); how fast the private bytes grew in the world in MB a minute (`private_mb_per_min_in_world`, a least-squares slope over the memory lines from `world_at_s` to the stop request: on a short run it is the loading's climb, on a long one a pile-up's slope; null with fewer than 3 lines there); and `series`, the name of `memory.csv` (null without memory lines, or when the file could not be written, for example open in another program: `game_gate.py` says so on stderr and writes `summary.json` all the same). The video memory peak and the time over the budget count every video memory line: the one written with each memory line, and the ones the runtime writes right before and after it makes the swap chain, right after the swap chain's buffers are made again for another size or format, and right after the system changes the card's budget by 256 MB or more. `memory.csv` has only the one nearest each memory line, so the summary's peak can come from a line with no row there |
|
||||
| `crash` | `kind` is `none`, `device_lost`, `panic` or `fault`. It also gives the time, the code, the module kind (`runtime`, `title`, `driver`, `system`, `unknown`) and the access (read/write). `title_watchdog` marks a write at address 0 in the title more than 25 s after the last frame line. `count` is the number of crashes |
|
||||
| `exit` | The game's exit code, and its kind: `clean`, `device_lost` (0x887A0005), `killed` or `other` |
|
||||
| `stop` | Why it was stopped (`target`, `stop_file`, `timeout`, `relaunched` or `memory`), whether it was killed, whether the cache was saved, whether the suspend was in time. After a memory stop, `memory_why` is the gate's whole sentence for it, with its numbers: `private bytes 31000 MB, over 30000 MB`, `the PC had under 200 MB left to commit for 25 s` or `video memory over its budget for 60 s`, for example. It is null for the other reasons |
|
||||
|
||||
@ -309,7 +309,7 @@ class Measures(unittest.TestCase):
|
||||
|
||||
def test_the_memory_series_and_a_pile_ups_slope(self):
|
||||
f = passing()
|
||||
for i, t in enumerate(range(10, 390, 5)):
|
||||
for t in range(10, 390, 5):
|
||||
# From the world on (70 s) the private bytes grow 10 MB every 5 s and the reaper's queue grows.
|
||||
grown = max(0, t - 70) // 5
|
||||
f.memory(t, 20000 + 10 * grown, 7000, waiting=3, reaper=100 * grown)
|
||||
@ -329,6 +329,69 @@ class Measures(unittest.TestCase):
|
||||
self.assertEqual(rows[-1]["private_mb"], "20630")
|
||||
self.assertEqual(rows[-1]["reaper_queue"], "6300")
|
||||
self.assertEqual(rows[-1]["vram_in_use_mb"], "7000")
|
||||
# The same bytes on every machine: LF line ends, never CRLF.
|
||||
with open(os.path.join(f.dir, "memory.csv"), "rb") as fh:
|
||||
self.assertNotIn(b"\r", fh.read())
|
||||
|
||||
def summary_files(self, f):
|
||||
"""`game_gate.py summary` on the folder: (exit code, summary.json, memory.csv rows or None, stderr)."""
|
||||
f.summarize()
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(err):
|
||||
code = game_gate.main(["game_gate.py", "summary", f.dir])
|
||||
with open(os.path.join(f.dir, "summary.json"), encoding="utf-8") as fh:
|
||||
s = json.load(fh)
|
||||
path = os.path.join(f.dir, "memory.csv")
|
||||
rows = None
|
||||
if os.path.isfile(path):
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
rows = list(csv.DictReader(fh))
|
||||
return code, s, rows, err.getvalue()
|
||||
|
||||
def test_the_series_takes_the_lines_within_2_s_of_each_memory_line(self):
|
||||
f = passing()
|
||||
f.memory(100, 20000, 7000, waiting=3, reaper=40) # the three lines at once, as the runtime writes them
|
||||
f.memory(200, 21000, 7500, waiting=5, reaper=50)
|
||||
census, video, memory = f.log[-3:]
|
||||
# The video memory line 2 s before (taken), the census line 2.5 s after (too far: empty cells).
|
||||
f.log[-3:] = [census.replace(stamp(200), stamp(202.5)), video.replace(stamp(200), stamp(198)), memory]
|
||||
f.memory(300, 22000, 8000)
|
||||
f.log[-3:] = f.log[-1:] # a memory line alone
|
||||
_, _, rows, _ = self.summary_files(f)
|
||||
got = [(r["t_s"], r["vram_in_use_mb"], r["shared_in_use_mb"], r["waiting_objects"], r["reaper_queue"])
|
||||
for r in rows]
|
||||
self.assertEqual(got, [("100.0", "7000", "500", "3", "40"), ("200.0", "7500", "500", "", ""),
|
||||
("300.0", "", "", "", "")])
|
||||
|
||||
def test_the_slope_counts_the_world_up_to_the_stop(self):
|
||||
f = Fake()
|
||||
f.event(1, "game", pid=1)
|
||||
f.frames(10, 70, 60.0, 13)
|
||||
f.frames(70, 420, 50.0, 4000)
|
||||
for t in range(70, 420, 5):
|
||||
# 120 MB a minute in the world, then a jump while the title ends after the stop request (390 s).
|
||||
f.memory(t, 20000 + 2 * (t - 70) if t <= 390 else 40000, 7000)
|
||||
f.event(390, "stop_requested", reason="target")
|
||||
f.event(420, "game_exited", exit_code=0)
|
||||
self.assertEqual(f.summarize()["memory"]["private_mb_per_min_in_world"], 120.0)
|
||||
# Fewer than 3 memory lines in the world: no slope.
|
||||
f = passing()
|
||||
for t in (40, 50, 60, 100, 200):
|
||||
f.memory(t, 20000 + t, 7000)
|
||||
self.assertIsNone(f.summarize()["memory"]["private_mb_per_min_in_world"])
|
||||
|
||||
def test_a_series_it_cannot_write_still_leaves_the_summary(self):
|
||||
# memory.csv held by another program: the summary is written all the same, with no series named.
|
||||
f = passing()
|
||||
for t in range(70, 390, 5):
|
||||
f.memory(t, 20000, 7000)
|
||||
os.makedirs(os.path.join(f.dir, "memory.csv")) # opening it to write fails, as a locked file does
|
||||
code, s, _, err = self.summary_files(f)
|
||||
self.assertEqual(code, 0)
|
||||
self.assertEqual(s["verdict"]["result"], "PASS")
|
||||
self.assertIsNone(s["memory"]["series"])
|
||||
self.assertEqual(s["memory"]["lines"], 64)
|
||||
self.assertIn("memory.csv not written or removed", err)
|
||||
|
||||
def test_a_build_without_memory_lines_gives_no_memory_peaks(self):
|
||||
f = passing()
|
||||
|
||||
@ -87,10 +87,10 @@ SOURCES = {
|
||||
"d3d12/crates/leonida-gpu/src/host.rs",
|
||||
"the PC's shared with the card: budget {} MB, in use {} MB": "d3d12/crates/leonida-gpu/src/host.rs",
|
||||
'h.log_video_memory("with the memory line")': "d3d12/crates/leonida-gpu/src/copystat.rs",
|
||||
# One key over the whole part WAITS reads, the ", " between its two numbers too.
|
||||
"memory, what waits to be let go: {waiting} objects let go that wait for the submissions that may use them "
|
||||
"(LEONIDA_BURY_LAG)": "d3d12/crates/leonida-gpu/src/census.rs",
|
||||
"{handed} retired objects, landed host lists and lists' fronts handed to the thread that lets them go":
|
||||
"d3d12/crates/leonida-gpu/src/census.rs",
|
||||
"(LEONIDA_BURY_LAG), {handed} retired objects, landed host lists and lists' fronts handed to the thread that "
|
||||
"lets them go": "d3d12/crates/leonida-gpu/src/census.rs",
|
||||
"crate::census::log();": "d3d12/crates/leonida-gpu/src/copystat.rs",
|
||||
}
|
||||
|
||||
@ -418,23 +418,29 @@ def memory_rows(run):
|
||||
|
||||
def write_series(run, folder):
|
||||
"""Writes memory.csv beside summary.json when the run has memory lines; returns its name or None. Without them
|
||||
it removes a memory.csv already there (a folder summarized again), so no old rows sit beside `series: null`."""
|
||||
it removes a memory.csv already there (a folder summarized again), so no old rows sit beside `series: null`.
|
||||
A file it cannot write or remove (open in another program) is said on stderr: the summary is written anyway."""
|
||||
path = os.path.join(folder, SERIES)
|
||||
rows = memory_rows(run)
|
||||
if not rows:
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
try:
|
||||
if not rows:
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
return None
|
||||
with open(path, "w", encoding="utf-8", newline="") as f:
|
||||
out = csv.DictWriter(f, fieldnames=SERIES_COLUMNS, lineterminator="\n")
|
||||
out.writeheader()
|
||||
out.writerows(rows)
|
||||
except OSError as e:
|
||||
print(f"{SERIES} not written or removed: {e.__class__.__name__}: {e.strerror or e}", file=sys.stderr)
|
||||
return None
|
||||
with open(path, "w", encoding="utf-8", newline="") as f:
|
||||
out = csv.DictWriter(f, fieldnames=SERIES_COLUMNS, lineterminator="\n")
|
||||
out.writeheader()
|
||||
out.writerows(rows)
|
||||
return SERIES
|
||||
|
||||
|
||||
def memory_block(run, world=None):
|
||||
def memory_block(run, world=None, end=None):
|
||||
"""Peaks of the runtime's memory lines over the whole run (none from a build without diagnostics), the
|
||||
reaper's queue at its longest, and how fast the private bytes grew in the world (a pile-up's slope)."""
|
||||
reaper's queue at its longest, and how fast the private bytes grew in the world up to `end` (a pile-up's
|
||||
slope; the lines written while the title ends after the stop request do not count)."""
|
||||
out = {"source": None, "lines": 0, "private_max_mb": None, "private_max_at_s": None, "in_memory_max_mb": None,
|
||||
"pc_commit_left_min_mb": None, "pc_commit_left_min_at_s": None, "vram_in_use_max_mb": None,
|
||||
"vram_max_at_s": None, "vram_budget_at_max_mb": None, "vram_over_budget_s": None,
|
||||
@ -445,11 +451,10 @@ def memory_block(run, world=None):
|
||||
out["reaper_queue_max"], out["reaper_queue_max_at_s"] = queue, round(t, 3)
|
||||
out["waiting_objects_max"] = max(w[1] for w in run.waits)
|
||||
if run.memory and world is not None:
|
||||
slope = slope_per_min([(m[0], m[1]) for m in run.memory if m[0] >= world])
|
||||
slope = slope_per_min([(m[0], m[1]) for m in run.memory if world <= m[0] and (end is None or m[0] <= end)])
|
||||
out["private_mb_per_min_in_world"] = round(slope, 1) if slope is not None else None
|
||||
if run.memory:
|
||||
out["series"] = SERIES
|
||||
if run.memory:
|
||||
out["source"], out["lines"] = "memory lines", len(run.memory)
|
||||
t, private = max(((t, p) for t, p, *_ in run.memory), key=lambda x: x[1])
|
||||
out["private_max_mb"], out["private_max_at_s"] = private, round(t, 3)
|
||||
@ -548,7 +553,7 @@ def summary(run):
|
||||
},
|
||||
"fps": fps,
|
||||
"pipelines": {"missed_waits": len(run.missed), "making_max": max((m for *_, m in run.frames), default=0)},
|
||||
"memory": dict(memory_block(run, world), stop_limits=run.meta.get("memory_stop")),
|
||||
"memory": dict(memory_block(run, world, end), stop_limits=run.meta.get("memory_stop")),
|
||||
"crash": {
|
||||
"kind": crash_kind,
|
||||
"at_s": round(first["at_s"], 3) if first and first["at_s"] is not None else None,
|
||||
@ -577,7 +582,8 @@ def main(argv):
|
||||
print(json.dumps(state(run)))
|
||||
return 0
|
||||
out = summary(run)
|
||||
write_series(run, argv[2])
|
||||
# `series` names the file only when it was written.
|
||||
out["memory"]["series"] = write_series(run, argv[2])
|
||||
with open(os.path.join(argv[2], "summary.json"), "w", encoding="utf-8", newline="\n") as f:
|
||||
json.dump(out, f, indent=2)
|
||||
f.write("\n")
|
||||
|
||||
Reference in New Issue
Block a user