Read CPU Speed & Usage

Hi All,

I need some support reading CPU speed and usage cross platform, I can see that for OSX and Linux using MBS plugins I can get the CPU speed but unable to read its usage,

Does anyone have any pointers they can give me for finding this information out about the clients machine?

Many thanks in advance,
Steve

By usage, you mean the percentage used of each processor at any given moment?

Yes please, or exact Mhz either.

CPU Usage : command line : Top command gives you a complete report.

[code]Processes: 170 total, 2 running, 7 stuck, 161 sleeping, 726 threads 13:13:48
Load Avg: 1.00, 1.04, 1.13 CPU usage: 3.78% user, 2.83% sys, 93.38% idle
SharedLibs: 12M resident, 9264K data, 0B linkedit.
MemRegions: 25740 total, 1601M resident, 110M private, 470M shared.
PhysMem: 3738M used (829M wired), 354M unused.
VM: 389G vsize, 1066M framework vsize, 0(0) swapins, 0(0) swapouts.
Networks: packets: 207019/216M in, 147607/11M out.
Disks: 280230/7316M read, 188226/4891M written.

PID COMMAND %CPU TIME #TH #WQ #PORT #MREG MEM RPRVT PURG
1464 top 5.3 00:03.24 1/1 0 22 37 2000K 1772K 0B
1460 bash 0.0 00:00.03 1 0 19 30 788K 644K 0B
1459 mdworker 0.0 00:00.04 3 0 52 60 2636K 1884K 0B
1458 CVMCompiler 0.0 00:00.23 2 1 31 69 14M 14M 12K
1457 login 0.0 00:00.06 2 0 30 46 1100K 792K 0B
1455 Terminal 10.6 00:00.61 7 1 176 158 10M+ 7768K+ 8192B
1454- Google Chrom 0.0 00:00.54 10 0 149 378 21M 16M 0B
1452 ocspd 0.0 00:00.00 2 0 22 34 800K 480K 0B
1451- Google Chrom 0.0 00:02.99 10 0 149 425 37M 33M 496K
1441- Google Chrom 0.0 00:02.17 10 0 149 401 27M 22M 256K
1437- Google Chrom 0.0 00:06.95 10 0 149 412 37M 32M 204K
1365 TM_Notifier 0.0 00:00.16 3 0 128 92 3468K 2268K 0B
1357 installd 0.0 00:00.35 2 0 49 184 22M 22M 0B
932 DataDetector 0.0 00:00.02 2 0 52 51 1772K 760K 0B[/code]

http://www.monkeybreadsoftware.net/class-darwinvmstatisticsmbs.shtml

CPU Ticks properties here.

System_profiler (Mac only) will show you an entire truck load of information, amongst which you find here :

[code]Hardware:

Hardware Overview:

  Model Name: iMac
  Model Identifier: iMac12,1
  Processor Name: Intel Core i5
  Processor Speed: 2.5 GHz
  Number of Processors: 1
  Total Number of Cores: 4
  L2 Cache (per Core): 256 KB
  L3 Cache: 6 MB
  Memory: 4 GB
  Boot ROM Version: IM121.0047.B1F
  SMC Version (system): 1.71f21
  Serial Number (system): C17FJDZRDHJF
  Hardware UUID: 8437B548-0E2A-51E0-88C3-5F3D6CDC841F[/code]

There is an example included with Xojo that shows you how to get the CPU usage (using a Declare) on Windows:

Examples/Platform-Specific/Windows/CPUUsage

For Linux system information including CPU characteristics

cat /proc/cpuinfo

Thank you everyone for your support I will let you know how I get on,

How can I then take only the info I require from a CAT command?

Cheers,

Hi Christian,

How can I work out Mhz and used Mhz of the processor with http://www.monkeybreadsoftware.net/class-darwinvmstatisticsmbs.shtm

Cheers

[quote=93005:@Steven Church]Thank you everyone for your support I will let you know how I get on,

How can I then take only the info I require from a CAT command? [/quote]

Use the shell.result property and parse it.

I’m also trying to read the CPU useage on the three platforms. I think this thread is uncomplete, thus I think it would be a good idea to complete it.
Currently, the Windows version works, with the example included.
For Linux, the cat /proc/cpuinfo command returns useful data about the CPU (brand, speed, etc.) but nothing about the current percentage of CPU used.
On the Mac, the DarwinVMStatisticsMBS class seems to return useful information, but the documentation just states to calculate deltas like in the example; yet, I fail to find the example file (the one about DarwinVMStatistics lacks the CPU ticks field).

It would be nice to have a definitive answer to read CPU useage.

I’m also trying to read the CPU useage on the three platforms. For the sake of completeness, here’s what I’ve found:

On the Mac, the DarwinVMStatisticsMBS class is one way to go, assuming you have purchased the plugin. An example can be found in /MacOSX/CPU load info.xojo_binary_project.

The Windows version, already mentioned in this thread, works fine, with the example included with Xojo.

For Linux, the cat /proc/cpuinfo command returns useful data about the CPU (brand, speed, etc.) but nothing ovious about the current percentage of CPU used. However, this command does that:
“grep 'cpu ’ /proc/stat | awk ‘{usage=($2+$4)*100/($2+$4+$5)} END {print usage}’”

HTH