linux 下统计程序性能,并绘制成图表

来源:互联网 发布:samlight打标软件 编辑:程序博客网 时间:2024/04/27 16:33

最近需要在linux统计程序运行性能,一般是使用top命令查看程序cpu,mem等信息的。但是老盯着看也不方便,准备把数据写到文件,再进行统计,并绘制成图表,便于分析:

研究了一下,top命令支持几个选项:

-b 后台模式,支持写到文件。不加不行。

-n 统计次数。

-d 统计周期。秒。

-p 要统计的pid.

命令行如下,统计10分钟的数据,间隔0.5s:

debian:/# ps aux|grep csraroot      3881  0.2  0.6  28744 20972 pts/0    S    16:46   0:00 gdb ./csramon_droot      3883 35.7 20.2 1470164 667344 pts/0  Sl+  16:46   0:48 /trunk/trunk/common/build/makes/lnx_2_6/dbg/bin/csramon_droot      4297  0.0  0.0   3952   732 pts/1    S+   16:48   0:00 grep csradebian:/# top -b -n 1200 -d 0.5 -p 3883 > test.txt

把数据重定向到test.txt。查看一下内容:

debian:/# head -n 10  test.txt

top - 17:10:39 up 31 min,  4 users,  load average: 0.11, 0.19, 0.18Tasks:  71 total,   2 running,  69 sleeping,   0 stopped,   0 zombieCpu(s): 13.3%us,  4.0%sy,  0.0%ni, 81.3%id,  1.4%wa,  0.0%hi,  0.0%si,  0.0%stMem:   3302380k total,  3194656k used,   107724k free,    18176k buffersSwap:        0k total,        0k used,        0k free,  2213452k cached  PID USER      PR  NI  VIRT  RES  SHR S <span style="color:#ff0000;">%CPU</span> %MEM    TIME+  COMMAND                                     4498 root      40   0 1585m 786m 5244 S   28 24.4   7:27.77 csramon_d                                      1 root      40   0  2144  776  684 S    0  0.0   0:00.89 init     

发现在第八列,就是%CPU,可以把它单独提取出来,放到csv文件,.csv可以直接用excel打开:

debian:/# cat test.txt|grep csramon_d|awk '{print $9}'> r.csv


现在就可以用Excel打开绘图了,excel绘图怎么弄,这里我就说了,我用的是WPS:





0 0
原创粉丝点击