Question

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?

Was it helpful?

Solution

You can use getrusage(2) to get the CPU time used, rather than just measuring real time. That should get you the answer you want without having to resort to funny business like blocking other programs from running.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top