LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 12-12-2015, 01:16 AM   #1
AnkitAg
LQ Newbie
 
Registered: Dec 2015
Posts: 1

Rep: Reputation: Disabled
Cool Ways to get CPU Utilization on a Linux machine


I am running Ubuntu 14.04 on my machine. I need to get the CPU utilization for a process running at a required monitoring interval.

I have tried the following have a few questions about them.
I considered calculating the effective usage between 2 points as follows:

Process run time(P) = utime + stime + cstime + cutime

Total CPU run time(C) = I am getting this value from /proc/stat.

Considering a monitoring interval t, CPU utilization is calculated as

CPU usage = ( P2 - P1 ) / (C2 - C1 ) * 100


Issue:
  1. The value CPU usage read comprises the sum total of all 4 ( on my machine ) cores. But top shows a value divided by 4. I found that there is an Irix mode which if turned on( by default ) gives values multiplied by 4. What I want to know is that which value is correct ? Should I multiply my value by 4 ?.
  1. I want to get the usage at sampling periods of lets say 1ms. But apparently /proc/stat is not updated at the same rate, and nether is top. What is the smallest sampling period that I can go down to with using this method ?
  2. Please let me know. Also if any other sugestions, please let me know. Also can we write a kernel module to do the same at my required sampling rate ? Does any such module exists ?

Thanks
Ankit
 
Old 12-12-2015, 11:32 AM   #2
Keruskerfuerst
Senior Member
 
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199

Rep: Reputation: 164Reputation: 164
I think the following:

Processors are numbered as follows:

P1: processor 1
P2: processor 2
P3: processor 3
P4: processor 4
...
PN: processor N

Average:

(P1+P2+P3+P4+...+PN)/N = average of cpu utilization.

I think you can have a look at the source code of "top".
 
  


Reply



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
High Run queue utilization although CPU utilization is low.. rajeprag Linux - Server 0 08-18-2013 09:44 AM
how to find all processes cpu utilization & the cpu processor in linux? vasanth.v999 Linux - Server 7 01-10-2012 08:43 AM
Linux desktop GUI tool for CPU utilization and bandwidth utilization karimasif Linux - Software 4 03-03-2008 01:09 PM
Distributing CPU utilization in LINUX paragkalra Linux - Networking 1 12-13-2007 02:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:48 AM.

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