I've written some multi-thread test, and now I want to be sure that the highest CPU usage of this test is equal to
100 * CPU_NUMBER of current machine. Is it possible to do?
UPD 0: I'm talking about Linux system.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
I think that you're looking for
sar. SAR stands for System Activty Report. It's used in unix-like operating systems to report about CPU, memory and IO usage, collected by
sysatat can be configured to
Monitor individual processes. Link
How often it collects, and how long sar keeps reports is decided on the first setup.
You just want to note that such a data collection is not "free" so I won't keep it on on production servers.
After it is configured it will be easy for you to extract datas from reports in your script by using the
You didn't specified what OS are you working on, so I encourage you to search how to set up sar/sysstat on your distro.
pidstat which is usually part of the
sysstat package can monitor a single process id and print statistics on each of its threads. For example, for a running chrome browser:
$ pidstat -t -p 27680 1 17:17:36 TGID TID %usr %system %guest %CPU CPU Command 17:17:37 27680 - 13.00 3.00 0.00 16.00 0 chrome 17:17:37 - 27680 9.00 1.00 0.00 10.00 0 |__chrome 17:17:37 - 27712 2.00 1.00 0.00 3.00 1 |__Chrome_IOThread 17:17:37 - 27714 2.00 0.00 0.00 2.00 1 |__CompositorTileW
This 1-second sample has many threads with 0% cpu which I have removed. I understand that 100% means just 1 cpu wholly occupied. There is a
-I flag to divide this by the number of cpus.