LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-26-2012, 09:57 PM   #1
DKSL
LQ Newbie
 
Registered: Apr 2012
Posts: 29

Rep: Reputation: Disabled
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
 
Old 06-26-2012, 10:27 PM   #2
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
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.
 
1 members found this post helpful.
Old 06-26-2012, 10:34 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,378

Rep: Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190
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.
 
1 members found this post helpful.
Old 06-27-2012, 03:01 AM   #4
DKSL
LQ Newbie
 
Registered: Apr 2012
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by towheedm View Post
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 View Post
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
#

Last edited by DKSL; 06-27-2012 at 03:14 AM.
 
Old 06-27-2012, 05:25 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,378

Rep: Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190Reputation: 4190
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.
 
Old 06-27-2012, 10:27 AM   #6
DKSL
LQ Newbie
 
Registered: Apr 2012
Posts: 29

Original Poster
Rep: Reputation: Disabled
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?
 
Old 06-27-2012, 03:28 PM   #7
DKSL
LQ Newbie
 
Registered: Apr 2012
Posts: 29

Original Poster
Rep: Reputation: Disabled
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?
 
  


Reply

Tags
cpu, measurement, top


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a standard way to measure CPU usage. ufmale Programming 4 03-19-2008 08:41 AM
tool to measure cpu/memory usage by a process saritha Linux - Software 1 10-08-2007 06:16 AM
need top clone- to measure CPU usage pao Linux - Software 4 10-07-2004 09:46 AM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
measure memory usage unosoft Linux - Software 1 10-07-2003 06:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration