pprof 查看goroutine

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 @ 0x147d9 0x1485b 0x1dcf8 0x1de28 0x203c 0x14a70
#	0x1dcf8	chanrecv+0x4e8		/private/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/makerelease054730537/go/src/pkg/runtime/chan.goc:268
#	0x1de28	runtime.chanrecv1+0x38	/private/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/makerelease054730537/go/src/pkg/runtime/chan.goc:352

  

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

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

 

转载于:https://www.cnblogs.com/wangxusummer/p/4054564.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值