iovisor / iovisor/bcc

Some question when using BCC to calculate process CPU utilization

Open
#3,973 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

Hi all,
I am now working with a project that try to calculate the process CPU utilization by BCC. I tried imitating the [cpudist](https://github.com/iovisor/bcc/blob/master/tools/cpudist.py) to get the on-cpu time and off-cpu time for the process. But why there is a big gap between the the sum of on-cpu time and off-cpu time and the interval I set to output.

For example, I wrote a test program below which will cause high cpu utilization:
```
int main(){
while(1);
}
```
And the output of my program is below:
```
TICKS PID COMM ON CPU(ms) OFF CPU(ms)
1651389333.51 260271 cpu 223.990950 0.01
1651389334.57 260271 cpu 351.987700 0.01
1651389335.63 260271 cpu 511.988248 0.01
1651389336.68 260271 cpu 671.987550 0.01
1651389337.73 260271 cpu 767.989400 0.02
1651389338.79 260271 cpu 991.900899 0.07
1651389339.84 260271 cpu 959.964844 0.04
1651389340.90 260271 cpu 959.984888 0.02
1651389341.95 260271 cpu 927.996113 0.01
1651389343.00 260271 cpu 967.971981 0.03
1651389344.06 260271 cpu 575.989917 0.03
```
I set the interval to be one second for this example, and the sum of the on-cpu time and off-cpu time is not one second and also unstable.

Can someone tell my the reason for this? And how to fix such problem? Or is there any better approachs to calculate the CPU utilization using BCC?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.