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

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

我有一个 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) perspective.Is 看它是不是上下文切换太多(Linux 中的循环调度)导致了这个问题?

您能做的最好的事情是 运行 使用 gprof、gperftools、callgrind(valgrind 的一部分)或(我认为最好的)Intel VTune 等分析器对其进行分析。他们可以向您展示代码背后的内容。而且你最好有调试符号(!=而不是未经优化的编译)来清楚地了解这一点。否则,您可以只了解 "best guesses" 正在发生的事情...

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

Vtune example