嗜睡分析器MCP服务器
专业的MCP(模型上下文协议)服务器,用于分析非常困倦的CPU配置文件(.spirity文件)。用40年的资深工程智慧打造。
🎯 目的
此MCP服务器使AI助手(如Claude)能够对CPU配置文件进行深入的性能分析,快速识别瓶颈和性能问题,而无需手动检查。
🏗️ 建筑
verysleepy-mcp/
├── cmd/
│ └── server/ # MCP server entry point
│ └── main.go
├── internal/
│ ├── sleepy/ # Core profile parsing (no external dependencies)
│ │ ├── types.go # Data structures
│ │ └── parser.go # .sleepy file parser
│ └── analyzer/ # Performance analysis algorithms
│ ├── hotspots.go # Hotspot detection
│ └── statistics.go # Statistical analysis
└── tools/ # MCP tool implementations
├── load_profile.go
├── find_hotspots.go
├── find_bottom_functions.go
├── analyze_modules.go
├── detect_issues.go
├── get_statistics.go
└── view_callstack.go设计原则
- 关注点分离:核心解析逻辑与分析逻辑隔离
- 核心没有外部依赖关系:解析器仅使用stdlib
- 缓存:缓存加载的配置文件以提高效率
- 演出:O(n)算法(如果可能),O(n log n)用于排序
- 可测试性:每个组件都可以独立测试
🛠️ 可用工具
1. load_profile
目的:加载并验证.spirity配置文件
参数:
file_path(string):.spirity文件的绝对路径
输出:配置文件元数据(持续时间、样本、调用堆栈等)
用例:在使用其他工具之前,始终先调用此命令
______________________________________________________________________
2. find_hotspots 🔥
目的:识别占用CPU时间最多的功能
参数:
file_path(string):加载配置文件的路径top_n(number):要返回的热点数量(默认值:10)
输出:功能排名表,包括:
- 总消耗时间
- 执行时间百分比
- 样本计数
- 源文件位置
用例: 从这里开始! 这是您查找优化内容的主要工具。
______________________________________________________________________
3. find_bottom_functions 🎯
目的:查找叶子函数(实际CPU工作发生的地方)
参数:
file_path(string):加载配置文件的路径top_n(number):要返回的函数数(默认值:10)
输出:叶子函数的排序列表
用例:识别热点后,使用此功能查找要优化的实际CPU密集型操作。这些是调用栈底部的函数,它们执行实际工作。
______________________________________________________________________
4. analyze_modules 📦
目的:按模块/库细分时间消耗
参数:
file_path(string):加载配置文件的路径
输出:模块级时间细分,带百分比和视觉条
用例:确定哪些组件或第三方库正在消耗资源。对架构决策有用。
______________________________________________________________________
5. detect_performance_issues ⚠️
目的:基于启发式的自动问题检测
参数:
file_path(string):加载配置文件的路径
输出:问题分类列表(严重、高、中、低),包括:
- 问题类型(CPU热点、热循环、深度调用堆栈等)
- 影响百分比
- 受影响的功能
用例:快速分流-运行此程序以获取所有问题的摘要。很好的分析起点。
检测启发式:
- 耗时>20%的功能→ 关键的
- 耗时>10%的功能→ High
- 堆叠深度>50帧→ 深度递归警告
- 80%以上的调用堆栈中的函数→ 热回路
______________________________________________________________________
6. get_statistics 📊
目的:获取全面的个人资料统计数据
参数:
file_path(string):加载配置文件的路径
输出:
- 总执行时间
- 调用堆栈计数和深度统计
- 独特的模块/功能计数
用例:获取轮廓特征概述。有助于理解配置文件范围。
______________________________________________________________________
7. view_callstack 📞
目的:查看包含已解析符号的详细调用堆栈
参数:
file_path(string):加载配置文件的路径callstack_index(数字):调用堆栈索引(从1开始)
输出:使用以下命令完成从叶到根的调用堆栈:
- 函数名
- 模块名称
- 震源位置
- 存储器地址
用例:深入了解具体的执行路径。当你知道要调查哪个调用堆栈时很有用。
🚀 快速开始
构建
cd verysleepy-mcp
go build -o verysleepy-mcp.exe ./cmd/server使用Claude Desktop进行配置
添加到您的Claude桌面配置(claude_desktop_config.json):
{
"mcpServers": {
"verysleepy-profiler": {
"command": "C:\\Users\\Admin\\Desktop\\Dev\\verySleepy\\verysleepy-mcp\\verysleepy-mcp.exe"
}
}
}用法示例
- 加载配置文件:
load_profile with file_path: "C:\path\to\profile.sleepy"- 自动检测问题:
detect_performance_issues with file_path: "C:\path\to\profile.sleepy"- 查找热门热点:
find_hotspots with file_path: "C:\path\to\profile.sleepy", top_n: 10- 分析模块分布:
analyze_modules with file_path: "C:\path\to\profile.sleepy"- 查找实际工作发生的位置:
find_bottom_functions with file_path: "C:\path\to\profile.sleepy", top_n: 10📖 分析工作流程(高级工程师方法)
第一步:装载和分类(5分钟)
1. load_profile
2. detect_performance_issues
3. get_statistics这为您提供了即时的概述,并确定了关键问题。
第二步:识别热点(10分钟)
4. find_hotspots (top 10)
5. analyze_modules了解时间花在哪里,涉及哪些组件。
第三步:深入研究(20分钟)
6. find_bottom_functions (top 10)
7. view_callstack (for interesting callstacks)找到实际的函数来优化和理解执行流程。
第四步:分析模式
- Cross-reference hotspots with bottom functions
- Check if hot functions are in your code or third-party libs
- Look for unexpected patterns (deep recursion, hot loops)🧠 性能分析最佳实践
理解差异
- 热点 (
find_hotspots):出现在昂贵调用堆栈中的任何函数。可能包括框架功能、入口点等。
- 底部功能 (
find_bottom_functions):实际的CPU密集型叶函数。这些是你通常想要优化的。
示例:
Hotspot: main() - 80% of time
↓
↓ (calls)
↓
Bottom Function: expensiveCalculation() - 80% of time两者都显示80%,但你想优化 expensiveCalculation(),不 main().
常见模式
- 热循环:在>80%的调用堆栈中具有相同的功能
- 修复:优化循环体或减少迭代次数
- 昂贵的图书馆电话:堆栈底部的第三方功能
- 修复:缓存结果、使用更快的替代方案或减少调用
- 深度游览:堆叠深度>50
- 修复:转换为迭代或添加记忆
- 系统调用开销:许多小型系统/API调用
- 修复:批量操作
🔍 示例分析会话
=== Profile: game.sleepy ===
1. load_profile
→ 2.5s total, 1539 samples, 250 functions
2. detect_performance_issues
→ Critical: Physics::Update (35% of time)
→ High: Renderer::DrawSprites (18% of time)
→ Hot Loop: Vector3::Normalize (appears in 92% of callstacks)
3. find_hotspots (top 5)
#1: Physics::Update (35%)
#2: Renderer::DrawSprites (18%)
#3: GameObject::Update (12%)
#4: Vector3::Normalize (10%)
#5: MemoryManager::Alloc (8%)
4. find_bottom_functions (top 5)
#1: Vector3::Normalize (28%) ← Real bottleneck!
#2: sin() from msvcrt (12%)
#3: malloc() (10%)
#4: RenderSprite() (8%)
#5: CollisionCheck() (6%)
5. Conclusion:
- Vector3::Normalize is the real problem (called in hot loop)
- Physics is expensive due to Vector3 operations and sin() calls
- Rendering has memory allocation overhead (malloc in hot path)
6. Action Items:
- Cache normalized vectors instead of recomputing
- Pre-compute sin/cos in lookup table
- Use memory pool instead of malloc in render path📁 文件格式支持
支持极度嗜睡 .sleepy 文件(包含ZIP存档):
Stats.txt-配置文件元数据Symbols.txt-符号表(地址→ 函数映射)Callstacks.txt-捕获的通话记录Threads.txt-线程信息(可选)IPCounts.txt-指令指针计数(可选)
🤝 贡献
此服务器遵循专业软件工程实践:
- 干净的建筑,清晰的分隔
- 全面的错误处理
- 性能优化算法
- 文档化良好的代码
- 高级代码质量
📝 许可证
专为Very Sleepy Profiler分析自动化而创建。
______________________________________________________________________
用40年的智慧构建:测量、分析、优化。永远不要猜。
