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

相关推荐
小的~~11 分钟前
ThreadLocal 、InheritableThreadLocal 与 TransmittableThreadLocal 的进阶指南
java·开发语言
运维开发笔记11 分钟前
3.1 Go if 语句学习笔记
golang
键盘会跳舞18 分钟前
C++:std::pair 源码级深度剖析 —— 关联容器的基石
开发语言·c++·pair·关联容器
(Charon)21 分钟前
【C++】手写线程安全队列:mutex + condition_variable 实现生产者消费者模型
c语言·开发语言·c++
AINative软件工程27 分钟前
LLM 应用的 Feature Flag 工程实践:Prompt、模型与 AI 行为的生产安全灰度
后端·llm·ai编程
崖边看雾28 分钟前
同步上下文管理器规则
开发语言·数据库
weixin_4316004442 分钟前
前端对接 SSE 的两种常见方式
前端·后端·学习·ai·sse·nest.js
Larcher7 小时前
React Router 不只是页面跳转:从 SPA 路由到权限守卫的完整实践
javascript·后端
Larcher7 小时前
大模型为什么每次回答都不一样?一文搞懂 Temperature、Top K 与 Top P
javascript·后端
名字还没想好☜9 小时前
Python f-string 进阶:数字格式化、对齐填充、调试 = 号与嵌套表达式
开发语言·数据库·python·字符串格式化·f-string