mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
app: make CPU timings more useful
Record the time for generating a frame and submitting it as well as the time for issuing the frame to the GPU and swapping buffers. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -291,6 +291,7 @@ func (g *GPU) renderLoop(glctx gl.Context) error {
|
|||||||
g.refreshErr <- glctx.MakeCurrent()
|
g.refreshErr <- glctx.MakeCurrent()
|
||||||
case frame := <-g.frames:
|
case frame := <-g.frames:
|
||||||
glctx.Lock()
|
glctx.Lock()
|
||||||
|
frameStart := time.Now()
|
||||||
if frame.collectStats && timers == nil && ctx.caps.EXT_disjoint_timer_query {
|
if frame.collectStats && timers == nil && ctx.caps.EXT_disjoint_timer_query {
|
||||||
timers = newTimers(ctx)
|
timers = newTimers(ctx)
|
||||||
zopsTimer = timers.newTimer()
|
zopsTimer = timers.newTimer()
|
||||||
@@ -348,8 +349,9 @@ func (g *GPU) renderLoop(glctx gl.Context) error {
|
|||||||
ft := zt + st + covt + cleant
|
ft := zt + st + covt + cleant
|
||||||
q := 100 * time.Microsecond
|
q := 100 * time.Microsecond
|
||||||
zt, st, covt = zt.Round(q), st.Round(q), covt.Round(q)
|
zt, st, covt = zt.Round(q), st.Round(q), covt.Round(q)
|
||||||
|
frameDur := time.Since(frameStart).Round(q)
|
||||||
ft = ft.Round(q)
|
ft = ft.Round(q)
|
||||||
res.summary = fmt.Sprintf("f:%7s zt:%7s st:%7s cov:%7s", ft, zt, st, covt)
|
res.summary = fmt.Sprintf("draw:%7s gpu:%7s zt:%7s st:%7s cov:%7s", frameDur, ft, zt, st, covt)
|
||||||
}
|
}
|
||||||
res.err = err
|
res.err = err
|
||||||
glctx.Unlock()
|
glctx.Unlock()
|
||||||
|
|||||||
+8
-17
@@ -26,10 +26,8 @@ type Option func(opts *window.Options)
|
|||||||
|
|
||||||
// Window represents an operating system window.
|
// Window represents an operating system window.
|
||||||
type Window struct {
|
type Window struct {
|
||||||
driver window.Driver
|
driver window.Driver
|
||||||
lastFrame time.Time
|
gpu *gpu.GPU
|
||||||
drawStart time.Time
|
|
||||||
gpu *gpu.GPU
|
|
||||||
|
|
||||||
out chan event.Event
|
out chan event.Event
|
||||||
in chan event.Event
|
in chan event.Event
|
||||||
@@ -123,27 +121,20 @@ func (w *Window) update(frame *op.Ops) {
|
|||||||
<-w.frameAck
|
<-w.frameAck
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) draw(size image.Point, frame *op.Ops) {
|
func (w *Window) draw(frameStart time.Time, size image.Point, frame *op.Ops) {
|
||||||
var drawDur time.Duration
|
|
||||||
if !w.drawStart.IsZero() {
|
|
||||||
drawDur = time.Since(w.drawStart)
|
|
||||||
w.drawStart = time.Time{}
|
|
||||||
}
|
|
||||||
w.gpu.Draw(w.queue.q.Profiling(), size, frame)
|
w.gpu.Draw(w.queue.q.Profiling(), size, frame)
|
||||||
w.queue.q.Frame(frame)
|
w.queue.q.Frame(frame)
|
||||||
now := time.Now()
|
|
||||||
switch w.queue.q.TextInputState() {
|
switch w.queue.q.TextInputState() {
|
||||||
case input.TextInputOpen:
|
case input.TextInputOpen:
|
||||||
w.driver.ShowTextInput(true)
|
w.driver.ShowTextInput(true)
|
||||||
case input.TextInputClose:
|
case input.TextInputClose:
|
||||||
w.driver.ShowTextInput(false)
|
w.driver.ShowTextInput(false)
|
||||||
}
|
}
|
||||||
frameDur := now.Sub(w.lastFrame)
|
|
||||||
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
|
||||||
w.lastFrame = now
|
|
||||||
if w.queue.q.Profiling() {
|
if w.queue.q.Profiling() {
|
||||||
|
frameDur := time.Since(frameStart)
|
||||||
|
frameDur = frameDur.Truncate(100 * time.Microsecond)
|
||||||
q := 100 * time.Microsecond
|
q := 100 * time.Microsecond
|
||||||
timings := fmt.Sprintf("tot:%7s cpu:%7s %s", frameDur.Round(q), drawDur.Round(q), w.gpu.Timings())
|
timings := fmt.Sprintf("tot:%7s %s", frameDur.Round(q), w.gpu.Timings())
|
||||||
w.queue.q.AddProfile(profile.Event{Timings: timings})
|
w.queue.q.AddProfile(profile.Event{Timings: timings})
|
||||||
}
|
}
|
||||||
if t, ok := w.queue.q.WakeupTime(); ok {
|
if t, ok := w.queue.q.WakeupTime(); ok {
|
||||||
@@ -260,7 +251,7 @@ func (w *Window) run(opts *window.Options) {
|
|||||||
// No drawing if not visible.
|
// No drawing if not visible.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
w.drawStart = time.Now()
|
frameStart := time.Now()
|
||||||
w.hasNextFrame = false
|
w.hasNextFrame = false
|
||||||
e2.Frame = w.update
|
e2.Frame = w.update
|
||||||
w.out <- e2.FrameEvent
|
w.out <- e2.FrameEvent
|
||||||
@@ -297,8 +288,8 @@ func (w *Window) run(opts *window.Options) {
|
|||||||
w.destroy(err)
|
w.destroy(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
w.draw(frameStart, e2.Size, frame)
|
||||||
if gotFrame {
|
if gotFrame {
|
||||||
w.draw(e2.Size, frame)
|
|
||||||
// We're done with frame, let the client continue.
|
// We're done with frame, let the client continue.
|
||||||
w.frameAck <- struct{}{}
|
w.frameAck <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user