Table of Contents

Name

threadcpu - show CPU usage of threads in user% and system%

Synopsis

threadcpu [ -h ] [ -s measuring-interval ] [ -p path-to-jstack ]

Description

threadcpu calculates user% and system% for all threads and writes them out in SPACE separated columns.
If it can identify a process as Java/JVM process then it calls jstack to get the list of threads including their names.
The 3 or 4 columns of threadcpu output are:

user percent
The relative time the task did spent in user mode in the measuring interval.

system percent
The relative time the task did spent in system mode in the measuring interval.

pid/nid
The task/thread ID as visible as /proc/*/task/<THREAD-ID>.

procname/threadname
This is an optional column and may be empty. In case of a Java thread it is the JVM thread name. Otherwise the name of the process as shown in /proc/<PID>/stat (including parenthesis).

The calculation is actually done by getting the jiffies used in the measuring interval for utime and stime for each task. And then the percentage in relation to the global used jiffies from /proc/stat is calculated. See proc(5) for more details.

If the measuring interval is too short to get reasonable results then a warning will be printed.

Options

-h
Show small help page and exit.

-s <seconds>
Specify the measuring interval in seconds. Default: 10.

-p <path-to-jstack>
Specify which jstack should be called in case of Java/JVM processes to get thread names. Default: /usr/bin/jstack

Examples

This line sorts the tasks by user% and prints the 12 most "active" tasks:
$ threadcpu -s 30 -p /opt/java/default/bin/jstack 2>/dev/null | sort -n | tail -n 12

See Also

lps(1) , proc(5)

Caveats

No signal handling is done on main process and jstack child.

Author

Frank Bergmann, http://www.tuxad.com


Table of Contents