Skip to content

Commit

Permalink
Show mem consumption when not tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
mossprescott committed Mar 21, 2024
1 parent af45ee2 commit c61583b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions alt/big.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def assemble(f, min_static=16, max_static=1023, builtins=BUILTIN_SYMBOLS):
CYCLES_PER_CALL = 100 # Number of cycles to run in the tight loop (when not tracing)


def run(program, chip=BigComputer, simulator="codegen", name="Flat!", font="monaco-9", halt_addr=None, trace=None, verbose_tty=True):
def run(program, chip=BigComputer, simulator="codegen", name="Flat!", font="monaco-9", halt_addr=None, trace=None, verbose_tty=True, meters=None):
"""Run with keyboard and text-mode graphics."""

# TODO: font
Expand Down Expand Up @@ -407,7 +407,8 @@ def run_trace():
cps = (cycles - last_cycle_count)/(now - last_cycle_time)
msgs.append(f"{cps/1000:0,.1f}k/s")
msgs.append(f"@{computer.pc}")
# TODO: let the caller add meters (e.g. Ribbit heap consumption)
if meters:
msgs.extend(meters(computer, cycles))
pygame.display.set_caption(f"{name}: {'; '.join(msgs)}")

last_cycle_time = now
Expand Down
13 changes: 12 additions & 1 deletion alt/scheme/rvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,23 @@ def trace(computer, cycles):
elif trace_level >= TRACE_ALL:
print(f"{cycles:3,d}: {computer.pc}")

def meters(computer, cycles):
inspector = Inspector(computer, symbols, stack_loc)
next_rib = unsigned(inspector.peek(next_rib_loc))
current_ribs = (next_rib - big.HEAP_BASE)//3
max_ribs = (big.HEAP_TOP - big.HEAP_BASE)//3
return {
f"mem: {100*current_ribs/max_ribs:0.1f}%"
}


big.run(program=instrs,
simulator=simulator,
name="Scheme",
halt_addr=halt_loop_addr,
trace=trace if trace_level > TRACE_NONE else None,
verbose_tty=verbose_tty)
verbose_tty=verbose_tty,
meters=meters)


def compile(src):
Expand Down

0 comments on commit c61583b

Please sign in to comment.