profile-app-cpu

Diagnose CPU saturation in live Node.js containers using V8 inspector CPU profiles.

24.2k|4.1k|Updated Dec 3, 2022
One-click install
npx skills add https://github.com/activepieces/activepieces --skill profile-app-cpu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: profile-app-cpu
Source: https://github.com/activepieces/activepieces/tree/main/.agents/skills/profile-app-cpu
Command: npx skills add https://github.com/activepieces/activepieces --skill profile-app-cpu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

When a production app container sits at its CPU cap and healthchecks time out without anything crashing, you need to find which function is burning CPU without restarting the process and losing the state you are trying to measure.

Core Features & Use Cases

  • Database Elimination: Query pg_stat_activity to confirm Postgres is a victim (ClientRead waits) rather than the cause before profiling the app.
  • Thread-Level Attribution: Use top -H on the container PID to separate a hot MainThread (JS on the event loop) from V8Worker GC threads and libuv threadpool work.
  • In-Place CPU Profiling: Open the V8 inspector with SIGUSR1 on a running container, capture a 30-second CPU profile over the Chrome DevTools Protocol, and aggregate samples by function to find the true hot frame.
  • Use Case: A self-hoster reports the app is "unhealthy" but the process is alive. You rule out the database, confirm the MainThread is hot, attach the inspector without a restart, and report that one function owns 84% of non-idle CPU.

Quick Start

Profile the CPU-bound app container and tell me which function is consuming the most CPU.

Frequently Asked Questions about profile-app-cpu

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I profile CPU usage of a running Node.js process in Docker?

Send SIGUSR1 to PID 1 inside the container to start the V8 inspector on 127.0.0.1:9229, then connect over the Chrome DevTools Protocol from inside the same network namespace. Run Profiler.start, wait about 30 seconds, and save the result from Profiler.stop as a .cpuprofile file.

How to find which function is using the most CPU in Node.js?

Aggregate the .cpuprofile samples by function name, URL, and line rather than reading raw stack nodes, because V8 emits one node per call stack and splits hot functions into many small entries. Sum self-time per function and compare against the (idle) percentage to report share of non-idle CPU.

Why does my Docker container show unhealthy but the app is still running?

A blocked event loop delays the healthcheck curl past its timeout, so the container shows unhealthy with a climbing FailingStreak while still serving traffic. Zombie curl processes accumulating in the container are killed healthchecks, not a leak.

Does docker stats CPU percentage mean the host is maxed out?

No, docker stats CPU is per-core, so 100% means one full core. A container capped at cpus: 1 reads about 100% when saturated even though the host has plenty of idle capacity.

How do I tell if Postgres or my app is the CPU bottleneck?

Query pg_stat_activity for wait events: sessions stuck in ClientRead with zero lock waits mean Postgres finished its work and is waiting on the client, so the app event loop is the bottleneck. A struggling database shows lock waits or long IO and LWLock waits instead.

Can I close the V8 inspector after opening it with SIGUSR1?

No, the inspector cannot be closed once started and lives until the process exits. Use a container you can recycle afterwards and note this in the incident record.