<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                Go語言有一個非常棒的設計就是標準庫里面帶有代碼的性能監控工具,在兩個地方有包: ~~~ net/http/pprof runtime/pprof ~~~ 其實net/http/pprof中只是使用runtime/pprof包來進行封裝了一下,并在http端口上暴露出來 ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/14.6.md#beego支持pprof)beego支持pprof 目前beego框架新增了pprof,該特性默認是不開啟的,如果你需要測試性能,查看相應的執行goroutine之類的信息,其實Go的默認包"net/http/pprof"已經具有該功能,如果按照Go默認的方式執行Web,默認就可以使用,但是由于beego重新封裝了ServHTTP函數,默認的包是無法開啟該功能的,所以需要對beego的內部改造支持pprof。 * 首先在beego.Run函數中根據變量是否自動加載性能包 ~~~ if PprofOn { BeeApp.RegisterController(`/debug/pprof`, &ProfController{}) BeeApp.RegisterController(`/debug/pprof/:pp([\w]+)`, &ProfController{}) } ~~~ * 設計ProfConterller ~~~ package beego import ( "net/http/pprof" ) type ProfController struct { Controller } func (this *ProfController) Get() { switch this.Ctx.Params[":pp"] { default: pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request) case "": pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request) case "cmdline": pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request) case "profile": pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request) case "symbol": pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request) } this.Ctx.ResponseWriter.WriteHeader(200) } ~~~ ## [](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/14.6.md#使用入門)使用入門 通過上面的設計,你可以通過如下代碼開啟pprof: ~~~ beego.PprofOn = true ~~~ 然后你就可以在瀏覽器中打開如下URL就看到如下界面:?[![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.6.pprof.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.6.pprof.png?raw=true) 圖14.7 系統當前goroutine、heap、thread信息 點擊goroutine我們可以看到很多詳細的信息: [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.6.pprof2.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.6.pprof2.png?raw=true) 圖14.8 顯示當前goroutine的詳細信息 我們還可以通過命令行獲取更多詳細的信息 ~~~ go tool pprof http://localhost:8080/debug/pprof/profile ~~~ 這時候程序就會進入30秒的profile收集時間,在這段時間內拼命刷新瀏覽器上的頁面,盡量讓cpu占用性能產生數據。 ~~~ (pprof) top10 Total: 3 samples 1 33.3% 33.3% 1 33.3% MHeap_AllocLocked 1 33.3% 66.7% 1 33.3% os/exec.(*Cmd).closeDescriptors 1 33.3% 100.0% 1 33.3% runtime.sigprocmask 0 0.0% 100.0% 1 33.3% MCentral_Grow 0 0.0% 100.0% 2 66.7% main.Compile 0 0.0% 100.0% 2 66.7% main.compile 0 0.0% 100.0% 2 66.7% main.run 0 0.0% 100.0% 1 33.3% makeslice1 0 0.0% 100.0% 2 66.7% net/http.(*ServeMux).ServeHTTP 0 0.0% 100.0% 2 66.7% net/http.(*conn).serve (pprof)web ~~~ [![](https://github.com/astaxie/build-web-application-with-golang/raw/master/zh/images/14.6.pprof3.png?raw=true)](https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/images/14.6.pprof3.png?raw=true) 圖14.9 展示的執行流程信息
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看