Skip to main content

A Model Context Protocol server for analyzing Perfetto trace files.

Project description

Perfetto MCP

Turn natural language into powerful Perfetto trace analysis

A Model Context Protocol (MCP) server that transforms natural-language prompts into focused Perfetto analyses. Quickly explain jank, diagnose ANRs, spot CPU hot threads, uncover lock contention, and find memory leaks – all without writing SQL.

✨ Features

  • Natural Language → SQL: Ask questions in plain English, get precise Perfetto queries
  • ANR Detection: Automatically identify and analyze Application Not Responding events
  • Performance Analysis: CPU profiling, frame jank detection, memory leak detection
  • Thread Contention: Find synchronization bottlenecks and lock contention
  • Binder Profiling: Analyze IPC performance and slow system interactions

📋 Prerequisites

  • Python 3.13+ (macOS/Homebrew):
    brew install python@3.13
    
  • uv (recommended):
    brew install uv
    

🚀 Getting Started

IDE Integration

Cursor

Add to ~/.cursor/mcp.json (global) or .cursor/mcp.json (project):

{
  "mcpServers": {
    "perfetto-mcp": {
      "command": "uvx",
      "args": ["perfetto-mcp"]
    }
  }
}
Claude Code
# Add to user scope
claude mcp add perfetto-mcp --scope user -- uvx perfetto-mcp

Or edit ~/Library/Application Support/Claude/claude.json (macOS) or %APPDATA%\Claude\claude.json (Windows):

{
  "mcpServers": {
    "perfetto-mcp": {
      "command": "uvx",
      "args": ["perfetto-mcp"]
    }
  }
}
VS Code

Add to .vscode/mcp.json (project) or run "MCP: Add Server" command:

{
  "mcpServers": {
    "perfetto-mcp": {
      "command": "uvx",
      "args": ["perfetto-mcp"]
    }
  }
}

Enable in GitHub Copilot Chat's Agent mode.

Codex

Edit ~/.codex/config.toml:

[mcp_servers.perfetto-mcp]
command = "uvx"
args = ["perfetto-mcp"]

Local Install

uvx perfetto-mcp
Using pip
pip3 install perfetto-mcp
python3 -m perfetto_mcp

📖 How to Use

Example starting prompt:

In the perfetto trace, I see that the FragmentManager is taking 438ms to execute. Can you figure out why it's taking so long?

Required Parameters

Every tool needs these two inputs:

Parameter Description Example
trace_path Absolute path to your Perfetto trace /path/to/trace.perfetto-trace
process_name Target process/app name com.example.app

In Your Prompts

Be explicit about the trace and process, prefix your prompt with:

"Use perfetto trace /absolute/path/to/trace.perfetto-trace for process com.example.app"

Optional Filters

Many tools support additional filtering (but let your LLM handle that):

  • time_range: {start_ms: 10000, end_ms: 25000}
  • Tool-specific thresholds: min_block_ms, jank_threshold_ms, limit

🛠️ Available Tools

🔎 Exploration & Discovery

Tool Purpose Example Prompt
find_slices Survey slice names and locate hot paths "Find slice names containing 'Choreographer' and show top examples"
execute_sql_query Run custom PerfettoSQL for advanced analysis "Run custom SQL to correlate threads and frames in the first 30s"

🚨 ANR Analysis

Note: Helpful if the recorded trace contains ANR

Tool Purpose Example Prompt
detect_anrs Find ANR events with severity classification "Detect ANRs in the first 10s and summarize severity"
anr_root_cause_analyzer Deep-dive ANR causes with ranked likelihood "Analyze ANR root cause around 20,000 ms and rank likely causes"

🎯 Performance Profiling

Tool Purpose Example Prompt
cpu_utilization_profiler Thread-level CPU usage and scheduling "Profile CPU usage by thread and flag the hottest threads"
main_thread_hotspot_slices Find longest-running main thread operations "List main-thread hotspots >50 ms during 10s–25s"

📱 UI Performance

Tool Purpose Example Prompt
detect_jank_frames Identify frames missing deadlines "Find janky frames above 16.67 ms and list the worst 20"
frame_performance_summary Overall frame health metrics "Summarize frame performance and report jank rate and P99 CPU time"

🔒 Concurrency & IPC

Tool Purpose Example Prompt
thread_contention_analyzer Find synchronization bottlenecks "Find lock contention between 15s–30s and show worst waits"
binder_transaction_profiler Analyze Binder IPC performance "Profile slow Binder transactions and group by server process"

💾 Memory Analysis

Tool Purpose Example Prompt
memory_leak_detector Find sustained memory growth patterns "Detect memory-leak signals over the last 60s"
heap_dominator_tree_analyzer Identify memory-hogging classes "Analyze heap dominator classes and list top offenders"

Output Format

All tools return structured JSON with:

  • Summary: High-level findings
  • Details: Tool-specific results
  • Metadata: Execution context and any fallbacks used

📚 Resources

📄 License

Apache 2.0 License. See LICENSE for details.


GitHubIssuesDocumentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perfetto_mcp-0.1.0.tar.gz (120.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perfetto_mcp-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file perfetto_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: perfetto_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 120.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for perfetto_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 806bb198a7c447089a209b933d09a5923483e587fcefa6dc32430caf9c045b7c
MD5 3f61fd8e606c6674930d47b3d8fbc738
BLAKE2b-256 1523e97e4efa95c27bf1f66c5cd73107b4112205a6d19c1c7a8a033487d0c795

See more details on using hashes here.

File details

Details for the file perfetto_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: perfetto_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for perfetto_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a49d9808b8c8b45f16f16850290e8e54262a0a20931c83791462c5a6fd491a52
MD5 a7aad0034f3d38d09fca976a43a733f2
BLAKE2b-256 c2a4e06e2ef9e15a7da0c042ff414376a18150c7c1fb2e5cb3ca03c11652527b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page