mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Monitor: the Cards strip's link column steps down a whole number at a time, so a narrow terminal never cuts it mid-word
_cards_strip crops its lines instead of wrapping them, so a card capped to x8 in a x16
slot read "Gen5 x8 o" at 80 columns, and "Gen5" in the real app (the Monitor shell's
padding leaves 78 of an 80-column terminal). The column now shrinks whole: the ceiling
goes first, then the generation, then the column itself, which is the line as it was
before this change. card_link gains show_gen=False for the last step.
Read on this machine's two RTX 5060 Ti (x8 and x4 in x16 slots) in a PTY at 80 and 110
columns: before "… 62 W Gen5", after "… 64 W x8". The new test fails at 6c1c9d00
(AssertionError: 'x8 o' unexpectedly found in '… 236 W Gen5 x8 of x') and passes here;
the five focused files give 131 passed, 1 skipped, 10 subtests.
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
6c1c9d0027
commit
6a65b42287
3 files changed
+55
-14
No files matched your search
@@ -181,13 +181,14 @@ def _rows(value: Any, fields: tuple[str, ...], limit: int) -> list[dict]:
|
||||
return out
|
||||
|
||||
|
||||
def card_link(row: Any, gap: bool = True) -> str:
|
||||
def card_link(row: Any, gap: bool = True, show_gen: bool = True) -> str:
|
||||
"""One graphics card's own PCIe link as the Terminal words it ("Gen5 x8"); "" when the server does not report it.
|
||||
The generation is the one the card runs at now, or the highest it can reach when it reports no current one (NVML
|
||||
reports a lower link while the card is idle). A card that runs narrower than it could - capped to x8 in a x16
|
||||
slot, or trained down to x4 by the board - gets both numbers ("Gen5 x8 of x16"), because the narrow one alone
|
||||
reads as a card someone chose; `gap=False` leaves the second number out for a column too narrow for it. An old
|
||||
server, or a card whose link is not readable, gives ""."""
|
||||
reads as a card someone chose; `gap=False` leaves the second number out for a column too narrow for it, and
|
||||
`show_gen=False` leaves only the width ("x8") for a column too narrow even for the link. An old server, or a
|
||||
card whose link is not readable, gives ""."""
|
||||
if not isinstance(row, dict):
|
||||
return ""
|
||||
gen = _number(row.get("pcie_gen"))
|
||||
@@ -196,6 +197,8 @@ def card_link(row: Any, gap: bool = True) -> str:
|
||||
if gen is None:
|
||||
return ""
|
||||
width, cap = _number(row.get("pcie_width")), _number(row.get("pcie_width_max"))
|
||||
if not show_gen:
|
||||
return f"x{int(width)}" if width else ""
|
||||
return (f"Gen{int(gen)}" + (f" x{int(width)}" if width else "")
|
||||
+ (f" of x{int(cap)}" if gap and width and cap and cap > width else ""))
|
||||
|
||||
|
||||
+22
-11
@@ -321,7 +321,7 @@ def _tile(title: str, big: str, sub: str, series: str, width: int, *, accent: st
|
||||
border_style="dim")
|
||||
|
||||
|
||||
def _cards_strip(cards: list[dict], glyphs: str, accent: str, ascii_mode: bool) -> Text:
|
||||
def _cards_strip(cards: list[dict], glyphs: str, accent: str, ascii_mode: bool, width: int = 110) -> Text:
|
||||
"""One line per card (up to 4): a small load bar, load %, memory, temperature, power and that card's own PCIe link
|
||||
(the server reports it per card; the tile above shows only the weakest); "+ N more cards" beyond that."""
|
||||
t = Text(no_wrap=True, overflow="crop")
|
||||
@@ -329,17 +329,28 @@ def _cards_strip(cards: list[dict], glyphs: str, accent: str, ascii_mode: bool)
|
||||
shown = cards[:4]
|
||||
names = [short_gpu(c.get("name")) for c in shown]
|
||||
pad = min(16, max(len(n) for n in names))
|
||||
links = [card_link(c) for c in shown] # "" for a card whose link the server does not report
|
||||
col = max((len(x) for x in links), default=0) # no column at all when no server reports one: the line stays as it was
|
||||
for c, name, link in zip(shown, names, links):
|
||||
util = c["util"]
|
||||
used, total = c["mem_used"], c["mem_total"]
|
||||
t.append(f"GPU {c['index'] if c['index'] is not None else '?'} {name[:pad]:<{pad}} ")
|
||||
t.append_text(bar((util / 100.0) if util is not None else None, 10, glyphs, accent))
|
||||
heads, tails = [], []
|
||||
for c, name in zip(shown, names): # the line's two text runs, the bar goes between them
|
||||
util, used, total = c["util"], c["mem_used"], c["mem_total"]
|
||||
heads.append(f"GPU {c['index'] if c['index'] is not None else '?'} {name[:pad]:<{pad}} ")
|
||||
mem = f"{fmt(used, 1)} / {fmt(total, 0)} GB" if used is not None and total is not None else "-- GB"
|
||||
temp = f"{fmt(c['temp'])} {'C' if ascii_mode else '°C'}"
|
||||
t.append(f" {fmt(util):>3} % {mem:<14} {temp:>6} {fmt(c['power']):>4} W" +
|
||||
(f" {link:>{col}}" if col else "") + chr(10))
|
||||
tails.append(f" {fmt(util):>3} % {mem:<14} {temp:>6} {fmt(c['power']):>4} W")
|
||||
links = [card_link(c) for c in shown] # "" for a card whose link the server does not report
|
||||
col = max((len(x) for x in links), default=0) # no column at all when no server reports one: the line stays as it was
|
||||
# the strip's line is cropped, never wrapped, so a link too long for the terminal gets cut mid-word ("Gen5 x8 o"):
|
||||
# the column steps down a number at a time - the ceiling, then the generation, then nothing - so whatever is left
|
||||
# fits whole. Read on this machine at 110, at 78 (an 80-column terminal less the shell's padding) and narrower.
|
||||
room = width - max(len(h) + 10 + len(x) for h, x in zip(heads, tails)) - 2 # 10: the load bar
|
||||
for form in ({"gap": False}, {"gap": False, "show_gen": False}, None):
|
||||
if not col or col <= room:
|
||||
break
|
||||
links = [card_link(c, **form) if form is not None else "" for c in shown]
|
||||
col = max((len(x) for x in links), default=0)
|
||||
for c, name, head, tail, link in zip(shown, names, heads, tails, links):
|
||||
t.append(head)
|
||||
t.append_text(bar((c["util"] / 100.0) if c["util"] is not None else None, 10, glyphs, accent))
|
||||
t.append(tail + (f" {link:>{col}}" if col else "") + chr(10))
|
||||
if len(cards) > 4:
|
||||
t.append(f"+ {len(cards) - 4} more cards: press 5" + chr(10), style="dim")
|
||||
return t
|
||||
@@ -501,6 +512,6 @@ def render(model: dict, *, width: int, height: int, connection: str, connection_
|
||||
hint = Text(f"{nav.keys(connect)} views" + " / filter Space freeze r refresh t theme b open in browser ? help q quit", style="dim")
|
||||
parts: list[Any] = [head, tabs, rule, st, state_bar, Text(""), row(tiles1), row(tiles2)]
|
||||
if ncards:
|
||||
parts += [Text(""), _cards_strip(cards, glyphs, accent, ascii_mode)]
|
||||
parts += [Text(""), _cards_strip(cards, glyphs, accent, ascii_mode, width)]
|
||||
parts += [bottom, Text(""), hint]
|
||||
return Group(*parts)
|
||||
@@ -248,6 +248,33 @@ class SeveralCards(unittest.TestCase):
|
||||
self.assertEqual(overview.build(m)["gpu"]["pcie_width_max"], 16.0)
|
||||
self.assertIn("Gen5 x4 of x16", draw(overview.build(m))) # the tile says the gap too
|
||||
|
||||
def test_the_cards_strip_link_shrinks_whole_as_the_terminal_narrows(self):
|
||||
"""The strip's line is cropped, not wrapped, so a long link gets cut mid-word ("Gen5 x8 o" on an 80-column
|
||||
terminal). The column steps down a number at a time - the ceiling, then the generation, then nothing - so
|
||||
whatever is left fits whole. The widths are what this machine's Monitor gives: 110, and 78 for an 80-column
|
||||
terminal less the shell's padding; the same card reads x8 in a x16 slot."""
|
||||
m = three_cards()
|
||||
for c in m["hardware"]["gpus"]:
|
||||
c.update({"pcie_gen": 5, "pcie_gen_max": 5, "pcie_width": 8, "pcie_width_max": 16})
|
||||
|
||||
def strip(width):
|
||||
return [ln for ln in draw(overview.build(m), width=width).splitlines() if ln.startswith("GPU ")]
|
||||
|
||||
self.assertIn("Gen5 x8 of x16", strip(110)[0]) # room: both numbers
|
||||
at80 = strip(80)
|
||||
self.assertIn("Gen5 x8", at80[0])
|
||||
self.assertNotIn("of x16", at80[0]) # the ceiling goes first, whole
|
||||
self.assertNotIn("x8 o", at80[0]) # never mid-word
|
||||
at76 = strip(76)
|
||||
self.assertIn(" x8", at76[0])
|
||||
self.assertNotIn("Gen", at76[0]) # then the generation
|
||||
at70 = strip(70)
|
||||
self.assertNotIn("x8", at70[0])
|
||||
self.assertNotIn("Gen", at70[0]) # then no column: the old line
|
||||
for width in (110, 80, 76, 70):
|
||||
for line in strip(width):
|
||||
self.assertLessEqual(len(line), width + 2) # nothing past the terminal here
|
||||
|
||||
def test_a_card_with_no_cap_reported_stays_one_number(self):
|
||||
"""An old server, or a driver that answers only the negotiated width: the strip and the tile say exactly what
|
||||
they said before, with no invented cap."""
|
||||
|
||||
Reference in new issue
Block a user