I got confused while reading this question on stack overflow. The asker says:
"'top' will simply not do, as there is a delay between cpu dumps, it requires 2 dumps and several seconds, which hangs my program".
What the asker is talking about? I've always assumed that top does exactly the same thing that the accepted answer recommends. And his claim that top "hangs his program" doesn't make any sense to me, but no one called him out on it in the comments.
Typically I need to get overall CPU utilization for a large group of processes running on a single machine. Usually I just run top with a fairly long sampling rate (usually 10 seconds) while running my processes under a worst case load and determine an average load estimate. Is getting a measurement this way totally wrong?
Note: While getting my measurements I also ensure that no other unnecessary services or user space processes are running.