Measure CPU usage after renice
I would like to measure if there is an increase/decrease in CPU usage after renicing a process. What will be the best way to achieve this?
The simplest way I can think of is with top. It can be used for re-nicing a process while checking CPU usage at the same time. See 'man top' for it's usage.
I might be inclined to retain the data in /proc/<pid>/stat at various time-points. You'll need to do the math yourself, but you can get the data (exactly) when you want it.
Also correct me if am wrong I should be trying to measure the time slices the process gets on each run, and try to see if there is an increase in the time slice or the frequency of getting the CPU has increased ryt? what fields in the /proc/stat should be used?
here is the out put,
# ./procstat 1142
start_time: 06.25 15:24 (2698.61s)
Presuming that is the procstat.c code I found, it should give you plenty of ideas.
Those fields always increment. You'll need to note the time delta and calculate the difference in clock ticks for the various CPU fields. Then you should be able to see if the rate changes.
Personally I'd do the conversion to seconds at the end - should it even by needed at all.
yes it is the procstat.c code. By looking at the fields only three fields are changing(incrementing, may be because of the process I have chosen) anyway all three are time fields. They are utime, stime and start_time. I think utime and stime are the important fields here.
utime %lu Amount of time that this process has been scheduled in user mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK). This includes guest time, guest_time (time spent running a virtual CPU, see below), so that applications that are not aware of the guest time field do not lose that time from their calculations.
stime %lu Amount of time that this process has been scheduled in kernel mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK).
Delta of utime in 5 secs will give no of clock ticks(cpu cycles) used by the process ryt? so after renicing(giving low value) the value of delta utime should increase ryt?
In what other ways can this data be utilized to see if there is an increase in cpu usage after renicing?
I tried the above logic. calculated the delta utime at 5 second intervals. These are the results,
dutime: 8 7786 7778
dutime: 8 7794 7786
dutime: 7 7801 7794
dutime: 4 7805 7801
dutime: 9 7814 7805
dutime: 8 7822 7814
there is some active changes in the dutime. But the results are not what I expected :( I thought that the dutime will increase with low nice values, but it looks like it is not like that. Results are worse when the application is in the background( am testing this on Android & by pressing home its put to background) dutime is zero. These are the results,
dutime: 9 8264 8255
dutime: 0 8264 8264
dutime: 0 8264 8264
So I have a new problem before going any further with fine tuning the time calculation, I need a way to make a process consume more processor time(even by starving other processes).
How to do this, any ideas?
|All times are GMT -5. The time now is 04:31 AM.|