GNU time 命令提供了更强大的功能:
下边我们来学习写 GNU time 的使用
1. 最简单的用法
root@chopin:~$ /usr/bin/time sleep 2
0.00user 0.00system 0:02.00elapsed 0%CPU (0avgtext+0avgdata 1784maxresident)k
0inputs+0outputs (0major+72minor)pagefaults 0swaps
使用 GNU time 命令,直接使用绝对路径即可,我们可以看到输出信息更多了,不过格式有点丑,后边会讲如何自定义格式。
2. 保持内置 time
的输出样式
有同学会问,能输出内置 Shell 那种的格式么?可以的,使用 -p
选项即可
root@chopin:~$ /usr/bin/time -p sleep 2
real 2.00
user 0.00
sys 0.00
3. 输出更详细的信息
还可以输出更加详细的信息,让你对程序运行信息一目了然。请使用 -v
选项
root@chopin:~$ /usr/bin/time -v sleep 2
Command being timed: "sleep 2"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1804
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 71
Voluntary context switches: 1
Involuntary context switches: 1
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
全部0条评论
快来发表一下你的评论吧 !