mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
apps/gophers: add per-frame mallocs to profiling status line
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/image/draw"
|
"golang.org/x/image/draw"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -166,6 +167,7 @@ func init() {
|
|||||||
func (a *App) run() error {
|
func (a *App) run() error {
|
||||||
a.w.Profiling = *stats
|
a.w.Profiling = *stats
|
||||||
ops := new(ui.Ops)
|
ops := new(ui.Ops)
|
||||||
|
var lastMallocs uint64
|
||||||
for a.w.IsAlive() {
|
for a.w.IsAlive() {
|
||||||
select {
|
select {
|
||||||
case users := <-a.updateUsers:
|
case users := <-a.updateUsers:
|
||||||
@@ -217,11 +219,16 @@ func (a *App) run() error {
|
|||||||
cs := layout.ExactConstraints(a.w.Size())
|
cs := layout.ExactConstraints(a.w.Size())
|
||||||
a.Layout(ops, cs)
|
a.Layout(ops, cs)
|
||||||
if a.w.Profiling {
|
if a.w.Profiling {
|
||||||
|
var mstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&mstats)
|
||||||
|
mallocs := mstats.Mallocs - lastMallocs
|
||||||
|
lastMallocs = mstats.Mallocs
|
||||||
al := layout.Align{Alignment: layout.NE}
|
al := layout.Align{Alignment: layout.NE}
|
||||||
cs := al.Begin(ops, cs)
|
cs := al.Begin(ops, cs)
|
||||||
in := layout.Insets{Top: a.cfg.Dp(16)}
|
in := layout.Insets{Top: a.cfg.Dp(16)}
|
||||||
cs = in.Begin(ops, cs)
|
cs = in.Begin(ops, cs)
|
||||||
dims := text.Label{Src: textColor, Face: a.face(fonts.mono, 8), Text: a.w.Timings()}.Layout(ops, cs)
|
txt := fmt.Sprintf("m: %d %s", mallocs, a.w.Timings())
|
||||||
|
dims := text.Label{Src: textColor, Face: a.face(fonts.mono, 8), Text: txt}.Layout(ops, cs)
|
||||||
dims = in.End(ops, dims)
|
dims = in.End(ops, dims)
|
||||||
al.End(ops, dims)
|
al.End(ops, dims)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user