duanjue6584 2018-09-09 16:33 采纳率: 100%
浏览 638
已采纳

无法解析跟踪:没有EvFrequency事件

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.

  • 写回答

1条回答 默认 最新

  • dsfdgdsfd23212 2018-09-09 16:55
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器