mpstat -P ALL 2 10
This is mostly for my own future reference. Today I needed to to check the resource consumption of an application on a currently bare metal system so I could get a good idea how to spec out its new virtual home. Now, in Linux, checking cpu consumption is easy, but I wanted to check the per core usage. The reason in this case was no one knew if this application was multithreaded (likely not if the application’s stability is indicative of its code quality) and how well if it was. Giving a machine multiple threads to run a single threaded application is a bit pointless. That said, I found two ways to check per core usage that didn’t involve installing additional packages on the system (htop, I’m looking at you).
Mpstat is a really cool program I happened upon today in my searches. It basically reports on every live stat you could ever want on a CPU.
mpstat -P ALL 2 10
That will report all stats on all cpus every 2 seconds, 10 times.
I’d prefer not using something that’s interractive so I can more easily use the data with other programs (like tr, cut, grep, etc), which is why I included this one second. With top, if you press the 1 key while it’s running, it will print per-core cpu stats.
Tasks: 188 total, 1 running, 187 sleeping, 0 stopped, 0 zombie Cpu0 : 0.3%us, 0.0%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu1 : 0.0%us, 0.0%sy, 0.0%ni, 97.0%id, 3.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu2 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu3 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 4086584k total, 3951260k used, 135324k free, 24532k buffers Swap: 8388600k total, 4203824k used, 4184776k free, 103416k cached