返回 MCP 目录
public公开dns本地运行

Go pprof Analyzer

一个基于Go的MCP服务器,提供分析Go性能剖析文件(pprof)的工具,支持多种分析类型和输出格式。

article

README

🚀 使用简体中文运行 PProf 的 Docker 容器

本项目提供了一个使用 Docker 容器运行 PProf 的解决方案,帮助开发者方便地进行性能剖析和分析。

🚀 快速开始

启动步骤

  1. 拉取 PProf 镜像
docker pull dockerhub.schaefer.name/pprof:latest-amd64
  1. 创建配置文件 pprof-config.yaml
address: ":8080"
pprofs:
  - name: "Heap profile"
    pattern: ".*\.heap"
    contentTypes: ["application/octet-stream"]
    subProcessProfile: true
    type: "heap"
  - name: "CPU profile"
    pattern: ".*\.cpu"
    contentTypes: ["text/plain"]
    type: "cpu"
  - name: "Goroutine profile"
    pattern: ".*\.goroutine"
    contentTypes: ["text/plain"]
    type: "goroutine"
  1. 启动 PProf 容器
docker run -d --name pprof -p 8080:8080 -v $(pwd)/pprof-config.yaml:/etc/pprof/config.yaml dockerhub.schaefer.name/pprof:latest-amd64
  1. 访问 PProf 的 Web 界面
# 在浏览器访问 http://<your-docker-host>:8080 或者 http://localhost:8080 如果在本机运行

📦 安装指南

将项目代码与 PProf 集成

  1. 在你的 Go 项目中添加以下代码进行性能剖析
import (
	"fmt"
	"log"
	"net/http"
	
	"github.com/google/pprof/agent"
)

func main() {
	log.Println("Starting application on port 8081")
	http.HandleFunc("/", handler)
	http.ListenAndServe(":8081", nil)
}

func handler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == "/debug/pprof" {
		w.Header().Set("Content-Type", "application/octet-stream")
		agent.Profile(r.Context(), w, agent.MainArgs{})
		return
	}
	fmt.Fprintf(w, "Hello, World!")
}
  1. 使用 curl 启动分析
# 分析 CPU 文件
curl -X POST http://localhost:8080/pprof/upload -F "file=@./testdata/gobench.cpu"

# 开启交互式 PProf UI(仅限 macOS)
curl -X POST http://localhost:8080/pprof/debug \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"address":"http://localhost:8081/debug/pprof/"}'

💻 使用示例

基础用法

分析本地 CPU 剖析文件

{
	"tool_name": "analyze_pprof",
	"arguments": {
		"profile_path": "./testdata/gobench.cpu",
		"type": "cpu"
	}
}

生成火焰图

{
	"tool_name": "generate_flamegraph",
	"arguments": {
		"profile_path": "./testdata/gobench.cpu",
		"output_path": "./flame-graph.svg"
	}
}

📚 详细文档

发布说明

版本更新日志

v0.1.2 (2023-05-26)
  • 修复了火焰图生成中的内存泄漏问题
  • 提高了剖析文件解析的效率
  • 支持 goroutine 剖析的子进程模式
  • 新增了基于时间戳的剖析文件命名规则

已知问题

  • 不支持分析非常大的剖析文件(超过 1GB)
  • 在处理某些特定类型的剖析数据时可能会出现延迟

使用说明

请确保在运行 PProf 容器之前已经拉取最新的镜像,并正确配置您的应用程序以生成相应的剖析文件。如遇问题,请参考官方文档或联系技术支持。

🚧 未来改进计划

  1. 支持更多类型的剖析文件
  2. 提供基于 Web 的交互式分析界面
  3. 增加对多线程和异步应用的支持
  4. 优化内存使用效率
  5. 新增结果导出功能
即贴即用配置

MCP 客户端配置生成器

选择客户端,补齐所需环境变量,再复制根据当前 MCP 公开配置生成的完整文件

terminal
check无需填写环境变量,可以直接复制
Claude Desktop
{
  "mcpServers": {
    "pprof-analyzer-docker": {
      "command": "docker run -i --rm pprof-analyzer-mcp"
    }
  }
}
建议保存到claude_desktop_config.json
help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端