app/system/profile_test.go

34 lines
759 B
Go
Raw Permalink Normal View History

2021-12-16 04:11:33 +00:00
package system
import (
"fmt"
"runtime"
"testing"
"time"
)
func TestProfile(t *testing.T) {
fmt.Printf("%+v\n", GetProfile())
var overall [][]int
for i := 0; i < 4; i++ {
// Allocate memory using make() and append to overall (so it doesn't get
// garbage collected). This is to create an ever increasing memory usage
// which we can track. We're just using []int as an example.
a := make([]int, 0, 999999)
overall = append(overall, a)
// Print our memory usage at each interval
fmt.Printf("%+v\n", GetProfile())
time.Sleep(time.Second)
}
// Clear our memory and print usage, unless the GC has run 'Alloc' will remain the same
overall = nil
fmt.Printf("%+v\n", GetProfile())
runtime.GC()
fmt.Printf("%+v\n", GetProfile())
}