Memory profiling code. Updates to reduce memory footprint.

This commit is contained in:
gmp
2019-08-28 11:48:22 -04:00
parent 635655e768
commit 83c9d40500
8 changed files with 547 additions and 174 deletions
+54 -29
View File
@@ -4,6 +4,8 @@ import (
"fmt"
"image/color"
"log"
"runtime"
"time"
gio "git.wow.st/gmp/giowrap"
@@ -99,18 +101,21 @@ func eventloop() {
lbar := gio.NewLabel(" ", gio.Face(face))
f2 := gio.NewFlex(gio.Axis(layout.Vertical))
topbar := gio.NewLabel("Scroll X and Y. Click to select", gio.Face(face))
f3 := gio.NewFlex(gio.Axis(layout.Horizontal))
f4 := gio.NewFlex(gio.Axis(layout.Vertical))
sh := gio.HScroll(gio.NewFlex(gio.Axis(layout.Horizontal)))
sv := gio.VScroll(gio.NewFlex(gio.Axis(layout.Vertical)))
numlabs := 50
labs := make([][]gio.Widget, numlabs)
sels := make([][]bool, numlabs)
for i := 0; i < 16; i++ {
labs[i] = make([]gio.Widget, numlabs)
sels[i] = make([]bool, numlabs)
for j := 0; j < numlabs; j++ {
labs[i][j] = NewSLabel(fmt.Sprintf("%03d", i*16+j), &sels[i][j])
numrows := 16
numcols := 50
labs := make([][]gio.Widget, numrows)
sels := make([][]bool, numrows)
for i := 0; i < numrows; i++ {
labs[i] = make([]gio.Widget, numcols)
sels[i] = make([]bool, numcols)
for j := 0; j < numcols; j++ {
labs[i][j] = NewSLabel(fmt.Sprintf("%03d", i+j*numrows), &sels[i][j])
}
}
@@ -120,8 +125,30 @@ func eventloop() {
gio.Left(x.Left), gio.Right(x.Right))
}
page := sysbg(sysinset(bg(margin(
f1(lbar, f2(topbar, sh(sv(f3(
f4(labs[0]...),
f4(labs[1]...),
f4(labs[2]...),
f4(labs[3]...),
f4(labs[4]...),
f4(labs[5]...),
f4(labs[6]...),
f4(labs[7]...),
f4(labs[8]...),
f4(labs[9]...),
f4(labs[10]...),
f4(labs[11]...),
f4(labs[12]...),
f4(labs[13]...),
f4(labs[14]...),
f4(labs[15]...),
)))))))))
var oldInsets app.Insets
stime := time.Now()
sm := runtime.MemStats{}
for {
select {
case e := <-w.Events():
@@ -129,32 +156,30 @@ func eventloop() {
case app.DestroyEvent:
return
case app.UpdateEvent:
ctx.Reset(e)
profileNow := time.Since(stime) > time.Second*2
if profileNow {
stime = time.Now()
//gio.RecordMallocs()
runtime.ReadMemStats(&sm)
}
gio.Mallocs("start")
ctx.Reset(&e)
if diffInsets(e.Insets, oldInsets) {
oldInsets = e.Insets
resetSysinset(e.Insets)
}
sysbg(sysinset(bg(margin(
f1(lbar, f2(topbar, sh(
sv(labs[0]...),
sv(labs[1]...),
sv(labs[2]...),
sv(labs[3]...),
sv(labs[4]...),
sv(labs[5]...),
sv(labs[6]...),
sv(labs[7]...),
sv(labs[8]...),
sv(labs[9]...),
sv(labs[10]...),
sv(labs[11]...),
sv(labs[12]...),
sv(labs[13]...),
sv(labs[14]...),
sv(labs[15]...),
))))))).Layout(ctx)
page.Layout(ctx)
ctx.Update()
gio.Mallocs("end")
if profileNow {
for _, m := range gio.AllMallocs {
fmt.Printf("Mallocs: %d (%s)\n", m.Value, m.Text)
}
gio.AllMallocs = nil
oldMallocs := sm.Mallocs
runtime.ReadMemStats(&sm)
fmt.Printf("Mallocs = %d\n", sm.Mallocs-oldMallocs)
}
}
}
}