You are not logged in.
Pages: 1
When I try to calculate the cpu usage by parse out the data from /proc/<PID>/stat, I meet a problem.
Firstly ,for each process I calculate the cpu usage % with below manner:
prb_time = utime+stime; the utime and stime is from the file /proc/<PID>/stat. After 2 seconds calculate the prb_time again. And then get the real run time of the process in the two second by the below:
prb_real_run_time = prb_time_new - prb_time_old.
I calculate all the processes under /proc and sum them. Let's name the summing result is sum_result_prb_time.
Secondly, I parse out the data from the first line(beginning with "cpu") of file /proc/stat to calculate the cpu time spending in user model, system model and idle task. The manner is: total_cpu_time = user+system+nice+idle. After 2 seconds, I calculate the cpu time again. And then I get the total cpu time by: real_cpu_run_time = total_cpu_time_new - total_cpu_time_old.
As my understanding, the value of the two value,sum_result_prb_time and real_cpu_run_time, should almost be same. Or there should be little difference with the two value. But I find that the value real_cpu_run_time is alomst much bigger than sum_result_prb_time. Could please someone give some comments for the result?
The below is the result:
sum_result_prb_time real_cpu_run_time
25....................... 32
124......................174
80.......................104
20.......................41
28.......................85
14.......................37
22.......................43
20.......................78
45.......................63
51.......................74
34.......................58
31.......................52
31.......................88
26.......................46
23.......................42
26.......................88
27.......................47
Offline
Pages: 1