CPUSTAT(8)
π CPUSTAT β a lil' tool that measures CPU utilization β¨
okay so bestie, welcome to the cpustat manual, from the System Manager's Manual section 8 π«Ά. Yes section 8, that's the sysadmin/voodoo section, we're in our grown-and-sexy era. Let's get into it π
πΈ NAME πΈ
cpustat β a tool to measure CPU utilization.
β¨ SYNOPSIS β¨
cpustat [ options ] [delay [count]]
π¦ DESCRIPTION π¦
So like, cpustat is this program that dumps the CPU utilization of the tasks that are currently running (and by "tasks" we mean processes or kernel threads, both of them count, no gatekeeping here π). It's genuinely so useful for monitoring long-lived processes on your system β daemons, kernel threads, and your regular everyday user processes. iykyk.
Here's the tea though: cpustat only shows you the tasks that actually measured some change in their CPU activity between each sample interval. And how does it know? Because of an increment in the CPU tick count stats of utime and stime in /proc/$pid/stat. So basically it only reports activity from busy tasks that are still alive at the moment of each sample snapshot. Which means β and this is important, bestie β it will not account for very short lived processes that pop in and out between each sample period. They're the ghosts. We don't see them. π
For each running task that consumed some CPU during the sample time, here's everything that gets displayed, no cap:
%CPUβ Total CPU used (in percent)%USRβ CPU used in user space (in percent)%SYSβ CPU used in system (kernel) space (in percent)PIDβ Process IDSβ Process StateCPUβ CPU used by the process at time of sampling.Timeβ Total CPU time used by the process since it started.Taskβ Process command line information (from processcmdlineorcommfields)
And the reason it's built this way? cpustat was designed to try and minimize the CPU overhead of process statistics gathering and reporting. It is therefore ideal for small embedded devices where CPU is limited and where measuring CPU utilisation may affect the overall CPU statistics. Lowkey self-aware of it. For this reason, it is not as complex as tools such as top(1) that have a more feature rich user interface. We are simple. We are efficient. We are iconic. π
π PROCESS STATE CODES π
Rβ RunningSβ SleepingDβ Waiting, Disk SleepTβ Stoppedtβ Tracing stoppedWβ PagingXorxβ DeadKβ WakekillWβ WakingPβ Parked
π OPTIONS π
the cpustat options are as follow, and yes we're listing every single one because you deserve the full menu, bestie π:
-aβ calculate CPU utilisation based on all CPUs. For example, if a process is using 100% of 1 CPU and the system has 4 CPUs, then the utilisation will show as 25%. The default is to show utilisation on a per CPU basis.-cβ get command information from processcommfield.-dβ strip directory basename off command information.-Dβ compute and show the distribution of CPU utilisation by task and by CPU.- By task, this breaks the CPU utilisation of each task into 20 ranges from minimum to the maximum and shows the count of tasks found at in that particular utilisation range. Useful to see any outliers and to characterize the typical per task usage of the CPU.
- By CPU, this shows the user and system CPU utilisation by per CPU.
-gβ show grand total of CPU utilisation statistics at the end of the run. This is the total cumulatave CPU used by each process, averaged over the entire run duration.-hβ show help.-iβ ignorecpustatin the statistics.-lβ show long (full) command information.-ntask_count β only display the first task_count number of top tasks.-pPID β only display process that matches the given PID.-qβ run quietly, only really makes sense with-roption.-rcsv_file β output gathered data in a comma separated values file. This can be then imported and graphed using your favourite open source spread sheet. The%CPUutilisation (system and user) for each process at each sample time is output into a table.-sβ show short command information.-Sβ show time stamp. If the-roption is used then an extra column appears in the CSV output file with the time of day for each sample.-tthreshold β ignore samples where the CPU usage delta per second less than the given threshold.-Tβ calculate total CPU utilisation.-xβ show extra CPU related statistics, namely: CPU load average over 1, 5 and 10 minutes, CPU frequency (average of all online CPU frequencies), number of CPUs online.-Xβ run in curses based "top" like mode; this will makecpustatconsume more CPU cycles as it adds on more display handling overhead.
β οΈ heads up on -X: it's giving top energy but it will eat more CPU cycles because of all the extra display handling overhead. Cute but expensive. π
π EXAMPLES π
cpustat
cpustat
Dump CPU stats every second until stopped.
cpustat -n 20 60
cpustat -n 20 60
Dump the top 20 CPU consuming tasks every 60 seconds until stopped.
cpustat 10 5
cpustat 10 5
Dump CPU stats every 10 seconds just 5 times.
cpustat -x -D -a 1 300
cpustat -x -D -a 1 300
Gather stats every second for 5 minutes with extra CPU stats and show CPU utilisation distributions per task and per CPU at the end of the run. Also, scale CPU utilisation by the number of CPUs so that 100% utilisation means 100% of all CPUs rather than 100% of 1 CPU.
π SEE ALSO π
forkstat(8), eventstat(8), vmstat(8), top(1)
π AUTHOR π
cpustat was written by Colin Ian King <colin.i.king@gmail.com>
This manual page was written by Colin Ian King <colin.i.king@gmail.com>, for the Ubuntu project (but may be used by others).
π COPYRIGHT π
Copyright Β© 2011-2021 Canonical Ltd, Copyright Β© 2021-2025 Colin Ian King
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
okay that's the whole page, you're officially a cpustat girlie now π
β¨ this was the CPUSTAT(8) page from the System Manager's Manual, and the version you're holding is dated January 8, 2024 β go forth and measure some CPU, bestie, ily, periodt ππ¦π
π¦ where this page comes from
- debian trixie: cpustat 0.03.00-1 Β· GPL-2.0-or-later
- nixos 26.05: cpustat 0.03.00
- nixpkgs unstable: cpustat 0.03.00
- ubuntu questing: cpustat 0.03.00-1
- ubuntu resolute: cpustat 0.03.00-1build1 Β· GPL-2.0-or-later
- ubuntu stonking: cpustat 0.03.00-1build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms