CPU Profiling with --prof and clinic.js
Profile Node.js CPU usage to find performance bottlenecks using built-in V8 profiler and clinic.js flame charts.
Prerequisites
- -Node.js installed
- -npm install -g clinic (for clinic.js)
Steps
Profile with the built-in V8 profiler
Start Node.js with the --prof flag to generate a V8 CPU profile log file.
Run your workload against the app while profiling. The log is written when the process exits.
Process the V8 profile log
Convert the raw V8 log into a human-readable summary showing where CPU time was spent.
Review the profile results
Examine the processed profile to identify hot functions and optimization opportunities.
Focus on the 'ticks' column. Functions with the most ticks are consuming the most CPU time.
Use clinic.js flame for visual profiling
Generate an interactive flame chart to visually identify CPU bottlenecks in your application.
Wider bars in the flame chart mean more CPU time. Look for unexpectedly wide bars in your own code (not Node internals).
Profile with Chrome DevTools Performance tab
Use the DevTools Performance tab for interactive CPU profiling with timeline and call tree views.
Full Script
FAQ
Discussion
Loading comments...