Joh*_*lla 19 statistics time command time-utility
我可以非常快速地监视进程的运行时间time:
x@y ~ $ time foo
real 0m14.299s
user 0m4.770s
sys 0m0.440s
Run Code Online (Sandbox Code Playgroud)
有没有办法可以获取记录到 STDOUT 的参数的 I/O 和 CPU 使用率的相同数据?一个简单的命令或实用程序time是理想的,我只传递我想要运行的东西的参数:
x@y ~ $ stats foo
wallclock runtime 0m14.299s
I/O reads 290,420 KB
I/O writes 239,429 KB
peak CPU usage 18.62%
mean CPU usage 1.44%
# etc.
Run Code Online (Sandbox Code Playgroud)
MaQ*_*eod 25
查看系统上的 time 手册页,某些实现具有格式选项以包括 I/O、CPU 和内存统计信息 (-f)。
例如, GNU time, with-v将显示所有可用信息(在 Linux 上):
/usr/bin/time -v ls
Command being timed: "ls"
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:00.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): 3664
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 273
Voluntary context switches: 2
Involuntary context switches: 2
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
Run Code Online (Sandbox Code Playgroud)
在BSDs,-l改用。
请注意,这是实际的/usr/bin/time程序,而不是某些 shellbash提供的关键字,您可以使用time pipeline.