是否有类似“时间”的东西也记录了I / O和CPU?


18

我可以使用以下命令快速监视进程的运行时间time

x@y ~ $ time foo

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

有没有一种方法可以获取记录在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.

Answers:


25

查看系统上的时间手册页,某些实现具有格式选项,其中包括I / O,CPU和内存统计信息(-f)。

例如,GNU timewith -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程序,而不是某些shell所bash提供的关键字,您可以使用它们来调用time pipeline


4
zshtime关键字也可以配置为(带有$TIMEFMT)以提供该信息。
斯特凡Chazelas

1
这正是我想要的。完善!另外,还要感谢这篇文章的编辑者,他们澄清说,command time -v ...由于bashhijacking ,您需要使用它来运行它time
John Feminella 2014年

4

该命令strace可能很有用,您可以将跟踪限制为仅计数-c或一部分系统调用,

-e trace=set
      Trace  only  the  specified set of system calls.  The -c option is
      useful for determining which  system  calls  might  be  useful  to
      trace.   For  example,  trace=open,close,read,write  means to only
      trace those four system calls.  Be careful when making  inferences
      about  the  user/kernel  boundary if only a subset of system calls
      are being monitored.  The default is trace=all.

在这个答案中,我用它来计算系统调用的数量。我不知道是否有任何内容可以概述吞吐量,但是strace可以得出类似awk摘要的数字。


strace会大大降低速度,因此测量不同系统调用的相对时间很有用,但我不会将其用作通用计时器。 perf如果您使用采样频率选项,则速度更快/干扰更少。
Marcin
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.