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?
probe module(@1).function(@2).call {
begin = gettimeofday_ns()
}
probe module(@1).function(@2).return {
if (begin>0)
stats <<< gettimeofday_ns() - begin
}
probe end {
if (begin == 0) {
printf("No samples observed so far.\n");
} else {
printf("Distribution of %s latencies (in nanoseconds) for %d samples\n", @2, @count(stats))
printf("max/avg/min: %d/%d/%d\n", @max(stats), @avg(stats), @min(stats))
print(@hist_log(stats))
}
}
global begin, stats