34 lines
759 B
Go
34 lines
759 B
Go
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())
|
|
|
|
}
|