Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 26, 2009, 07:00 AM   #1
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Accurately measuring the current load on a Mac

I'm trying to add a little feature that takes the current load on a computer and then sends it back to a central server (same computer or different computer it does not really matter) and then the server routes network requests based on the load of the registered servers with it.

What is the best way of getting current load on a Mac for a system such as this? It is a C only application I am afraid so no Cocoa / Objective-C.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Jun 26, 2009, 09:45 AM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);
That gives the three load values like you see in:

Code:
TwinTurboG5:~ nerfle$ uptime
 9:44  up 23:22, 2 users, load averages: 1.45 1.31 1.12
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Jun 26, 2009, 10:21 AM   #3
Cromulent
Thread Starter
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by Sayer View Post
Use the stdlib function "getloadavg()" like this:

Code:
double   loads[3];

getloadavg(loads, 3);
That gives the three load values like you see in:

Code:
TwinTurboG5:~ nerfle$ uptime
 9:44  up 23:22, 2 users, load averages: 1.45 1.31 1.12
The problem with that is it is not accurate enough. The servers performance will be quite variable and as such I think the load average might not offer the kind of information I need.

I mean obviously it does give you an idea, but it is still reasonably general.

Edit : I guess it might actually do the job if I just call it more than once a minute and take the moving average of the average load over a one minute period.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Jun 26, 2009, 10:28 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Use DTrace to read the kernel load variable? As discussed here...
robbieduncan is offline   0 Reply With Quote
Old Jun 26, 2009, 12:01 PM   #5
Cromulent
Thread Starter
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by robbieduncan View Post
Use DTrace to read the kernel load variable? As discussed here...
Heh, I didn't think DTrace handled things like that. I really need to start trying to understand it better. Thanks for the link.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help! Web pages won't load on my Mac Pro jer2eydevil88 OS X 15 Yesterday 06:46 PM
What is the current consensus on the Boxee Box? danny_w Apple TV and Home Theater 13 Feb 19, 2011 06:39 PM
What is the C drive on a mac? and cache? grosslyclever Mac Basics and Help 6 Jan 26, 2011 08:12 PM
How accurate are the temps displayed on iStat Pro? pilotkid MacBook Pro 0 Jun 15, 2010 02:25 AM
problems with pogramme loaded on my mac benney50 Mac Help/Tips 2 Apr 15, 2003 05:21 AM


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

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC