Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-*.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating user timing marks.
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "cpu-profile-analysis" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/vscode/main/.github/skills/cpu-profile-analysis/SKILL.md 2. 保存为 ~/.claude/skills/cpu-profile-analysis/SKILL.md 3. 装好后重载技能,告诉我可以用了
Analyze .cpuprofile files (V8 sampling profiler) and DevTools trace files (Trace-*.json, Chrome Trace Event Format) to find performance bottlenecks, compare code paths, and understand timing.
.cpuprofile or Trace-*.json file and wants to understand performancecode/didResolveTextFileEditorModel (trace files).cpuprofile: Top-level JSON with nodes, samples, timeDeltas keys. Created by the VS Code profiler.Trace-*.json: Top-level JSON with traceEvents array (and optional metadata). Created by Chrome/Electron DevTools (Performance tab). These are richer than .cpuprofile -- they contain CPU samples, layout/paint events, user timing marks, GC events, input events, and multi-process data.(idle), (program), or (garbage collector) represent no user code running..cpuprofile FilesA .cpuprofile is JSON with these top-level keys:
nodes: Array of call frame nodes forming a tree (each has id, callFrame, children)samples: Array of node IDs -- one per profiler tick, referencing the leaf (innermost) frametimeDeltas: Array of microsecond deltas between consecutive samplesstartTime / endTime: Absolute timestamps in microseconds$vscode: Optional VS Code metadataProfile and trace files can exceed V8's string limit (~512MB). Always check the file size first and choose the right parsing strategy:
import { readFileSync, statSync } from 'fs';
const stat = statSync(profilePath);
const sizeMB = stat.size / (1024 * 1024);
console.log(`File size: ${sizeMB.toFixed(0)}MB`);
let data;
if (sizeMB < 400) {
// Small enough for JSON.parse
data = JSON.parse(readFileSync(profilePath, 'utf8'));
} else {
// Too large -- use Buffer-based extraction (see "Handling Huge Files" section)
data = parseProfileFromBuffer(readFileSync(profilePath));
}
For files under ~400MB, JSON.parse(readFileSync(..., 'utf8')) works fine. For larger files, see the Handling Huge Files section below.
Profiles are often single-line JSON. Reformat for inspection (only if small enough):
if (sizeMB < 400) {
const data = JSON.parse(fs.readFileSync(profilePath, 'utf8'));
fs.writeFileSync(profilePath, JSON.stringify(data, null, 2));
}
Write a Node.js analysis script. Build these structures:
// Node lookup
const nodeMap = new Map(); // id -> node
const parentMap = new Map(); // id -> parent id
// Absolute timestamps from deltas
const timestamps = [data.startTime];
for (let i = 0; i < data.timeDeltas.length; i++) {
timestamps.push(timestamps[i] + data.timeDeltas[i]);
}
// Stack walker (leaf to root)
function getStack(sampleNodeId) {
const stack = [];
let id = sampleNodeId;
while (id !== undefined) {
const node = nodeMap.get(id);
if (node) stack.push(node.callFrame.functionName);
id = parentMap.get(id);
…
帮助开发者验证 Azure DevOps 流水线改动,快速排查构建与 YAML 配置问题。
帮助开发者升级 Anthropic SDK、迁移版本并解决相关依赖与类型问题。
为 AI 编码助手生成或更新聊天定制配置文件,统一协作与开发体验
帮助开发者定位并读取 Code OSS 开发构建日志,快速排查运行与扩展问题。
将当前会话分支的修改合并回基础分支,便于整合开发成果。
帮助开发者创建和维护组件截图测试夹具,并优化组件的可测试性。