5

I want to measure the execution time of a c-code segment using Linux. I take one timestamps at the beginning of the code segment and one at the end. But I don't know how to protect the code against IRQs and context switches to high prior tasks. The program runs in user space! The code segment is short so don't panic hosing the system.

Does anyone know an easy solution for this kind of protection?

4

1 回答 1

3

您可以使用getrusage(2)来获取所使用的 CPU 时间,而不仅仅是测量实时时间。这应该可以为您提供您想要的答案,而不必求助于阻止其他程序运行等有趣的事情。

于 2013-04-27T17:29:08.920 回答