我正在尝试使用 time
命令作为对一些执行大量文本处理并进行大量网络调用的脚本进行基准测试的简单解决方案。为了评估它是否合适,我尝试这样做:
/usr/bin/time -f "\n%E elapsed,\n%U user,\n%S system, \n %P CPU, \n%M
max-mem footprint in KB, \n%t avg-mem footprint in KB, \n%K Average total
(data+stack+text) memory,\n%F major page faults, \n%I file system
inputs by the process, \n%O file system outputs by the process, \n%r
socket messages received, \n%s socket messages sent, \n%x status" yum
install nmap
得到:
1:35.15 elapsed,
3.17 user,
0.40 system,
3% CPU,
0 max-mem footprint in KB,
0 avg-mem footprint in KB,
0 Average total (data+stack+text) memory,
127 major page faults,
0 file system inputs by the process,
0 file system outputs by the process,
0 socket messages received,
0 socket messages sent,
0 status
这并不完全符合我的预期 - 特别是 0 值。即使我将命令更改为 ping google.com
,套接字消息也为 0。这是怎么回事?还有其他选择吗?
[而且我很困惑它是应该留在这里还是发布在 serverfault 中]
最佳答案
我认为它不适用于 Linux;我假设您使用的是 Linux,因为您说的是“strace”。手册页说:
Bugs
Not all resources are measured by all versions of Unix,
so some of the values might be reported as zero. The present
selection was mostly inspired by the data provided by 4.2 or
4.3BSD.
我在 OSX 系统(BSD-ish)上试过“wget”来检查它是否报告套接字统计信息,至少套接字可以工作:
0.00 user,
0.01 system,
1% CPU,
0 max-mem footprint in KB,
0 avg-mem footprint in KB,
0 Average total (data+stack+text) memory,
0 major page faults,
0 file system inputs by the process,
0 file system outputs by the process,
151 socket messages received,
8 socket messages sent,
0 status
希望对你有帮助, 亚历克斯。
关于bash - 使用时间命令进行基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7198356/