Tuesday, January 4, 2022

[SOLVED] How to record timestamps when a program enters/leaves user/kernel mode in Linux?

Issue

Is there a way to monitor the timestamp when a program enters/leaves user/kernel mode in Linux?

getrusage() returns resource usage measures containing total user/system CPU time used, but this is not what I need.


Solution

strace the process.

strace --absolute-timestamps --syscall-times will give the timestamp when the process enters the syscall and the time it spends in the syscall, so the timestamp when leaving the syscall can be calculated from the two.



Answered By - KamilCuk