1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "internal/trace/v2/version"
14 // TextWriter emits the text format of a trace.
15 type TextWriter struct {
20 // NewTextWriter creates a new write for the trace text format.
21 func NewTextWriter(w io.Writer, v version.Version) (*TextWriter, error) {
22 _, err := fmt.Fprintf(w, "Trace Go1.%d\n", v)
26 return &TextWriter{w: w, v: v}, nil
29 // WriteEvent writes a single event to the stream.
30 func (w *TextWriter) WriteEvent(e Event) error {
33 return fmt.Errorf("mismatched version between writer (go 1.%d) and event (go 1.%d)", w.v, e.Version)
37 _, err := fmt.Fprintln(w.w, e.String())