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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With