当前位置: 首页 > news >正文

米东区做网站一级域名好还是二级域名好

米东区做网站,一级域名好还是二级域名好,长沙营销型网站建设,男做变态手术视频网站pprof是Go语言内置的性能分析工具,它可以帮助我们分析程序的CPU使用情况、内存分配等。 pprof 包含两部分: Go语言内置的两个包 net/http/pprof 对 runtime/pprof 的二次封装,一般是服务型应用。比如 web server ,它一直运行。这…

pprof是Go语言内置的性能分析工具,它可以帮助我们分析程序的CPU使用情况、内存分配等。

pprof 包含两部分:

  • Go语言内置的两个包

    1. net/http/pprof

      runtime/pprof 的二次封装,一般是服务型应用。比如 web server ,它一直运行。这个包对提供的 http 服务进行数据采集分析。

    2. runtime/pprof

      采集程序运行数据进行性能分析,一般用于后台工具型应用,这种应用运行一段时间就结束。

  • 性能剖析工具 go tool pprof

性能分析指标

  1. CPU性能分析
  2. 内存(Memory)性能分析
  3. 阻塞(block)性能分析
  4. 锁(mutex)性能分析

内置包应用

runtime/pprof

cpu分析

关键

// 开启 cpu 采集分析:
pprof.StartCPUProfile(w io.Writer)// 停止 cpu 采集分析:
pprof.StopCPUProfile()

demo

package mainimport ("log""os""runtime/pprof"
)func main() {f, err := os.OpenFile("cpu.pprof", os.O_CREATE|os.O_RDWR, 0644)if err != nil {log.Fatalf("Failed to open profile file: %v", err)return}if err = pprof.StartCPUProfile(f); err != nil {log.Fatalf("Failed to start CPU profiling: %v", err)return}defer pprof.StopCPUProfile()// do something
}

内存分析

关键

pprof.WriteHeapProfile(w io.Writer)

demo

func captureHeapProfile(filename string) error {// 打开文件,用于存储堆内存信息file, err := os.Create(filename)if err != nil {return err}defer file.Close()// 写入堆内存信息if err = pprof.WriteHeapProfile(file); err != nil {return err}return nil
}
net/http/pprof

对于服务类型的应用,主要在服务内部匿名引入net/http/pprof包,然后通过HTTP访问pprof页面。
匿名引入方式为:import _ "net/http/pprof"

package mainimport ("fmt""net/http"_ "net/http/pprof"
)func main() {http.HandleFunc("/", hello)err := http.ListenAndServe(":8080", nil)if err != nil {fmt.Println("ListenAndServe Err:", err.Error())return}
}func hello(resp http.ResponseWriter, req *http.Request) {fmt.Fprintln(resp, "Hello World, Are You OK?")
}

浏览器打开 http://localhost:8080/debug/pprof/

如果HTTP服务不是通过http.ListenAndServe(":8080", nil)启动的,需要自己注册pprof路由

net/http/pprof包中,有init函数

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

如果使用自定义的ServeMux,则需要增加注册后,才能获取到pprof

// 自己注册这几个函数
r.HandleFunc("/debug/pprof/", pprof.Index)
r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
r.HandleFunc("/debug/pprof/profile", pprof.Profile)
r.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
r.HandleFunc("/debug/pprof/trace", pprof.Trace)

go tool pprof

命令格式:

pprof <format> [options] [binary] <source>
pprof [options] [binary] <source>
pprof -http [host]:[port] [options] [binary] <source>

想在浏览器查看,需要安装graphviz

web页面模式

go tool pprof -http=:6666 [file_pprof|url_pprof]

go tool pprof -http=:9999 cpu.pprof
go tool pprof -http=:9999 mem.pprof
命令行模式

go tool pprof [file_pprof|url_pprof]

常用:

go tool pprof -http=:9999 cpu.pprof
go tool pprof -http=:9999 /tmp/profile215959616/mem.pprof
go test -bench="Fib$" -cpuprofile=cpu.pprof .
go tool pprof -text cpu.pprof

https://blog.csdn.net/sinat_24985411/article/details/128816228

https://www.cnblogs.com/jiujuan/p/14588185.html

https://github.com/google/pprof/blob/main/doc/README.md

https://pkg.go.dev/runtime/pprof#hdr-Profiling_a_Go_program

https://www.cnblogs.com/jiujuan/p/14588185.html

http://www.yidumall.com/news/16509.html

相关文章:

  • 电信cn2线路福州排名seo公司
  • 免费做网站的问题企业培训方案
  • 企业网站建设 制作佛山网站建设工作
  • 设置网站维护页面网络营销总结
  • 上海市建设工程 安全协会网站网络营销的常用方法
  • 怎么做纪念网站网络营销推广公司名称
  • 唐山建网站百度客服联系方式
  • 道滘做网站百度权重什么意思
  • 旅游网站设计思路百度收录站长工具
  • 做电子元器件销售什么网站好重庆网站排名
  • 建设思想政治教育专题网站网站搜索优化找哪家
  • bs模式网站开发天津海外seo
  • 乌海建设局网站网易游戏推广代理加盟
  • 如何制作属于自己的网页seo好学吗入门怎么学
  • 邢台地区网站建设售后完善营销
  • wordpress美化版seo查询爱站
  • visual studio2005做网站超级外链工具 增加外链中
  • 基础很差去公司做网站东营优化公司
  • 天津高端网站建设网站统计数据
  • 东莞建设有限公司关键词优化排名软件案例
  • 一互联网网站design上海网站营销推广
  • 顺义顺德网站建设精品成品网站1688
  • 西安人才网官网搜索引擎优化服务
  • 重庆高端网站建设价格安卓手机优化软件排名
  • 搭建网站的空间哪里买地推拉新app推广接单平台免费
  • 传媒公司属于诈骗吗宁波好的seo外包公司
  • 北京市网站公司网站google搜索引擎入口2022
  • 做数据分析网站企业网站建设公司
  • wp网站搬家教程方法seo
  • 做一张网页需要多少钱武汉seo技术