LinuxQuestions.org
Register a domain and help support LQ
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-24-2010, 08:19 AM   #1
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Rep: Reputation: 0
Different results from vmstat and ps


Hi all, I am trying to determine CPU usage on a radio controller running Linux. We have a script that another member of my work wrote using vmstat which I could not get any consistant results from. So, in an effort to understand what was going on I wrote a script using ps. Sadley after running several tests using both scripts, they do no match up at all, vmstat always gives me a much higher value. However, if I simply run the commands at any given time they do match up, therefore I believe that there is an error in one of the scripts. I am very new to linux and so I would very much appriciate a learned eye to look over these.

Here is the vmstat script:

#!/bin/bash

declare -i total
declare -i tries

tries=0
total=0

while [ $total -le 0 ]
do
if [ $tries -gt 6 ]; then
echo "You've tried entering a number $tries now. Maybe you should take a break and try again later."
exit
fi

if [ $tries -gt 3 ]; then
echo "Really? $tries attempts later and you're still not entering a number?"
fi

if [ $tries -gt 0 ]; then
if [ $tries -le 3 ]; then
echo "How about you enter a number this time?"
fi
fi

if [ $tries -le 0 ]; then
echo "How many seconds do you want the monitor to run for?"
fi

read total
tries="$(expr $tries + 1)"
done

vmstat -n 1 >> vmstat.log &

sleep 0.3

vmstat -n 1 >> vmstat.log &

sleep 0.3

vmstat -n 1 >> vmstat.log &

start="$(date +%s)"
elapsed=0
lastreport=0
report=0

cat /dev/null > vmstat.log

while [ $elapsed -lt $total ]
do
#date --rfc-3339=ns >> vmstat.log
#vmstat -n >> vmstat.log

end="$(date +%s)"

elapsed="$(expr $end - $start)"

report="$(expr $total - $elapsed)"

if [ $lastreport -ne $report ]; then
lastreport=$report
echo "$lastreport seconds remaining..."
fi

sleep 0.25
done

killall vmstat

echo "Finished"
========================================================================

And here is the ps script that I wrote:

#!/bin/bash
# Test script to log each running process and it's CPU utilization.

#empty the log file
cat /dev/null > psstats.log

# Read in user input for test duration.
echo "How long would you like to run the test in seconds?"
read time

#Variables for timing
start="$(date +%s)"
elapsed=0
oldelapsed=0
lastreport=0
report=0

#Loop to run for a specific number of seconds given by the user above.
while [ $elapsed -lt $time ]
do

end="$(date +%s)"

oldelapsed=$elapsed

elapsed="$(expr $end - $start)"

report="$(expr $time - $elapsed)"

#If time has not elapsed or if an entire second has passed perform the test.
if [ $elapsed -eq 0 ] || [ $oldelapsed -eq $(expr $elapsed - 1) ] && [ $report -gt 0 ]; then
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log
echo $(expr $elapsed + 1) >> psstats.log
ps -eo pcpu,pmem,vsz,pid,user,args >> psstats.log &
sleep 0.3
echo "===============================" >> psstats.log

fi

#Print out remaining time per second.
if [ $lastreport -ne $report ]; then
lastreport=$report
if [ $lastreport -ge 10 ]; then
echo "$lastreport seconds remaining..."
else
echo "0$lastreport seconds remaining..."
fi
fi
done

echo "Finished"
 
Old 06-25-2010, 12:43 PM   #2
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Reposting on General...
 
Old 06-25-2010, 01:07 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by alburdet619 View Post
Reposting on General...
wrong answer!!--double-posting not allowed
 
Old 06-25-2010, 04:12 PM   #4
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
My bad, just trying to get an answer for work and hadn't gotten a response in over a day... oh well i'll just be patient. Sorry to ruffle feathers.
 
Old 06-26-2010, 06:46 AM   #5
halvy
Member
 
Registered: Aug 2005
Location: Anchorage, Alaska (soon EU, hopefully)
Distribution: Anything NOT SystemD (ie. M$) related.
Posts: 918

Rep: Reputation: 41
Had any luck?

What have you tried so far?

The only suggestion that comes to mind is the two programs are just that.. two different programs, with possibly different nice settings, etc.. which if not completely aligned.. will give different answers.

Sorry I cannot think of anything better.

Lettuce know..
 
Old 06-26-2010, 08:16 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,037

Rep: Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912
I really don't undestand what you're trying to achieve.
If you want to know what the (entire) system has done over a period, probe /proc/stat at the beginning and end of the period. A small amount of basic maths will sort the numbers out.

Or try collectl - it maintains process data, but may be overkill for you.
 
Old 06-26-2010, 11:11 AM   #7
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Haven't had much time to work on this, our product went beta in the last few days so testing has been more urgent. Like I said i'm very green on Linux so i'm not sure what the nice settings are, i'm guessing command line options? As far as I have been able to test it seems like it's definatly a problem in the code of one of them. As I said earlier running the same command line functions with the same options as in the programs gives very consistant results. However the scripts run simultaniously gives very differing results... I don't know what to think other than i'm not giving the correct command line options to ps, however I have tested most of thos from the man file and haven't found any that give me more processes than I get with the -e option.
 
Old 06-26-2010, 11:20 AM   #8
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
I really don't undestand what you're trying to achieve.
The system i'm testing is a Voice over IP radio controler, and by making radio calls using the system and monitoring the CPU usage i'm hoping to get a projection for maximum simultanious radio calls. Memory is not an issue, these calls take very little, however CPU gets eaten up the more calls that are currently on the system.

Therefore, my company had the above script using vmstat to take a sample very 1/3 of a second for however many seconds the user desires. However, upon running this the results were very erratic and inconsistant.

So, I am attempting to root cause this problem by writing my own script using ps to see what processess cause this erratice CPU usage.
 
Old 06-26-2010, 08:04 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,037

Rep: Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912
Running multiple processes to scan /proc/ (after all that's what both vmstat and ps actully do) is always going to be dodgy. Despite your attempts to separate them by a third of a second, their dispatch after that is at the whim of the scheduler. They won't be at exactly 0.3 apart - and they'll be separate processes competing with everything else.
Go get collectl.
 
1 members found this post helpful.
Old 06-28-2010, 09:32 AM   #10
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
Go get collectl.
I'm gonna try this if I get time, it sounds like a much better program than either vmstat or ps. Thanks for the suggestion, i'll let you know how it works out.
 
Old 06-28-2010, 12:02 PM   #11
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Okay, so the big problem is that we are running Wind River which is not a very popular linux platform. I don't know, and doubt, that collectl would work on Wind River and we can't even compile it because we don't have a compiler that works with Wind River. Any suggestions/help with this?
 
Old 06-28-2010, 12:03 PM   #12
alburdet619
LQ Newbie
 
Registered: Jun 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Nevermind, another guy at work got it to work! So I will play with that thanks everyone!
 
  


Reply


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
vmstat question Robhogg Linux - General 3 04-10-2009 06:00 PM
vmstat lucifer_smiles Linux - Server 1 01-29-2008 07:09 PM
issue with VMSTAT Linux_Kidd Red Hat 1 12-30-2006 07:15 AM
vmstat UltraSoul Solaris / OpenSolaris 9 07-14-2006 11:11 PM
regarding vmstat output cnkhandar Linux - Newbie 1 07-07-2006 09:01 AM


All times are GMT -5. The time now is 04:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration