The MP3car.com Store  

Welcome to the MP3Car.com forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   MP3Car.com > Mp3Car Technical > MacCar

Reply
 
Thread Tools Display Modes
Old 01-16-2008, 09:16 AM   #1
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
Getting CPU load, memory info etc.

Is there a way of getting the system information using ObjC/Cocoa or AppleScript? I need to get the info that is normally provided by top in logging mode, but there seems to be a bug in the OS X that prevents me from re-directing grepped output to a file.

top -l 0 > test.txt - works
top -l 0 | grep Load - works
top -l 0 | grep Load > test.txt - DOES NOT WORK :-(
Jirka Jirout is offline   Reply With Quote
Sponsored Links
Old 01-16-2008, 10:07 AM   #2
CarFrontEnd Creator
iamgnat's CarPC Specs
 
iamgnat's Avatar
 
Join Date: Jul 2004
Location: NoVA
Vehicle: 04 Ford Escape
Posts: 846
My Photos: (0)
Sort of (it C code), I don't have it with me though and I can't remember the detail that the example goes into.

If you don't already have it, Amit Singh's Mac OSX Internals is great for this type of info.

-dave

EDIT: The other option is to go grab the source code to top and see how they do it

EDIT 2: Your -l argument is the problem. Change it from 0 to 1. The issue is that with 0, it keeps outputting and redirections don't like that. If that is what you really want (e.g. so you aren't constantly running the top command), then execute the command through a file handle and run it through a select loop to process the data.
__________________
My pathetic worklog.
CarFrontEnd (now it's own sub-forum!!!!)

Last edited by iamgnat : 01-16-2008 at 10:12 AM.
iamgnat is offline   Reply With Quote
Old 01-16-2008, 11:02 AM   #3
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
I am using an NSTask to run this, getting it's standard output. Unfortunately, there is nothing written to standard output. I have a similar script to monitor the disk space (also constantly outputting something every few seconds) and that one works fine:

Code:
#!/bin/sh while [ 1 ] do df -l | grep \/ sleep 3 done

But I will try the 1 parameter for -l and using a loop in my own script.
Jirka Jirout is offline   Reply With Quote
Old 01-16-2008, 11:38 AM   #4
CarFrontEnd Creator
iamgnat's CarPC Specs
 
iamgnat's Avatar
 
Join Date: Jul 2004
Location: NoVA
Vehicle: 04 Ford Escape
Posts: 846
My Photos: (0)
Quote: Originally Posted by Jirka Jirout View Post
I am using an NSTask to run this, getting it's standard output. Unfortunately, there is nothing written to standard output.

If you are running the NSTask with the -l 0, it is buffering the output until the task completes (which it never will with the 0 argument).

EDIT: Actually it looks like i'm wrong on that. You should be seeing output to the standardOutput handle from a NSTask object. If you post the snippet in question (launching, looping, etc..), i'll be happy to take a look and see if anything jumps out.

I can't work up an example now (I can tell you the Perl code off the top of my head, but I don't do it that often in C ), but I will try to remember tonight when I get home.

-dave
__________________
My pathetic worklog.
CarFrontEnd (now it's own sub-forum!!!!)

Last edited by iamgnat : 01-16-2008 at 11:42 AM.
iamgnat is offline   Reply With Quote
Old 01-18-2008, 03:28 AM   #5
atl
Newbie
atl's CarPC Specs
 
atl's Avatar
 
Join Date: Nov 2005
Location: Germany
Vehicle: 1995/Audi/A6 & 2003/Audi/A4 Cabrio
Posts: 38
My Photos: (1)
HI,

to get CPU usage and other system related stuff from command line tools, normally you have to put the output of these tools into a pipe and read the pipe from your application. You can't run these tools with parameters for 1 sample (like "top -l 1"), because the start of the tool creates higher cpu usage and the output is forged.

If you have Dashcode you can create an sample Widget from a template for a meassurement widget (in german called "Messgeraet"). This creates sample code for watching cpu usage in Javascript. But it should be not so difficult to do the same in Cocoa/ObjectC.

I've done nearly the same via AppleScript. But because of the lack of pipes I had to use a temporary file.

ByE...
atl is offline   Reply With Quote
Old 01-18-2008, 05:38 AM   #6
QCar Creator
Jirka Jirout's CarPC Specs
 
Jirka Jirout's Avatar
 
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
My Photos: (0)
Well, what I ended up with for now is this:

Code:
#!/bin/sh while [ 1 ] do top -l 1 | grep -e Load -e PhysMem -e QCar sleep 1 done

But the issue with load caused by start of top is certainly a valid one and I have forgotten about it. This could also be the reason why this script always returns 0% as the CPU load for QCar process.

So I will have to use the top sources from Darwin to build this completely in Cocoa after all...
Jirka Jirout is offline   Reply With Quote
Old 01-18-2008, 07:52 AM   #7
atl
Newbie
atl's CarPC Specs
 
atl's Avatar
 
Join Date: Nov 2005
Location: Germany
Vehicle: 1995/Audi/A6 & 2003/Audi/A4 Cabrio
Posts: 38
My Photos: (1)
The disadvantage of coding a tool what reads the current CPU usage once and quit is, that it has to wait some time before getting a acceptable value. Because the tool by itself rise the CPU and System usage on start (allocate resources, ...).

I have used iostat to get the CPU usage. From my AppleScript application I run the command
Code:
/usr/sbin/iostat -Iw1 -n0

and redirect the output into a file on a ramdisk. From this file I read regulary the last line and get the CPU usage from it. The RAM disk will be created on start of the application and destroyed on quit.

I hope this helps you. The best would be, you redirect the output into a pipe. This should possible in Cocoa/ObjectC, because it's also possible in JavaScript.


ByE...
atl is offline   Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Speed up Road Runner JohnWPB RR FAQ 4 09-15-2007 01:58 PM
Moderate to High CPU Usage....Looking For Additional Guidance.... jmciver Road Runner 19 12-15-2006 10:34 PM
Can you load WinXP onto a memory stick? Udonboy General Hardware Discussion 14 09-06-2004 08:11 AM
load soft ware to usb hard disk then load to comp tracker92 General Hardware Discussion 1 08-29-2004 06:57 PM
for those looking to decrease memory load from xp saikano Software & Software Development 16 07-18-2004 06:05 PM


All times are GMT -5. The time now is 08:55 AM.


Sponsored Links
The MP3car.com Store

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0
Copyright © 1999 - 2008 Mp3Car.com Inc.
Ad Management by RedTyger
Message Board Statistics