【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/

相关推荐
房西杭3 分钟前
背包<->仓库转移接口(BagMgr + StoreMgr,Lua)
后端
tntxia6 分钟前
设计模式中模板方法的钩子使用
后端
我的div丢了肿么办8 分钟前
go语言对路由中的业务逻辑进行抽离
后端·go
yuniko-n9 分钟前
【JUC】内存屏障
java·开发语言
leo在掘金9 分钟前
纯Rust重写Photoshop,一个月7.2万Star
后端·架构
韩振方10 分钟前
Kubernetes 通过资源 requests 决定 Pending Pod 能否找到节点
后端
用户3600555790010 分钟前
Kestrel_VLLM - 18 · 投机解码位级对拍收口:batch 与 M=1 一致,注意力路径与 CPU 逐字节对齐
后端
Thneonl11 分钟前
git reset --hard 之后先别哭:reflog 里存着你刚弄丢的那个分支
运维·后端
Linux运维技术栈13 分钟前
近期 PHP 高危安全风险排查与多环境升级实操
开发语言·安全·php
弦儿15 分钟前
后端 Web 实战:员工管理模块(多表关系 + 多表查询 + 分页查询 + 条件分页)
后端·sql