Skip to content

Commit

Permalink
more frame dump information
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Sep 18, 2018
1 parent d9b3ac4 commit 80af40e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
22 changes: 13 additions & 9 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type context struct {
floatWindowFocus int
scrollwheelFocus int
dockedCnt int

cmdstim []time.Duration // contains timing for all commands
}

func contextAllCommands(ctx *context) {
Expand Down Expand Up @@ -309,7 +311,14 @@ func (ctx *context) Draw(wimg *image.RGBA) int {
painter = &myRGBAPainter{Image: img}
}

if ctx.cmdstim != nil {
ctx.cmdstim = ctx.cmdstim[:0]
}

for i := range ctx.cmds {
if perfUpdate {
t0 = time.Now()
}
icmd := &ctx.cmds[i]
switch icmd.Kind {
case command.ScissorCmd:
Expand Down Expand Up @@ -363,9 +372,6 @@ func (ctx *context) Draw(wimg *image.RGBA) int {
// first command draws the background, insure that it's always fully opaque
cmd.Color.A = 0xff
}
if perfUpdate {
t0 = time.Now()
}
colimg := image.NewUniform(cmd.Color)
op := draw.Over
if cmd.Color.A == 0xff {
Expand Down Expand Up @@ -484,9 +490,6 @@ func (ctx *context) Draw(wimg *image.RGBA) int {

case command.TriangleFilledCmd:
cmd := icmd.TriangleFilled
if perfUpdate {
t0 = time.Now()
}
if rasterizer == nil {
setupRasterizer()
}
Expand Down Expand Up @@ -520,9 +523,6 @@ func (ctx *context) Draw(wimg *image.RGBA) int {
draw.Draw(img, icmd.Rectangle(), icmd.Image.Img, image.Point{}, draw.Src)

case command.TextCmd:
if perfUpdate {
t0 = time.Now()
}
dstimg := wimg.SubImage(img.Bounds().Intersect(icmd.Rectangle())).(*image.RGBA)
d := font.Drawer{
Dst: dstimg,
Expand All @@ -549,6 +549,10 @@ func (ctx *context) Draw(wimg *image.RGBA) int {
default:
panic(UnknownCommandErr)
}

if dumpFrame {
ctx.cmdstim = append(ctx.cmdstim, time.Since(t0))
}
}

if perfUpdate {
Expand Down
19 changes: 17 additions & 2 deletions shiny.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nucular

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -411,11 +412,25 @@ func (w *masterWindow) updateLocked() {

draw.Draw(wimg, bounds, image.White, bounds.Min, draw.Src)

fh, err := os.Create(fmt.Sprintf("framedump/frame%d.png", frameCnt))
if err == nil {
if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.png", frameCnt)); err == nil {
png.Encode(fh, wimg)
fh.Close()
}

if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.txt", frameCnt)); err == nil {
wr := bufio.NewWriter(fh)
fps := 1.0 / te.Sub(t0).Seconds()
tot := time.Duration(0)
fmt.Fprintf(wr, "# Update %0.4fms = %0.4f updatefn + %0.4f draw (%d primitives) [max fps %0.2f]\n", te.Sub(t0).Seconds()*1000, t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, nprimitives, fps)
for i := range w.prevCmds {
fmt.Fprintf(wr, "%0.2fms %#v\n", w.ctx.cmdstim[i].Seconds()*1000, w.prevCmds[i])
tot += w.ctx.cmdstim[i]
}
fmt.Fprintf(wr, "sanity check %0.2fms\n", tot.Seconds()*1000)
wr.Flush()
fh.Close()
}

frameCnt++
}
if nprimitives > 0 {
Expand Down

0 comments on commit 80af40e

Please sign in to comment.