mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
apps/gophers: upgrade to new profiling api
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ module gioui.org/apps
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org/ui v0.0.0-20190712120518-326f78c3413a
|
gioui.org/ui v0.0.0-20190712123730-25a20af2843d
|
||||||
github.com/google/go-github/v24 v24.0.1
|
github.com/google/go-github/v24 v24.0.1
|
||||||
golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f
|
golang.org/x/exp v0.0.0-20190627132806-fd42eb6b336f
|
||||||
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
|
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9
|
||||||
|
|||||||
+31
-16
@@ -29,6 +29,7 @@ import (
|
|||||||
"gioui.org/ui/f32"
|
"gioui.org/ui/f32"
|
||||||
"gioui.org/ui/gesture"
|
"gioui.org/ui/gesture"
|
||||||
"gioui.org/ui/input"
|
"gioui.org/ui/input"
|
||||||
|
"gioui.org/ui/input/system"
|
||||||
"gioui.org/ui/key"
|
"gioui.org/ui/key"
|
||||||
"gioui.org/ui/layout"
|
"gioui.org/ui/layout"
|
||||||
"gioui.org/ui/measure"
|
"gioui.org/ui/measure"
|
||||||
@@ -67,6 +68,11 @@ type App struct {
|
|||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
ctxCancel context.CancelFunc
|
ctxCancel context.CancelFunc
|
||||||
|
|
||||||
|
// Profiling.
|
||||||
|
profiling bool
|
||||||
|
profile system.ProfileEvent
|
||||||
|
lastMallocs uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type userPage struct {
|
type userPage struct {
|
||||||
@@ -182,9 +188,8 @@ func colorMaterial(ops *ui.Ops, color color.RGBA) ui.BlockOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) run() error {
|
func (a *App) run() error {
|
||||||
a.w.Profiling = *stats
|
a.profiling = *stats
|
||||||
ops := new(ui.Ops)
|
ops := new(ui.Ops)
|
||||||
var lastMallocs uint64
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case users := <-a.updateUsers:
|
case users := <-a.updateUsers:
|
||||||
@@ -200,7 +205,7 @@ func (a *App) run() error {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case 'P':
|
case 'P':
|
||||||
if e.Modifiers.Contain(key.ModCommand) {
|
if e.Modifiers.Contain(key.ModCommand) {
|
||||||
a.w.Profiling = !a.w.Profiling
|
a.profiling = !a.profiling
|
||||||
a.w.Redraw()
|
a.w.Redraw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,19 +241,8 @@ func (a *App) run() error {
|
|||||||
a.cfg = e.Config
|
a.cfg = e.Config
|
||||||
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.profiling {
|
||||||
var mstats runtime.MemStats
|
a.layoutTimings(ops, cs)
|
||||||
runtime.ReadMemStats(&mstats)
|
|
||||||
mallocs := mstats.Mallocs - lastMallocs
|
|
||||||
lastMallocs = mstats.Mallocs
|
|
||||||
al := layout.Align{Alignment: layout.NE}
|
|
||||||
cs := al.Begin(ops, cs)
|
|
||||||
in := layout.Insets{Top: ui.Dp(16)}
|
|
||||||
cs = in.Begin(&a.cfg, ops, cs)
|
|
||||||
txt := fmt.Sprintf("m: %d %s", mallocs, a.w.Timings())
|
|
||||||
dims := text.Label{Material: theme.text, Face: a.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
|
|
||||||
dims = in.End(dims)
|
|
||||||
al.End(dims)
|
|
||||||
}
|
}
|
||||||
a.w.Draw(ops)
|
a.w.Draw(ops)
|
||||||
a.faces.Frame()
|
a.faces.Frame()
|
||||||
@@ -396,6 +390,27 @@ func (a *App) face(f *sfnt.Font, size float32) text.Face {
|
|||||||
return a.faces.For(f, ui.Sp(size))
|
return a.faces.For(f, ui.Sp(size))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) layoutTimings(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
|
for _, e := range a.inputs.Events(a) {
|
||||||
|
if e, ok := e.(system.ProfileEvent); ok {
|
||||||
|
a.profile = e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
system.ProfileOp{Key: a}.Add(ops)
|
||||||
|
var mstats runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&mstats)
|
||||||
|
mallocs := mstats.Mallocs - a.lastMallocs
|
||||||
|
a.lastMallocs = mstats.Mallocs
|
||||||
|
al := layout.Align{Alignment: layout.NE}
|
||||||
|
cs = al.Begin(ops, cs)
|
||||||
|
in := layout.Insets{Top: ui.Dp(16)}
|
||||||
|
cs = in.Begin(&a.cfg, ops, cs)
|
||||||
|
txt := fmt.Sprintf("m: %d %s", mallocs, a.profile.Timings)
|
||||||
|
dims := text.Label{Material: theme.text, Face: a.face(fonts.mono, 10), Text: txt}.Layout(ops, cs)
|
||||||
|
dims = in.End(dims)
|
||||||
|
return al.End(dims)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
func (a *App) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||||
for i := range a.userClicks {
|
for i := range a.userClicks {
|
||||||
click := &a.userClicks[i]
|
click := &a.userClicks[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user