views:

675

answers:

1

I am running a shell script to execute a c++ application, which measures the performance of an api. i can capture the latency (time taken to return a value for a given set of parameters) of the api, but i also wish to capture the cpu and memory usage alongside at intervals of say 5-10 seconds.

is there a way to do this without effecting the performance of the system too much and that too within the same script? i have found many examples where one can do outside (independently) of the script we are running; but not one where we can do within the same script.

+2  A: 

I'd suggest to use 'time' command and also 'vmstat' command. The first will give CPU usage of executable execution and second - periodic (i.e. once per second) dump of CPU/memory/IO of the system.

Example:

time dd if=/dev/zero bs=1K of=/dev/null count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 0.738194 seconds, 1.4 GB/s
0.218u 0.519s 0:00.73 98.6%     0+0k 0+0io 0pf+0w <== that's time result
Drakosha
could you provide an example? i tried the same within shell, but it expects the process to get over and i have multiple instances of the call running in the same script ... written one line after the other.
gagneet
I added an example, i think you'll need to collect the output and sum it manually. Another suggestion to make all the runs in one script and do 'time' for it.
Drakosha