Ubuntu Server 9.10

So there is the time command which will show you the time it took for a specific process/command to run after the command has completed. For example:

:~$ time ls
real 0m0.020s
user 0m0.000s
sys 0m0.000s

I'd like to also collect the average CPU usage, Memory, and Disk (i/o) utilization after the process has completed using time (or another command if necessary). How can I accomplish this?

Mainly I am using this to benchmark MySQL import performance using different innodb_buffer_pool_size settings.

  • This is not a very accurate test, the operating system may be caching data to, making you results unreliable. – The Unix Janitor Mar 20 '10 at 19:29

That's kind of what the getrusage calls are meant for, though most of the fields are unused on Linux (at least that was the case the last time I had to care.

I usually just use top -p myself, as it limits top to the process I care about. You can then toggle additional fields in the usual fashion. For example, top -p 1 would only show the init process. You can then watch the performance of MySQL as you do your import.

You can watch CPU stats, memory usage (RSS & Virtual), faults, anything top would normally give you.


I'm not quite sure if this'll work exactly the way you want to, but vmstat <delay> will print out stats every seconds.

There's also sar which reads system stats automatically taken every 10 minutes, or however long sard is configured for.


Good question. In the context of MySQL, you might be better off using tools designed for that purpose. You have Sysbench, Supersmack, and others. See the links below.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.