问题描述
我运行一个shell脚本来执行一个c ++应用程序,它测量api的性能。我可以捕获api的延迟(返回给定参数集的值的时间),但我也希望捕获cpu和内存使用情况,间隔时间为5-10秒。
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.
推荐答案
我建议使用''命令以及'命令。第一个将给予系统的CPU /内存/ IO的可执行执行和第二个周期性(即每秒一次)转储的CPU使用。
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.
示例:
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
这篇关于动态捕获CPU和内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!