text stringlengths 0 1.47k |
|---|
now.Sub(start).Seconds(), len(gaps), cur, gaps[len(gaps)-1].Round(time.Microsecond)) |
} |
} |
if forDur > 0 && now.Sub(start) >= forDur { |
break |
} |
time.Sleep(poll) |
} |
elapsed := time.Since(start) |
fmt.Printf("\n%d frames in %v: %.1f frames/s\n", |
len(gaps), elapsed.Round(time.Millisecond), float64(len(gaps))/elapsed.Seconds()) |
if len(gaps) > 0 { |
mn, p50, p95, mx := spread(gaps) |
fmt.Printf("interval min %v, p50 %v, p95 %v, max %v\n", |
mn.Round(time.Microsecond), p50.Round(time.Microsecond), p95.Round(time.Microsecond), mx.Round(time.Microsecond)) |
} |
if len(seen) > 0 { |
fmt.Printf("pages seen: %s\n", counts(seen)) |
} |
return nil |
} |
// fillPage writes one color over a whole framebuffer page, doubling a word rather than looping a |
// pixel at a time: the driver is what is being measured, so the write is kept out of the way and |
// what it costs to render a real page is added on top of the figure this gives. |
func fillPage(page []byte, c color.RGBA, v varInfo) { |
var px uint32 |
px |= uint32(c.R) << v.Red[0] |
px |= uint32(c.G) << v.Green[0] |
px |= uint32(c.B) << v.Blue[0] |
px |= uint32(c.A) << v.Transp[0] |
var word [4]byte |
binary.LittleEndian.PutUint32(word[:], px) |
// A page is a whole row of a panel, so this is only to make the function total: what is shorter |
// than a pixel has no whole word to double, and the doubling below would not keep the pattern's |
// four-byte period in any case. |
if len(page) < len(word) { |
copy(page, word[:len(page)]) |
return |
} |
n := copy(page, word[:]) |
for n < len(page) { |
n += copy(page[n:], page[:n]) |
} |
} |
// verdict says what one pan costs, since that is the number the whole bench exists for. The panel |
// scans out at 59.64 Hz, so a pan of about 16.7 ms is one frame period and the driver pacing itself |
// against the panel; about twice that is two, and the driver is the ceiling near 30 frames a second. |
// It is deliberately a reading and not a law: what the pan waits for is the command queue, and a |
// device under load can take longer for reasons that have nothing to do with the panel. |
func verdict(pan, pace time.Duration, late int) string { |
switch { |
case pace > 0 && late > 0: |
return fmt.Sprintf("asked for %v and did not keep it: %d frame(s) went late", pace, late) |
case pan >= 30*time.Millisecond: |
return "a pan costs about two frame periods: expect a ceiling near 30 frames/s" |
case pan >= 12*time.Millisecond: |
return "a pan costs about one frame period (59.64 Hz panel): the driver paces itself at vsync" |
default: |
return "a pan returns in well under a frame period: the panel is not the ceiling here" |
} |
} |
// paceNote is how a bench run was paced, in words, with the rate that comes of it. |
func paceNote(pace time.Duration) string { |
if pace <= 0 { |
return ", as fast as the driver takes it" |
} |
return fmt.Sprintf(", paced to %v (%.1f frames/s)", pace, 1/pace.Seconds()) |
} |
// benchPresent drives the panel as fast as the driver will take it, and times the two halves of a |
// frame apart: writing the page, and the pan that puts it up. The pan is the half that sets the |
// ceiling, because it is the driver's own cost and is the same for every program that presents; the |
// write here is a bare fill, so a daemon that renders into its page adds its own work on top and |
// presents more slowly than this. For what the daemon actually manages, use -watch. |
// |
// Every frame a different color, over the whole panel, deliberately: the screen's Present skips rows |
// that have not changed, so a bench that redraws one picture measures the skipping and not the |
// presenting, and reports a rate no moving content could reach. The pages are cycled the way the |
// daemon cycles them, so the pattern this paints is also one a camera can count. |
func benchPresent(f *os.File, mem []byte, v varInfo, line, panelW, panelH, pages, iters int, |
pace, forDur time.Duration, a, b color.RGBA, each bool) error { |
pageBytes := line * panelH |
if pages < 1 || pageBytes <= 0 { |
return fmt.Errorf("no frame fits the mapping (%d by %d, %d pages)", line, panelH, pages) |
} |
if need := pageBytes * pages; len(mem) < need { |
return fmt.Errorf("mapped %d bytes, need %d for %d pages", len(mem), need, pages) |
} |
// Nothing here may leave the panel holding something the daemon does not know about; see keepPanel. |
kept := keepPanel(mem, line, panelH, pages, v) |
defer kept.restore(f, mem, v) |
fmt.Printf("bench: %dx%d, %d page(s), colors %02x%02x%02x / %02x%02x%02x%s\n", |
panelW, panelH, pages, a.R, a.G, a.B, b.R, b.G, b.B, paceNote(pace)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.