Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert process cpu usage in clock ticks to percentage?

I setup collectd on my Debian 6 virtual machine for monitoring and performance analysis. Collectd's processes plugin provides statistics about a process' cpu usage, though what units these statistics have is not documented anywhere. It's certainly not jiffies or milliseconds, since the total cpu usage of several processes could go as high as 400,000 (of some unknown unit) per second on a 4 core virtual machine.

By looking at collectd's source code (https://github.com/collectd/collectd/blob/master/src/processes.c - in the ps_read_process function) , I figured out this data is read from the /proc/$pid/stat file of the process. The proc man page (link- http://man7.org/linux/man-pages/man5/proc.5.html) says the cpu usage there is measured in clock ticks.

This is nice, but clock ticks are a little arbitrary for monitoring and performance analysis. I'd like to convert the clock ticks value to something more meaningful, ideally percentage of total cpu time. How can I do that in a portable way, without just assuming my processor provides 3GHZ of clock ticks?

like image 388
akir94 Avatar asked Dec 20 '25 21:12

akir94


1 Answers

Further inspection of collectd's code revealed that the cpu usage is converted to microseconds.

Also, turns out a similar question was already asked and answered here.

like image 93
akir94 Avatar answered Dec 23 '25 20:12

akir94



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!