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.
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.
I think that you're looking for sar. SAR stands for System Activity Report. It's used in Unix-like operating systems to report on CPU, memory, and IO usage, collected by sysstat.
Then, 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 production servers.
After it is configured, it will be easy for you to extract data from reports in your script by using the sar command, grep, and awk.
You didn't specify what OS you are 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.