501bdf712a026c2113b4f7141828d5554febf217 — Chris Waldon 4 months ago 948c1d3
doc: fix package name and add pkg usage example

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2 files changed, 44 insertions(+), 1 deletions(-)

M profiling.go
A README.md => README.md +7 -0
@@ 0,0 1,7 @@
## gioprofiler

Profiling tools for gio

## Licensing

Dual Unlicense/MIT

M profiling.go => profiling.go +37 -1
@@ 1,4 1,40 @@
package profiling
Package gioprofiler provides tools for recording frame timings for later analysis.

The simplest usage is to construct a profilier at the start of your event loop
function and to defer stopping it until the window is closed. Something like:

    func loop(w *app.Window) error {
        // log to a CSV file with a randomly-chosen name. The file's path will be
        // logged to stderr.
        recorder, err := NewRecorder(nil)
        if err != nil {
            // handle
        defer recorder.Stop()

        var ops op.Ops

        for event := range window.Events() {
            switch event := event.(type) {
                case system.DestroyEvent:
                    // returning will execute the deferred call to Stop(), which
                    // flushes the CSV file.
                    return event.Err
                case system.FrameEvent:
                    gtx := layout.NewContext(&ops, event)

                    // record the last frame's timing info and prepare the next one

                    // lay out your UI here

The actual disk I/O is performed by a different goroutine and will not block the UI unless it gets more than 60 frames behind.
package gioprofiler

import (