diff --git a/engine/engine.go b/engine/engine.go index b762da6..faf33c0 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -45,19 +45,19 @@ func (e *Engine) Init() error { return ErrNoInterpreter } - mechanoid.Log("Initializing interpreter...") + mechanoid.Debug("Initializing interpreter...") if err := e.Interpreter.Init(); err != nil { return fmt.Errorf("init interpreter: %v", err) } if e.FileStore != nil { - mechanoid.Log("Initializing file store...") + mechanoid.Debug("Initializing file store...") if err := e.FileStore.Init(); err != nil { return fmt.Errorf("init file store: %v", err) } } - mechanoid.Log("Initializing devices...") + mechanoid.Debug("Initializing devices...") for _, d := range e.Devices { err := d.Init() if err != nil { diff --git a/interp/wasman/interp.go b/interp/wasman/interp.go index 47c1c85..b0684ef 100644 --- a/interp/wasman/interp.go +++ b/interp/wasman/interp.go @@ -37,12 +37,7 @@ func (i *Interpreter) Init() error { } func (i *Interpreter) Load(code engine.Reader) error { - ms := runtime.MemStats{} - - if mechanoid.Debugging { - runtime.ReadMemStats(&ms) - mechanoid.Debug("Interpreter Load - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) - } + mechanoid.DebugMemory("Interpreter Load") conf := config.ModuleConfig{ Recover: true, @@ -59,12 +54,7 @@ func (i *Interpreter) Load(code engine.Reader) error { } func (i *Interpreter) Run() (engine.Instance, error) { - ms := runtime.MemStats{} - - if mechanoid.Debugging { - runtime.ReadMemStats(&ms) - mechanoid.Debug("Interpreter Run - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) - } + mechanoid.DebugMemory("Interpreter Run") var err error i.instance, err = i.linker.Instantiate(i.module) @@ -84,21 +74,14 @@ func (i *Interpreter) Run() (engine.Instance, error) { } func (i *Interpreter) Halt() error { - ms := runtime.MemStats{} + mechanoid.DebugMemory("Interpreter Halt") - if mechanoid.Debugging { - runtime.ReadMemStats(&ms) - mechanoid.Debug("Interpreter Halt - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) - } i.instance = nil i.module = nil + // force a garbage collection to free memory runtime.GC() - - if mechanoid.Debugging { - runtime.ReadMemStats(&ms) - mechanoid.Debug("Interpreter Halt after GC - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) - } + mechanoid.DebugMemory("Interpreter Halt after GC") return nil } diff --git a/log.go b/log.go index 1a033b4..b5ac51e 100644 --- a/log.go +++ b/log.go @@ -8,17 +8,17 @@ func Log(msg string) { } // Log a message into terminal if debug mode is enabled -func Debug(args ...any) { +func Debug(msg string) { if Debugging { - println(args) + println(msg) } } // DebugMemory prints memory usage if debug mode is enabled. -func DebugMemory(args ...any) { +func DebugMemory(msg string) { if Debugging { ms := runtime.MemStats{} runtime.ReadMemStats(&ms) - println(args, "Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) + println(msg, "Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys) } }