Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to parse trace: no EvFrequency event

Tags:

go

I generate a trace like this:

func main() {
    f, err := os.Create("trace.out")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    err = trace.Start(f)
    if err != nil {
        panic(err)
    }
    defer trace.Stop()
//this is my app:
    http.HandleFunc("/", someFunc)
    log.Fatal(http.ListenAndServe(":5000", nil))
}

Then i run in the CLI:

$ go run main.go

Refresh browser, trace.out is generated, 1.8 MB, then:

$ go tool trace trace.out
018/09/09 13:25:18 Parsing trace...
failed to parse trace: no EvFrequency event

What am I missing here? Thanks.

like image 615
Gabriel Avatar asked Oct 20 '25 01:10

Gabriel


1 Answers

Trace data can only be viewed after you stopped the trace (i.e. after trace.Stop() has been called). In the code you supplied http.ListenAndServer(...) will block forever (unless it runs into an error).

Are you trying to view the trace before the trace has been stopped?

One solution might be to wait for an interrupt signal and then exit the function when received which would cause the tracing to be stopped and written.

func main() {
    f, err := os.Create("trace.out")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    err = trace.Start(f)
    if err != nil {
        panic(err)
    }
    defer trace.Stop()

    http.HandleFunc("/", someFunc)
    go func() {
        log.Fatal(http.ListenAndServe(":5000", nil))
    }()

    signalChan := make(chan os.Signal, 1)
    signal.Notify(signalChan, os.Interrupt)
    <-signalChan
}
like image 111
dolan Avatar answered Oct 22 '25 01:10

dolan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!