Skip to content

Commit

Permalink
logs: put heap logging of wasman interpreter behind Debug option
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Mar 4, 2024
1 parent 6384fcc commit e9ef29e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package mechanoid

var debug = true
var Debug = true
25 changes: 19 additions & 6 deletions interp/wasman/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (i *Interpreter) Init() error {
}

func (i *Interpreter) Load(code engine.Reader) error {
ms := runtime.MemStats{}

if mechanoid.Debug {
runtime.ReadMemStats(&ms)
println("Interpreter Load - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
}

conf := config.ModuleConfig{
Recover: true,
Logger: mechanoid.Log,
Expand All @@ -61,8 +68,10 @@ func (i *Interpreter) Load(code engine.Reader) error {
func (i *Interpreter) Run() (engine.Instance, error) {
ms := runtime.MemStats{}

runtime.ReadMemStats(&ms)
println("Heap start Run Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
if mechanoid.Debug {
runtime.ReadMemStats(&ms)
println("Interpreter Run - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
}

var err error
i.instance, err = i.linker.Instantiate(i.module)
Expand All @@ -84,8 +93,10 @@ func (i *Interpreter) Run() (engine.Instance, error) {
func (i *Interpreter) Halt() error {
ms := runtime.MemStats{}

runtime.ReadMemStats(&ms)
println("Heap start Halt Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
if mechanoid.Debug {
runtime.ReadMemStats(&ms)
println("Interpreter Halt - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
}

// clean up extern refs
i.references.Clear()
Expand All @@ -95,8 +106,10 @@ func (i *Interpreter) Halt() error {
// force a garbage collection to free memory
runtime.GC()

runtime.ReadMemStats(&ms)
println("Heap start Halt after gc: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
if mechanoid.Debug {
runtime.ReadMemStats(&ms)
println("Interpreter Halt after GC - Heap Used: ", ms.HeapInuse, " Free: ", ms.HeapIdle, " Meta: ", ms.GCSys)
}

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mechanoid

// Log a message into terminal if debug mode is enabled
func Log(msg string) {
if debug {
if Debug {
println(msg)
}
}
2 changes: 1 addition & 1 deletion nodebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

package mechanoid

var debug = false
var Debug = false

0 comments on commit e9ef29e

Please sign in to comment.