golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/cmd/gotracevalidate/main.go (about)

     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.
     4  
     5  // Code generated by "gen.bash" from internal/trace/v2; DO NOT EDIT.
     6  
     7  //go:build go1.21
     8  
     9  package main
    10  
    11  import (
    12  	"flag"
    13  	"fmt"
    14  	"io"
    15  	"log"
    16  	"os"
    17  
    18  	"golang.org/x/exp/trace"
    19  	"golang.org/x/exp/trace/internal/testtrace"
    20  )
    21  
    22  func init() {
    23  	flag.Usage = func() {
    24  		fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s\n", os.Args[0])
    25  		fmt.Fprintf(flag.CommandLine.Output(), "\n")
    26  		fmt.Fprintf(flag.CommandLine.Output(), "Accepts a trace at stdin and validates it.\n")
    27  		flag.PrintDefaults()
    28  	}
    29  	log.SetFlags(0)
    30  }
    31  
    32  var logEvents = flag.Bool("log-events", false, "whether to log events")
    33  
    34  func main() {
    35  	flag.Parse()
    36  
    37  	r, err := trace.NewReader(os.Stdin)
    38  	if err != nil {
    39  		log.Fatal(err)
    40  	}
    41  	v := testtrace.NewValidator()
    42  	for {
    43  		ev, err := r.ReadEvent()
    44  		if err == io.EOF {
    45  			break
    46  		}
    47  		if err != nil {
    48  			log.Fatal(err)
    49  		}
    50  		if *logEvents {
    51  			log.Println(ev.String())
    52  		}
    53  		if err := v.Event(ev); err != nil {
    54  			log.Fatal(err)
    55  		}
    56  	}
    57  }