Command

是否有類似“時間”的東西也記錄 I/O 和 CPU?

  • February 8, 2016

我可以通過以下方式快速監控程序的執行時間time

x@y ~ $ time foo

real        0m14.299s
user        0m4.770s
sys         0m0.440s

有沒有一種方法可以獲得參數的 I/O 和 CPU 使用率的相同數據,記錄到 STDOUT?一個簡單的命令或實用程序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.

查看系統上的時間手冊頁,一些實現具有格式選項,包括 I/O、CPU 和記憶體統計資訊 (-f)。

例如, GNUtime-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

BSDs-l改為使用。

請注意,這是實際/usr/bin/time程序,而不是某些 shellbash提供的關鍵字,您可以使用time pipeline.

引用自:https://unix.stackexchange.com/questions/120451