Recent

Author Topic: current cpu load  (Read 5349 times)

Del4ev

  • Newbie
  • Posts: 2
current cpu load
« on: May 18, 2010, 02:14:37 pm »
Hi,

Is there any cross-platform way to get current CPU load in percentage?
if no, how to get this load in linux and win separately {$ifdef linux}...{$endif} {ifdef win32}...{$endif}

for example, my program should work only if current cpu less than 10%

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: current cpu load
« Reply #1 on: May 19, 2010, 08:20:48 am »
You could evaluate output of "top" for Linux.
But I don't think your approach is well elaborated. If CPU usage falls below 10% and your program runs some calculation usage would raise to 100%, unless you implement sleep() cycles. It's a to do or not to do situation. Maybe you should think about threading with priority tpIdle.
Lazarus 1.7 (SVN) FPC 3.0.0

kees

  • New Member
  • *
  • Posts: 13
Re: current cpu load
« Reply #2 on: May 20, 2010, 06:20:40 am »
Have a look at sysstat for Linux:
http://pagesperso-orange.fr/sebastien.godard/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12201
  • FPC developer.
Re: current cpu load
« Reply #3 on: May 20, 2010, 08:17:44 am »
Various OSes use different ways to calculate such load numbers. Some factor in kernel time, some not.

(e.g. a BSD system's load number is  typically higher than an equivalent linux system. And that is not technical, just a result of how "load" is calculated).

I wouldn't try to take decisions on such value at all, but if I had to, I wouldn't hardcode the values if I were you, for the above reasons.

Also the meaning varies. Windows puts all CPU power (all cpus and cores combined) at 100%, while *nix loads take 100% as the CPU processing of one core.

 

TinyPortal © 2005-2018