7 "internal/trace/v2/event"
8 "internal/trace/v2/event/go122"
11 // Version represents the version of a trace file.
18 var versions = map[Version][]event.Spec{
22 // Specs returns the set of event.Specs for this version.
23 func (v Version) Specs() []event.Spec {
27 func (v Version) Valid() bool {
32 // headerFmt is the format of the header of all Go execution traces.
33 const headerFmt = "go 1.%d trace\x00\x00\x00"
35 // ReadHeader reads the version of the trace out of the trace file's
36 // header, whose prefix must be present in v.
37 func ReadHeader(r io.Reader) (Version, error) {
39 _, err := fmt.Fscanf(r, headerFmt, &v)
41 return v, fmt.Errorf("bad file format: not a Go execution trace?")
44 return v, fmt.Errorf("unknown or unsupported trace version go 1.%d", v)
49 // WriteHeader writes a header for a trace version v to w.
50 func WriteHeader(w io.Writer, v Version) (int, error) {
51 return fmt.Fprintf(w, headerFmt, v)