1

我有一个在 Linux 内核之上运行的应用程序(一个简单的 C 代码)。我正在测量代码两点之间的时间。我想知道是否有任何其他进程或调度程序本身在这两点之间抢占了我的应用程序。有没有办法找到这个。

4

1 回答 1

1

识别代码中两点之间是否有任何上下文切换的一种方法是使用

getrusage(int who, struct rusage *usage)

调用并比较ru_nvcsw & ru_nivcsw的值

   struct rusage {
       ...
       long   ru_nvcsw;         /* voluntary context switches */
       long   ru_nivcsw;        /* involuntary context switches */
   };
于 2015-10-04T05:48:08.330 回答