在 Linux 中,非常高的经过(挂钟)时间和低系统时间的含义

Meaning of very high Elapsed(wall clock) time and low System time in Linux

本文关键字:时间 系统 挂钟 Linux 非常 经过      更新时间:2023-10-16

我有一个C++二进制文件,我正在尝试测量它最坏情况的性能。我用/usr/bin/time -v <命令>

结果是

User time (seconds): 161.07
System time (seconds): 16.64
Percent of CPU this job got: 7%
Elapsed (wall clock) time (h:mm:ss or m:ss): 39:44.46
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): 19889808
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 1272786
Voluntary context switches: 233597
Involuntary context switches: 138
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

我如何解释这个结果,是什么导致这个应用程序花费这么多时间?

无需等待用户输入,它基本上处理大型文本文件和数据库。

我是从Linux(OS)的角度来看待它的。是不是太多的上下文切换(Linux 中的循环调度)导致了这种情况?

你能做的最好的事情是使用像gprof,gperftools,callgrind(valgrind的一部分)或(在我看来最好的)Intel VTune这样的分析器运行它。他们可以向您展示代码背后的内容。而且您最好拥有调试符号(!=而不是在没有优化的情况下进行编译)来清楚地了解这一点。否则,你可以对引擎盖下发生的事情有"最佳猜测"......

正如我所说,我偏向于 VTune,因为它速度很快,并且显示了很多有用的信息。看这里的例子:

Vtune 示例