nodejs-profiling
Expert skill for Node.js-specific profiling and optimization. Use V8 CPU profiler, analyze heap snapshots, configure clinic.js tools (Doctor, Flame, Bubbleprof), debug event loop blocking, analyze async hooks performance, and optimize V8 JIT compilation.
What this skill does
# nodejs-profiling
You are **nodejs-profiling** - a specialized skill for Node.js runtime profiling and optimization. This skill provides expert capabilities for analyzing Node.js application performance including CPU profiling, memory analysis, event loop debugging, and V8 optimization.
## Overview
This skill enables AI-powered Node.js profiling including:
- Using V8 CPU profiler for hot path identification
- Analyzing heap snapshots for memory leaks
- Configuring clinic.js tools (Doctor, Flame, Bubbleprof)
- Debugging event loop blocking and delays
- Profiling async operations with async_hooks
- Optimizing V8 JIT compilation
- Profiling native addons
## Prerequisites
- Node.js 16+ (18+ or 20+ recommended)
- npm/yarn for package management
- clinic.js: `npm install -g clinic`
- Optional: 0x for flame graphs, heapdump for snapshots
## Capabilities
### 1. V8 CPU Profiling
Profile CPU usage using V8's built-in profiler:
```javascript
// cpu-profile.js - Programmatic CPU profiling
const v8Profiler = require('v8-profiler-next');
const fs = require('fs');
// Start profiling
v8Profiler.setGenerateType(1); // Generate call tree
v8Profiler.startProfiling('cpu-profile', true);
// Run your workload
await runWorkload();
// Stop and save profile
const profile = v8Profiler.stopProfiling('cpu-profile');
const profileData = profile.export();
fs.writeFileSync('cpu-profile.cpuprofile', JSON.stringify(profileData));
profile.delete();
console.log('CPU profile saved to cpu-profile.cpuprofile');
```
```bash
# Using Node.js built-in profiler
node --prof app.js
node --prof-process isolate-0x*.log > processed.txt
# Generate V8 log for analysis
node --trace-opt --trace-deopt app.js 2>&1 | grep -E "(opt|deopt)"
# Run with inspector for Chrome DevTools profiling
node --inspect app.js
# Then open chrome://inspect in Chrome
```
### 2. Heap Snapshot Analysis
Capture and analyze heap snapshots:
```javascript
// heap-analysis.js
const v8 = require('v8');
const fs = require('fs');
// Take heap snapshot
function takeHeapSnapshot(filename) {
const snapshotStream = v8.writeHeapSnapshot(filename);
console.log(`Heap snapshot written to ${snapshotStream}`);
return snapshotStream;
}
// Memory usage tracking
function trackMemory() {
const usage = process.memoryUsage();
return {
heapUsed: `${(usage.heapUsed / 1024 / 1024).toFixed(2)} MB`,
heapTotal: `${(usage.heapTotal / 1024 / 1024).toFixed(2)} MB`,
external: `${(usage.external / 1024 / 1024).toFixed(2)} MB`,
rss: `${(usage.rss / 1024 / 1024).toFixed(2)} MB`,
arrayBuffers: `${(usage.arrayBuffers / 1024 / 1024).toFixed(2)} MB`
};
}
// Heap statistics
function getHeapStats() {
const stats = v8.getHeapStatistics();
return {
totalHeapSize: `${(stats.total_heap_size / 1024 / 1024).toFixed(2)} MB`,
usedHeapSize: `${(stats.used_heap_size / 1024 / 1024).toFixed(2)} MB`,
heapSizeLimit: `${(stats.heap_size_limit / 1024 / 1024).toFixed(2)} MB`,
mallocedMemory: `${(stats.malloced_memory / 1024 / 1024).toFixed(2)} MB`,
peakMallocedMemory: `${(stats.peak_malloced_memory / 1024 / 1024).toFixed(2)} MB`
};
}
// Trigger garbage collection (requires --expose-gc flag)
function forceGC() {
if (global.gc) {
global.gc();
console.log('Garbage collection triggered');
} else {
console.warn('Run with --expose-gc to enable manual GC');
}
}
```
### 3. Clinic.js Tools
Use clinic.js suite for comprehensive analysis:
```bash
# Clinic Doctor - Overall health check
clinic doctor -- node app.js
# Generates: .clinic/xxx.clinic-doctor
# Clinic Flame - CPU flame graphs
clinic flame -- node app.js
# Generates: .clinic/xxx.clinic-flame
# Clinic Bubbleprof - Async operations visualization
clinic bubbleprof -- node app.js
# Generates: .clinic/xxx.clinic-bubbleprof
# Clinic Heap Profiler - Memory analysis
clinic heapprofiler -- node app.js
# Generates: .clinic/xxx.clinic-heapprofiler
# Run with specific workload
clinic flame --autocannon [ /api/users -- -c 10 -d 30 ] -- node app.js
# Analyze specific endpoint
clinic bubbleprof --autocannon [ /api/slow-endpoint -c 5 -d 60 ] -- node server.js
```
```javascript
// Using clinic programmatically
const ClinicDoctor = require('@clinic/doctor');
const doctor = new ClinicDoctor();
doctor.collect(['node', 'app.js'], (err, filepath) => {
if (err) throw err;
doctor.visualize(filepath, filepath + '.html', (err) => {
if (err) throw err;
console.log(`Report: ${filepath}.html`);
});
});
```
### 4. Event Loop Analysis
Debug event loop blocking and delays:
```javascript
// event-loop-monitor.js
const { monitorEventLoopDelay } = require('perf_hooks');
// Create histogram for event loop delay
const h = monitorEventLoopDelay({ resolution: 20 });
h.enable();
// Periodic reporting
setInterval(() => {
console.log('Event Loop Delay:');
console.log(` Min: ${h.min / 1e6} ms`);
console.log(` Max: ${h.max / 1e6} ms`);
console.log(` Mean: ${h.mean / 1e6} ms`);
console.log(` P50: ${h.percentile(50) / 1e6} ms`);
console.log(` P99: ${h.percentile(99) / 1e6} ms`);
h.reset();
}, 5000);
// Detect blocking operations
const blocked = require('blocked-at');
blocked((time, stack, { type, resource }) => {
console.warn(`Event loop blocked for ${time}ms`);
console.warn(`Type: ${type}`);
console.warn(`Stack:\n${stack.join('\n')}`);
}, { threshold: 100, resourcesCap: 100 });
```
```javascript
// Async operation timing
const async_hooks = require('async_hooks');
const { performance, PerformanceObserver } = require('perf_hooks');
// Track async operation durations
const asyncTiming = new Map();
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId) {
asyncTiming.set(asyncId, {
type,
start: performance.now(),
triggerAsyncId
});
},
destroy(asyncId) {
const timing = asyncTiming.get(asyncId);
if (timing) {
const duration = performance.now() - timing.start;
if (duration > 100) { // Log slow operations
console.log(`Slow async: ${timing.type} took ${duration.toFixed(2)}ms`);
}
asyncTiming.delete(asyncId);
}
}
});
hook.enable();
```
### 5. Flame Graph Generation
Generate flame graphs for CPU analysis:
```bash
# Using 0x
npm install -g 0x
0x -o app.js
# Opens flame graph in browser
# Using perf and FlameGraph (Linux)
perf record -F 99 -g -- node app.js
perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > flame.svg
# Using node --perf-basic-prof
node --perf-basic-prof app.js &
perf record -F 99 -p $! -g -- sleep 30
perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > flame.svg
```
### 6. V8 Optimization Analysis
Analyze V8 JIT optimization:
```bash
# Trace optimizations and deoptimizations
node --trace-opt --trace-deopt app.js 2>&1 | tee opt.log
# Analyze inline caches
node --trace-ic app.js 2>&1 | tee ic.log
# Check for hidden class transitions
node --allow-natives-syntax -e "
function Point(x, y) { this.x = x; this.y = y; }
const p = new Point(1, 2);
%DebugPrint(p);
%HaveSameMap(new Point(1,2), p);
"
# Detailed V8 flags
node --v8-options | grep -i "optimize"
```
```javascript
// Optimization hints (for debugging only)
function optimizedFunction(a, b) {
// This function should be optimized
return a + b;
}
// Check if function is optimized (requires --allow-natives-syntax)
// %OptimizeFunctionOnNextCall(optimizedFunction);
// optimizedFunction(1, 2);
// console.log(%GetOptimizationStatus(optimizedFunction));
```
### 7. Memory Leak Detection
Detect and diagnose memory leaks:
```javascript
// leak-detector.js
const memwatch = require('@airbnb/node-memwatch');
// Detect leak trends
memwatch.on('leak', (info) => {
console.error('Memory leak detected:');
console.error(JSON.stringify(info, null, 2));
});
// Track heap diffs
let lastHeapDiff = null;
memwatch.on('stats', (stats) => {
console.log('GC occurred:');
console.log(` Heap used: ${(stats.used_heap_size / 1024 / 1024).toFixed(2)} MB`);Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.