【go-工具】pprof

pprof是什么

参考:https://wxsm.space/2023/go-pprof-note/

参考:https://juejin.cn/post/6961301143285104653

怎么用
复制代码
package main

import (
	"log"
	"net/http"
	_ "net/http/pprof"
	"time"
)

func work(w http.ResponseWriter, r *http.Request) {
	start := time.Now()
	result := 0
	for i := 0; i < 100000000; i++ {
		result += i
	}
	duration := time.Since(start)
	log.Printf("Done in %v. Result: %d", duration, result)
	w.Write([]byte("Done"))
}

func main() {
	http.HandleFunc("/work", work)
	log.Println("Server is starting...")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
  • _ "net/http/pprof"
    • 添加这个之后,会调用pprof的init函数

访问:http://localhost:8080/debug/pprof/

相关推荐
老毛肚几秒前
Spring源码探究1.0
java·后端·spring
txinyu的博客几秒前
结合STL,服务器项目解析vetcor map unordered_map
开发语言·c++
北京地铁1号线1 分钟前
1.1 文档解析:PDF/Word/HTML的结构化提取
开发语言·知识图谱·文档解析
源代码•宸3 分钟前
Golang原理剖析(程序初始化、数据结构string)
开发语言·数据结构·经验分享·后端·golang·string·init
忆锦紫11 分钟前
图像增强算法:对比度增强算法以及MATLAB实现
开发语言·图像处理·matlab
m0_7482500314 分钟前
C++ Web 编程
开发语言·前端·c++
小鸡脚来咯17 分钟前
RESTful API 面试详解
后端·面试·restful
4***175418 分钟前
Python酷库之旅-第三方库Pandas(051)
开发语言·python·pandas
吴巴格19 分钟前
springboot引用其他中间件,如何确定版本
spring boot·后端·中间件