8

私は顧客のhttpサービスを持っています:

    s := &http.Server{
            Addr:         config.Port,
            Handler:      Controller.Log(http.DefaultServeMux),
            ReadTimeout:  3 * time.Second,
            WriteTimeout: 3 * time.Second,
    }

    http.HandleFunc("/exapmle/router/", exampleFunc)

    err := s.ListenAndServe()
    if err != nil {
            log.Critical(err)
            os.Exit(1)
    }

それは動作しません:

go tool pprof http://localhost:8201/debug/pprof/profile

戻りエラー:

Failed to fetch http://localhost:8201/debug/pprof/profile?seconds=30

ありがとう。

編集: 問題は、デフォルトの http サーバーを書き直し、net/http/pprof パッケージに http ハンドラーを挿入することだと思います。

func init() {
    http.Handle("/debug/pprof/", http.HandlerFunc(Index))
    http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
    http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
    http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
}

私のコードではハンドラーが機能しません。

4

1 に答える 1

9

「WriteTimeout」をプロファイル書き込み時間よりも短く設定します。

pprof.StartCPUProfile() 実行時, すでに書き込みを開始しています. 参照:

したがって、http.WriteTimeout はプロファイルの書き込み時間より大きくなければなりません。

下手な英語でごめんなさい。

于 2014-01-02T03:22:22.897 に答える