【问题标题】:Why wall clock is very much higher than cpu user/kernel time为什么挂钟比cpu用户/内核时间高得多
【发布时间】:2013-08-01 08:40:18
【问题描述】:

在我用 C++ 编写的应用程序中,我得到了以下时间信息。

0.46u CPU user time
1.27s CPU kernel time
41.83s Real wall clock
4% CPU% usage.
0 Major page faults
207848 No. of file system outputs.
100269 minor page faults.
82: No. of times the process was context switched involuntarily.
1297 No. of times that the program was context-switched.

即使没有严重的页面错误,如此高的挂起时间是什么原因?

【问题讨论】:

  • 如果您不向我们展示您的代码/逻辑,我们怎么知道?
  • 你在里面睡了几个?
  • 显示代码。您的应用程序是否在执行大量磁盘 IO?
  • Major page fault 为 0,表示没有磁盘 IO。如果我错了,请纠正我。
  • 这可能看起来有点明显,但该过程是否进行任何输入。特别是键盘输入。一个简单的std::getline( std::cin, line ) 可能会花费数小时的挂钟时间,而没有 CPU 则如此。

标签: c++ linux page-fault cpu-time


【解决方案1】:

因为您的代码花费大量时间进行磁盘 I/O 和“等待”:

207848 No. of file system outputs.
100269 minor page faults.
82: No. of times the process was context switched involuntarily.
1297 No. of times that the program was context-switched.

所有这些活动(“进程没有不自觉地切换上下文”除外)都表明您的进程正在等待硬盘交付或承担某些事情。

此外,您的代码在内核模式下花费的时间比在用户模式下花费的时间更多,这也表明您的代码正在执行大量磁盘 I/O(或其他 I/O)。

【讨论】:

  • 感谢 Mats,但主要的页面错误是 0。这意味着进程不会向磁盘读取/写入任何内容。
  • 是的,但它仍然会陷入操作系统以服务页面错误 - 因此它增加了进程在内核模式下花费的时间。 No of file system outputs 绝对不为零。所以你必须在某处写入某个文件(-系统设备)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2020-11-29
  • 2013-07-04
  • 2017-02-23
相关资源
最近更新 更多