truss -D和truss -E的区别是什么?

我目前正在分析一个从文件读取并且性能非常低的Solaris命令。 truss -D命令显示我read系统调用需要0.03秒,但是当我使用truss -E ,它们总是为0.0000或0.0001(比-D选项低两个数量级)。 在man页上,它说:

  -D Includes a time delta on each line of trace output. The value appears as a field containing seconds.fraction and represents the elapsed time for the LWP that incurred the event since the last reported event incurred by that LWP. Specifically, for system calls, this is not the time spent within the system call. -E Includes a time delta on each line of trace output. The value appears as a field containing seconds.fraction and represents the difference in time elapsed between the beginning and end of a system call. In contrast to the -D option, this is the amount of time spent within the system call. 

所以-E选项会测量在系统调用中花费的实际时间,而-D不会…任何人都可以解释究竟是什么造成了这种差异? 在系统调用的“外部”剩下的时间里正在做什么?

根据你引用的文档,我发现很清楚,一个系统调用覆盖了整个系统调用的时间,另一个覆盖了系统调用的时间。

系统调用花费的时间百分比与花费在系统调用之外的时间百分比将粗略地告诉您一个进程是否受CPU限制。

CPU绑定进程大部分时间都花在系统调用之外。 这是一个进程将进入的状态,而它正在执行计算。 对于一个CPU绑定的过程,这两个数字之间的差异将会很大,并且可能至less是一个数量级。

一个不受CPU限制的进程将被阻塞,等待大部分时间的事件。 由于阻塞只能发生在系统调用中。 对于不受CPU限制的进程,数字将大致相同(可能仅相差一个数字百分比)。

这是简单的解释,实际上还有几个方面需要考虑。 由于内存映射和交换,一个进程实际上可以阻塞,而不需要进入系统调用。 另外,内核可以提供一些function,这些function涉及内核代码的计算。 这可能导致一个进程花费大部分时间在系统调用中,并且仍然是CPU绑定的。 后者例如可能发生在使用encryption文件系统时。

系统调用之外的时间是在进入下一个系统调用之前运行程序代码的时间。