Commit d2241c6d authored by protolambda's avatar protolambda

cmd,mipsevm: improve stats reporting

parent 05097d36
...@@ -244,15 +244,22 @@ func Run(ctx *cli.Context) error { ...@@ -244,15 +244,22 @@ func Run(ctx *cli.Context) error {
stepFn = Guard(po.cmd.ProcessState, stepFn) stepFn = Guard(po.cmd.ProcessState, stepFn)
} }
start := time.Now()
startStep := state.Step
for !state.Exited { for !state.Exited {
step := state.Step step := state.Step
name := meta.LookupSymbol(state.PC) name := meta.LookupSymbol(state.PC)
if infoAt(state) { if infoAt(state) {
delta := time.Since(start)
l.Info("processing", l.Info("processing",
"step", step, "step", step,
"pc", mipsevm.HexU32(state.PC), "pc", mipsevm.HexU32(state.PC),
"insn", mipsevm.HexU32(state.Memory.GetMemory(state.PC)), "insn", mipsevm.HexU32(state.Memory.GetMemory(state.PC)),
"ips", float64(step-startStep)/(float64(delta)/float64(time.Second)),
"pages", len(state.Memory.Pages),
"mem", state.Memory.Usage(),
"name", name, "name", name,
) )
} }
......
...@@ -276,3 +276,18 @@ func (r *memReader) Read(dest []byte) (n int, err error) { ...@@ -276,3 +276,18 @@ func (r *memReader) Read(dest []byte) (n int, err error) {
func (m *Memory) ReadMemoryRange(addr uint32, count uint32) io.Reader { func (m *Memory) ReadMemoryRange(addr uint32, count uint32) io.Reader {
return &memReader{m: m, addr: addr, count: count} return &memReader{m: m, addr: addr, count: count}
} }
func (m *Memory) Usage() string {
total := uint64(len(m.Pages)) * PageSize
const unit = 1024
if total < unit {
return fmt.Sprintf("%d B", total)
}
div, exp := uint64(unit), 0
for n := total / unit; n >= unit; n /= unit {
div *= unit
exp++
}
// KiB, MiB, GiB, TiB, ...
return fmt.Sprintf("%.1f %ciB", float64(total)/float64(div), "KMGTPE"[exp])
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment