Teffy is a library for reading & writing Google Chrome Trace Event Format files in Go.
go get github.com/omaskery/teffy
The package is split into three main parts:
events
- the logical representation of trace eventsio
- the ability to read/write events to files (including streaming)utils/trace
- opinionated utilities for generating traces
package main
import (
"fmt"
"os"
tio "github.com/omaskery/teffy/pkg/io"
)
func main() {
f, _ := os.Open("some.trace")
defer f.Close()
trace, _ := tio.ParseJsonObj(f)
for _, event := range trace.Events() {
fmt.Printf("- %v\n", event)
}
}
package main
import (
"os"
"github.com/omaskery/teffy/pkg/events"
tio "github.com/omaskery/teffy/pkg/io"
)
func main() {
f, _ := os.OpenFile("some.trace", os.O_RDWR, os.ModePerm)
defer f.Close()
data := tio.TefData{}
data.Write(&events.BeginDuration{
Name: "my event",
Categories: []string{ "cool", "categories" },
Timestamp: 0,
})
// your amazing code
data.Write(&events.EndDuration{
Name: "my event",
Categories: []string{ "cool", "categories" },
Timestamp: 100,
})
_ = tio.WriteJsonObject(f, data)
}
package main
import (
"github.com/omaskery/teffy/pkg/util/trace"
)
func main() {
t, _ := trace.TraceToFile("some.trace")
defer t.Close()
defer t.BeginDuration("my event", trace.WithCategories("cool", "categories")).End()
// your amazing code
t.Instant("wow a thing happened!", trace.WithStackTrace())
}