### Install pprof-analyzer-mcp using Go Install Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Installs the pprof-analyzer-mcp executable into the Go bin directory using 'go install'. This allows running the command directly if the bin directory is in the system's PATH. Supports installation via module path or GitHub path. ```bash # Installs the executable using the module path defined in go.mod go install . # Or directly using the GitHub path (recommended after publishing) # go install github.com/ZephyrDeng/pprof-analyzer-mcp@latest ``` -------------------------------- ### Install pprof-analyzer-mcp Go Tool Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Installs the pprof-analyzer-mcp executable using 'go install'. This command places the executable in your Go bin directory, making it available in your system's PATH. ```bash go install github.com/ZephyrDeng/pprof-analyzer-mcp@latest ``` -------------------------------- ### Install Graphviz on Windows Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Install Graphviz on Windows using the Chocolatey package manager. This ensures the `dot` command is available for generating SVG flame graphs. ```bash choco install graphviz ``` -------------------------------- ### Install Graphviz on Debian/Ubuntu Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Install Graphviz on Debian or Ubuntu-based systems using apt-get. This is necessary for generating SVG flame graphs with the `generate_flamegraph` tool. ```bash sudo apt-get update && sudo apt-get install graphviz ``` -------------------------------- ### Run Memory Leak Detector Command Line Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md Executes the memory leak detection tool using command-line arguments. It requires paths to two pprof heap profiles (old and new) and specifies thresholds for growth percentage and the number of top leaks to report. This is a common way to initiate the analysis. ```go go run test_memory_leak_detector.go -old=heap_before.pprof -new=heap_after.pprof -threshold=0.05 -limit=10 ``` -------------------------------- ### Install Graphviz on CentOS/Fedora Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Install Graphviz on CentOS or Fedora systems using yum or dnf. This dependency is required for the `generate_flamegraph` tool to create SVG flame graphs. ```bash sudo yum install graphviz # 或者 sudo dnf install graphviz ``` -------------------------------- ### Example Go Program for Memory Leak Simulation Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md This Go program is designed to simulate a memory leak by continuously appending strings to a global slice, preventing them from being garbage collected. It generates two heap profiles (`heap_before.pprof` and `heap_after.pprof`) at different stages, which can then be used by the memory leak detection tool. Ensure `runtime.MemProfileRate` is set appropriately for detailed profiling. ```go package main import ( "fmt" os" runtime" runtime/pprof" time" ) // Global variable to prevent garbage collection var leakySlice []string func main() { // Enable memory profiling runtime.MemProfileRate = 1 // Create first heap profile (before leak) f1, _ := os.Create("heap_before.pprof") runtime.GC() // Force garbage collection pprof.WriteHeapProfile(f1) f1.Close() // Create some "leaky" allocations for i := 0; i < 10000; i++ { leakySlice = append(leakySlice, fmt.Sprintf("This is a string that will not be garbage collected: %d", i)) } // Wait a moment to ensure memory operations complete time.Sleep(1 * time.Second) // Create second heap profile (after leak) f2, _ := os.Create("heap_after.pprof") runtime.GC() // Force garbage collection pprof.WriteHeapProfile(f2) f2.Close() fmt.Println("Heap profiles created: heap_before.pprof and heap_after.pprof") } ``` -------------------------------- ### Install Graphviz on macOS Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Install Graphviz on macOS using the Homebrew package manager. This dependency is required for the `generate_flamegraph` tool to create SVG flame graphs. ```bash brew install graphviz ``` -------------------------------- ### Generate Heap Profiles with `runtime/pprof` in Go Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md This Go code snippet demonstrates how to generate heap profiles at different points in time within an application using the `runtime/pprof` package. It's essential for capturing the memory state before and after a potential leak. Ensure necessary imports are included. ```go package main import ( "os" runtime/pprof // other imports ) func main() { // Start your application // Generate first heap profile (before potential leak) f1, _ := os.Create("heap_before.pprof") pprof.WriteHeapProfile(f1) f1.Close() // Run your application for some time // ... // Generate second heap profile (after potential leak) f2, _ := os.Create("heap_after.pprof") pprof.WriteHeapProfile(f2) f2.Close() } ``` -------------------------------- ### Generate Heap Profiles with `go tool pprof` for Running Process Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md This bash snippet illustrates how to interact with a running Go process's pprof endpoint using `go tool pprof`. It guides you through fetching heap profiles, saving them in protocol buffer format, and exiting the tool. This method is useful for profiling processes that may not expose a direct HTTP endpoint for downloads. ```bash # First profile go tool pprof -inuse_space http://localhost:6060/debug/pprof/heap # At the pprof prompt, type: # > proto > heap_before.pprof # > quit # Wait some time... # Second profile go tool pprof -inuse_space http://localhost:6060/debug/pprof/heap # At the pprof prompt, type: # > proto > heap_after.pprof # > quit ``` -------------------------------- ### Install Graphviz on CentOS/Fedora Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Installs the Graphviz dependency on CentOS or Fedora systems using yum or dnf package managers. Graphviz is required for generating SVG flame graphs. ```bash sudo yum install graphviz # or sudo dnf install graphviz ``` -------------------------------- ### Fetch Heap Profiles via HTTP pprof Endpoint Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md This bash script shows how to retrieve heap profiles from a running Go application's pprof HTTP endpoint. It uses `curl` to fetch the `/debug/pprof/heap` resource, saving the profiles to files for later analysis. Make sure the application is accessible at the specified address and port. ```bash # First profile curl -s http://localhost:6060/debug/pprof/heap > heap_before.pprof # Wait some time... # Second profile curl -s http://localhost:6060/debug/pprof/heap > heap_after.pprof ``` -------------------------------- ### Detect Memory Leaks via MCP Server Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md Use the `detect_memory_leaks` tool via the MCP server by providing URIs to two heap profiles and setting a growth threshold and result limit. ```APIDOC ## POST /tools/detect_memory_leaks ### Description Analyzes two heap profiles to detect memory leaks. It identifies memory allocations that have grown significantly between the two profiles. ### Method POST ### Endpoint /tools/detect_memory_leaks ### Parameters #### Request Body - **tool_name** (string) - Required - Must be `"detect_memory_leaks"`. - **arguments** (object) - Required - Contains the arguments for the leak detection tool. - **old_profile_uri** (string) - Required - URI to the earlier heap profile (supports `file://`, `http://`, `https://`). - **new_profile_uri** (string) - Required - URI to the later heap profile (supports `file://`, `http://`, `https://`). - **threshold** (float) - Optional - Growth threshold as a decimal (e.g., 0.05 for 5%). Defaults to a sensible value if not provided. - **limit** (integer) - Optional - Maximum number of results to show. Defaults to a sensible value if not provided. ### Request Example ```json { "tool_name": "detect_memory_leaks", "arguments": { "old_profile_uri": "file:///path/to/your/heap_before.pprof", "new_profile_uri": "file:///path/to/your/heap_after.pprof", "threshold": 0.05, "limit": 15 } } ``` ### Response #### Success Response (200) - **result** (object) - Contains the detected memory leak information. - **leaks** (array) - A list of detected memory leaks. - **name** (string) - The name of the memory allocation type. - **absolute_growth** (integer) - Absolute memory growth in bytes. - **percentage_growth** (float) - Percentage growth. - **object_count_growth** (integer) - Growth in the number of objects. - **average_object_size** (integer) - Average size of the objects in bytes. #### Response Example ```json { "result": { "leaks": [ { "name": "[]string", "absolute_growth": 102400, "percentage_growth": 0.15, "object_count_growth": 100, "average_object_size": 1024 } ] } } ``` ``` -------------------------------- ### Commit Changes using Conventional Commits Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Commits changes to the repository using the Conventional Commits format. This format is important for automated changelog generation during the release process. Examples include 'feat:' for new features and 'fix:' for bug fixes. ```bash git add . git commit -m "feat: Add awesome new feature" # or git commit -m "fix: Resolve issue #42" ``` -------------------------------- ### Detect Memory Leaks using MCP Server JSON Configuration Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/docs/memory_leak_detection.md This JSON object defines the configuration for the `detect_memory_leaks` tool within the pprof-analyzer-mcp's MCP server. It specifies the URIs for the old and new heap profiles, a growth threshold, and a limit for the number of results. Ensure the URIs are accessible and the threshold/limit values are appropriate for your analysis. ```json { "tool_name": "detect_memory_leaks", "arguments": { "old_profile_uri": "file:///path/to/your/heap_before.pprof", "new_profile_uri": "file:///path/to/your/heap_after.pprof", "threshold": 0.05, // 5% growth threshold "limit": 15 // Show top 15 potential leaks } } ``` -------------------------------- ### Build pprof-analyzer-mcp from Source Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Builds the pprof-analyzer-mcp executable from source code using the Go toolchain. Requires Go 1.18 or higher. Generates an executable in the current directory. ```bash go build ``` -------------------------------- ### Create and Push Git Tag for Release Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md To initiate the automated release process, create a new Git tag following the 'v*' pattern and push it to GitHub. This action triggers the GoReleaser workflow. ```bash # 示例:创建标签 v0.1.0 git tag v0.1.0 # 推送标签到 GitHub git push origin v0.1.0 ``` -------------------------------- ### Build Docker Image for pprof-analyzer-mcp Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Builds a Docker image tagged as 'pprof-analyzer-mcp' from the Dockerfile in the project root. This image bundles the application and its dependencies, including Graphviz. ```bash docker build -t pprof-analyzer-mcp . ``` -------------------------------- ### Run All Tests with Go Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/tests/README.md Executes all tests within the tests directory of the pprof-analyzer-mcp project using the Go testing framework. This command is useful for a comprehensive test run before committing changes or for CI/CD pipelines. ```bash go test -v ./tests/... ``` -------------------------------- ### Create and Push Git Tag for Release Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Creates a new Git tag (e.g., 'v0.1.0') and pushes it to the remote repository. Pushing a tag matching the 'v*' pattern triggers the automated release process via GitHub Actions and GoReleaser. ```bash # Example: Create tag v0.1.0 git tag v0.1.0 # Push the tag to GitHub git push origin v0.1.0 ``` -------------------------------- ### Generate Test Coverage Report with Go Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/tests/README.md Generates a test coverage report for the pprof-analyzer-mcp project. It first runs tests with coverage enabled, saving the output to `coverage.out`, and then uses the `go tool cover` command to generate an HTML report for visualization. ```bash go test -v -coverprofile=coverage.out ./tests/... go tool cover -html=coverage.out ``` -------------------------------- ### Analyze Online CPU Profile (from GitHub Raw URL) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a CPU profile directly from a raw GitHub URL, fetching the profile data for analysis. Top 5 results are requested. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.cpu", "profile_type": "cpu", "top_n": 5 } } ``` -------------------------------- ### Run pprof-analyzer-mcp using Docker Container Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Runs the pprof-analyzer-mcp application as a Docker container. The '-i' flag keeps STDIN open for stdio transport, and '--rm' automatically removes the container on exit. This is a convenient way to run the server with Graphviz dependency bundled. ```bash docker run -i --rm pprof-analyzer-mcp ``` -------------------------------- ### Open Interactive Pprof UI for Online CPU Profile (macOS Only) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Opens an interactive pprof UI for a CPU profile fetched from a raw GitHub URL. This feature is macOS specific. An optional HTTP address can be provided. ```json { "tool_name": "open_interactive_pprof", "arguments": { "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.cpu" // Optional: "http_address": ":8082" // Example of overriding the default port } } ``` -------------------------------- ### Configure MCP Client with JSON Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Configure your MCP client, such as VS Code's Roo Cline extension, to connect to the pprof-analyzer-mcp server using the 'stdio' transport protocol. This typically involves creating a `.roo/mcp.json` file in your project root with the specified server configuration. ```json { "mcpServers": { "pprof-analyzer": { "command": "pprof-analyzer-mcp" } } } ``` -------------------------------- ### Generate Flame Graph for Online Heap Profile (from GitHub Raw URL) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Generates a flame graph SVG for a heap profile fetched from a raw GitHub URL. The output SVG will be saved locally. ```json { "tool_name": "generate_flamegraph", "arguments": { "profile_uri": "https://raw.githubusercontent.com/google/pprof/refs/heads/main/profile/testdata/gobench.heap", "profile_type": "heap", "output_svg_path": "./online_heap_flamegraph.svg" } } ``` -------------------------------- ### Analyze CPU Profile (Text format, Top 5) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a CPU profile from a local file URI and returns the top 5 results in text format. Requires a 'cpu.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/cpu.pprof", "profile_type": "cpu" } } ``` -------------------------------- ### Run Specific Test with Go Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/tests/README.md Executes a specific test function within a given package using the Go testing framework. The `-run` flag allows targeting individual test cases, which is helpful for debugging or verifying a particular fix. ```bash go test -v ./tests/analyzer -run TestAnalyzeHeapProfile ``` -------------------------------- ### Analyze Heap Profile (Markdown format, Top 10) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a heap profile from a local file URI, returning the top 10 results in markdown format. Requires a 'heap.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/heap.pprof", "profile_type": "heap", "top_n": 10, "output_format": "markdown" } } ``` -------------------------------- ### Configure MCP Client for Dockerized pprof-analyzer-mcp Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Configures an MCP client (e.g., Roo Cline) to connect to the pprof-analyzer-mcp server running inside a Docker container. This involves specifying the Docker run command in the client's configuration file. ```json { "mcpServers": { "pprof-analyzer-docker": { "command": "docker run -i --rm pprof-analyzer-mcp" } } } ``` -------------------------------- ### Analyze Goroutine Profile (Text format, Top 5) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a goroutine profile from a local file URI and returns the top 5 results in text format. Requires a 'goroutine.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/goroutine.pprof", "profile_type": "goroutine" } } ``` -------------------------------- ### Generate Flame Graph for CPU Profile Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Generates a flame graph SVG file for a CPU profile from a local file URI. Requires a 'cpu.pprof' file and a path to save the output SVG. ```json { "tool_name": "generate_flamegraph", "arguments": { "profile_uri": "file:///path/to/your/cpu.pprof", "profile_type": "cpu", "output_svg_path": "/path/to/save/cpu_flamegraph.svg" } } ``` -------------------------------- ### Analyze CPU Profile (JSON format, Top 3) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a CPU profile from a local file URI and returns the top 3 results in JSON format. Requires a 'cpu.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/cpu.pprof", "profile_type": "cpu", "top_n": 3, "output_format": "json" } } ``` -------------------------------- ### Push Changes to Main Branch Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md After committing your changes using Conventional Commits, push them to the main branch of your GitHub repository. This is a prerequisite for creating tags and triggering releases. ```bash git push origin main ``` -------------------------------- ### Analyze CPU Profile (Default Flame Graph JSON format) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a CPU profile from a local file URI using the default 'flamegraph-json' output format. Requires a 'cpu.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/cpu.pprof", "profile_type": "cpu" // output_format defaults to "flamegraph-json" } } ``` -------------------------------- ### Generate Flame Graph for Heap Profile (inuse_space) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Generates a flame graph SVG file for a heap profile from a local file URI. Requires a 'heap.pprof' file and a path to save the output SVG. ```json { "tool_name": "generate_flamegraph", "arguments": { "profile_uri": "file:///path/to/your/heap.pprof", "profile_type": "heap", "output_svg_path": "/path/to/save/heap_flamegraph.svg" } } ``` -------------------------------- ### Analyze Heap Profile (Explicitly Flame Graph JSON format) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a heap profile from a local file URI and explicitly sets the output format to 'flamegraph-json'. Requires a 'heap.pprof' file. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "file:///path/to/your/heap.pprof", "profile_type": "heap", "output_format": "flamegraph-json" } } ``` -------------------------------- ### Analyze Remote CPU Profile (from HTTP URL) Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Analyzes a CPU profile from an HTTP URL. The profile data will be fetched from the provided URI. ```json { "tool_name": "analyze_pprof", "arguments": { "profile_uri": "https://example.com/profiles/cpu.pprof", "profile_type": "cpu" } } ``` -------------------------------- ### Commit Changes for Release Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README_zh-CN.md Committing changes using Conventional Commits format is crucial for automated changelog generation. Ensure your commit messages follow the specified patterns like 'feat: ...' or 'fix: ...'. ```bash git add . git commit -m "feat: 添加了很棒的新功能" # 或者 git commit -m "fix: 解决了问题 #42" ``` -------------------------------- ### Disconnect a Pprof Session Source: https://github.com/zephyrdeng/pprof-analyzer-mcp/blob/main/README.md Disconnects an active pprof session using its process ID (PID). The PID is typically obtained from a previous 'open_interactive_pprof' command. ```json { "tool_name": "disconnect_pprof_session", "arguments": { "pid": 12345 // Replace 12345 with the actual PID returned by open_interactive_pprof } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.