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

相关推荐
JavaPub1 分钟前
Ontology 本体论是什么?从哲学概念到 AI、知识图谱与软件工程
后端
PPPPickup1 分钟前
基础知识差缺补漏-面试版持续更新
java·开发语言
liuxiaocheng5 分钟前
聊聊 Vercel AI SDK 的流式协议:前后端到底是怎么"边想边说"的
前端·后端
得物技术17 分钟前
得物知识问答:复合检索 Agent 的系统设计实践
人工智能·后端·ai编程
兔兔兔兔125 分钟前
记录C++ 3
开发语言·c++
andongni20327 分钟前
SpringBoot 入门实验报告
java·spring boot·后端
黄鸭部落格ShiYuYuanFang28 分钟前
【分享】软考每日一练与解析-计组 8/12
java·开发语言
m0_6174939429 分钟前
Python 使用 cryptography 实现数据加密与解密
开发语言·python
大白同学42133 分钟前
初始Qt——了解Qt背景
开发语言·qt
李广坤42 分钟前
Agent 记忆系统详解:从"金鱼脑"到"过目不忘"的进化之路
后端