Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个在 Linux 内核之上运行的应用程序(一个简单的 C 代码)。我正在测量代码两点之间的时间。我想知道是否有任何其他进程或调度程序本身在这两点之间抢占了我的应用程序。有没有办法找到这个。
识别代码中两点之间是否有任何上下文切换的一种方法是使用
getrusage(int who, struct rusage *usage)
调用并比较ru_nvcsw & ru_nivcsw的值
struct rusage { ... long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ };