I need to get statistics from /proc/pid/schedstat for a particular process.

Here https://www.kernel.org/doc/Documentation/scheduler/sched-stats.txt I found the description of fields.

What are measure units of (1) time spent on the cpu and of (2) time spent waiting on a runqueue? How convert them to seconds? Are they measured in clock ticks and I should divide them by sysconf(_SC_CLK_TCK)?


According to the doc the time unit is "jiffies" As in, "I'll be there in a jiffy!" :)

A jiffy is equal to the time it takes light to travel one centimeter in a vacuum or approximately 33.3564 picoseconds. - Wikipedia

But that's not the definition you want. Try this post https://stackoverflow.com/questions/10885685/jiffies-how-to-calculate-seconds-elapsed where the top answer says

The size of a jiffy is determined by the value of the kernel constant HZ.

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

Conclusion: divide a schedstat time value by the system's HZ constant to convert to seconds.

Update: If you're dealing with these times in a programmatic context, the now top answer on that same page points to some system routines that you can call to do conversions (e.g. jiffies to milliseconds).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.