首页 > 其他 > 详细

pprof 查看goroutine

时间:2014-10-27 17:15:28      阅读:170      评论:0      收藏:0      [点我收藏+]
package main

import (
  "net/http"
  "runtime/pprof"
)

var quit chan struct{} = make(chan struct{})

func f() {
  <-quit
}

func handler(w http.ResponseWriter, r *http.Request) {
  w.Header().Set("Content-Type", "text/plain")

  p := pprof.Lookup("goroutine")
  p.WriteTo(w, 1)
}

func main() {
  for i := 0; i < 10000; i++ {
    go f()
  }

  http.HandleFunc("/", handler)
  http.ListenAndServe(":11181", nil)
}

 

这上面的例子中,我们启动了10000个goroutine,并阻塞,然后通过访问http://localhost:11181/,我们就可以得到整个goroutine的信息,仅列出关键信息:

goroutine profile: total 10004

10000 @ 0x186f6 0x616b 0x6298 0x2033 0x188c0
#0x2033  main.f+0x33 /Users/siddontang/test/pprof.go:11

  

可以看到,在main.f这个函数中,有10000个goroutine正在执行

转自:http://www.tuicool.com/articles/VBFNNfA

 

pprof 查看goroutine

原文:http://www.cnblogs.com/wangxusummer/p/4054564.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!