The Linux kernel comes with a performance analysis tool called perf that can even be used on production servers to analyze the call stack of a server, or a process. This is useful to find the bottlenecks of a query processing or simply of a server running and improve those.
It is usually found in the package “perf”, at least it is the case of RHEL, CentOS and Linux.
/proc/sys/kernel/perf_event_paranoid can be used to restrict access to the performance counters.
Profile system as long as needed, can be cancelled with Ctl-C:
perf record -a -g
Profile system for a given period of time:
perf record -a -g -s sleep $TIME_IN_SECONDS
For the duration of a command:
perf record -a -g -s -- $COMMAND
Different things can be recorded:
Reports are saved by default in $HOME/perf.data. Old reports are renamed as $HOME/perf.data.old.
This is done by perf top, like system-wide profiling:
perf top
Profiling without accumulating stats:
perf top -z
View profile recorded:
perf report -n
With a graph:
perf report -g
Unless otherwise specified, the contents of this website are (C)Copyright Michael Paquier 2010-2025 and are licensed for use under CC BY-NC-ND 4.0.