LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Measure CPU usage after renice (http://www.linuxquestions.org/questions/linux-newbie-8/measure-cpu-usage-after-renice-4175413574/)

DKSL 06-26-2012 09:57 PM

Measure CPU usage after renice
 
Hi all,

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?

DK

towheedm 06-26-2012 10:27 PM

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.

syg00 06-26-2012 10:34 PM

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.

DKSL 06-27-2012 03:01 AM

Quote:

Originally Posted by towheedm (Post 4712966)
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.

Yes top commands TIME/TIME+ give the time a process has spent on the CPU. However I am using this in android and top dosen't have all the fields and dosen't support the interactive keys. What is the proper way to compile the top.c file. I tried to compile(on ubuntu) it gives lot of undefined errors.

Quote:

Originally Posted by syg00 (Post 4712973)
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.

I looked in to the /proc/<pid>/stat and found a code to display the output in a more readable form :) There are many time values what should I be looking for getting the processes time spent on CPU(or increase or decrease after a renice).

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
pid: 1142
tcomm: (com.test.noise3)
state: S
ppid: 37
pgid: 37
sid: 0
tty_nr: 0
tty_pgrp: -1
flags: 4194624
min_flt: 6040
cmin_flt: 0
maj_flt: 0
cmaj_flt: 0
utime: 11.590000
stime: 7.790000
cutime: 0.000000
cstime: 0.000000
priority: 20
nice: 0
num_threads: 8
it_real_value: 0.000000
start_time: 06.25 15:24 (2698.61s)
vsize: 137080832
rss: 5090
rsslim: 4294967295
start_code: 32768
end_code: 36524
start_stack: 3199794400
esp: 3199793352
eip: 2949704456
pending: 0000000000000000
blocked: 0000000000001204
sigign: 0000000000000000
sigcatch: 00000000000094e8
wchan: 4294967295
zero1: 0
zero2: 0
exit_signal: 0000000000000011
cpu: 0
rt_priority: 0
policy: 0
#

syg00 06-27-2012 05:25 AM

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.

DKSL 06-27-2012 10:27 AM

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 def:
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 def:
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?

DKSL 06-27-2012 03:28 PM

I tried the above logic. calculated the delta utime at 5 second intervals. These are the results,

pid: 263
dutime: 8 7786 7778
priority: 10
nice: -10

pid: 263
dutime: 8 7794 7786
priority: 15
nice: -5

pid: 263
dutime: 7 7801 7794
priority: 15
nice: -5

pid: 263
dutime: 4 7805 7801
priority: 15
nice: -5

pid: 263
dutime: 9 7814 7805
priority: 15
nice: -5

pid: 263
dutime: 8 7822 7814
priority: 5
nice: -15

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,

pid: 263
dutime: 9 8264 8255
priority: 5
nice: -15

pid: 263
dutime: 0 8264 8264
priority: 5
nice: -15

pid: 263
dutime: 0 8264 8264
priority: 5
nice: -15

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 08:51 AM.