From 80af40e97caea71decee629741279b228a951fa7 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 18 Sep 2018 14:02:08 +0200 Subject: [PATCH] more frame dump information --- context.go | 22 +++++++++++++--------- shiny.go | 19 +++++++++++++++++-- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/context.go b/context.go index 8c02f95..945ccb8 100644 --- a/context.go +++ b/context.go @@ -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) { @@ -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: @@ -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 { @@ -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() } @@ -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, @@ -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 { diff --git a/shiny.go b/shiny.go index 11c0af6..a48b42d 100644 --- a/shiny.go +++ b/shiny.go @@ -1,6 +1,7 @@ package nucular import ( + "bufio" "bytes" "errors" "fmt" @@ -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 {