Commit 895976f2 authored by vipwzw's avatar vipwzw

测试cache的内存花费

parent 1569ff03
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math" "math"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
...@@ -230,3 +231,29 @@ func TestCalcLocalPrefix(t *testing.T) { ...@@ -230,3 +231,29 @@ func TestCalcLocalPrefix(t *testing.T) {
assert.Equal(t, calcCodeKey("a"), []byte("mavl-js-code-a")) assert.Equal(t, calcCodeKey("a"), []byte("mavl-js-code-a"))
assert.Equal(t, calcRollbackKey([]byte("a")), []byte("LODB-js-rollback-a")) assert.Equal(t, calcRollbackKey([]byte("a")), []byte("LODB-js-rollback-a"))
} }
func TestCacheMemUsage(t *testing.T) {
dir, ldb, kvdb := util.CreateTestDB()
defer util.CloseTestDB(dir, ldb)
e := initExec(ldb, kvdb, t)
vm, err := e.createVM("test", nil, 0)
assert.Nil(t, err)
vms := make([]*otto.Otto, 1024)
for i := 0; i < 1024; i++ {
vms[i] = vm.Copy()
}
printMemUsage()
}
func printMemUsage() {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}
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