Skip to content
Advertisement

SystemTap script to profile latency of functions

My goal is to profile the execution time of each function in a kernel module. Using the sample scripts I saw online, I came up with the following script to fulfill my need. But occasionally I get negative values for calculated latencies. Although, they happen rarely but I guess that indicates something is wrong with my script. Can anyone help me with that please?

JavaScript

Advertisement

Answer

The gettimeofday_*() functions can only approximate wallclock time. It is possible that across CPUs, or across a time adjustment moment, the values won’t move monotonically the way you expect. get_cycles() is more monotonic on a given CPU, and a few other clock-related functions are available.

Also, your begin variable is a simple scalar. What if the same function is being called from multiple threads/cpus, or if recursion occurs? It’ll get overwritten. This should be enough (and work correctly, from a nesting/concurrency point of view):

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement