Page 1 of 1

Get CPU Usage

PostPosted: January 5th, 2007, 12:44 am
by Gullb3rg
Hi!
I have tried to rewrite this: http://www.swissdelphicenter.ch/torry/s ... php?id=969 , so it just gives me the CPU usage. This is how my code look like: http://qndelphi.pastebin.ca/306009. The code works in a label but when i try to get the code to a Gauge it gives me some acces violation.
If someone know my problem or has a easier way to get CPU usage i woul'd be very glad.

Performance counters (component)

PostPosted: January 24th, 2007, 9:44 pm
by eashton
I have been using the components from the following site:

http://www.wilsonc.demon.co.uk/delphi.htm

You need to download and install the following:
1. lanmanutils;
2. miscunits;
3. miscutils;
4. ntcomp; and
5. ntutils.

There is a demo project included.

The other thing to consider is what you are doing with the value that you are receiving from getcpuusage.

I apologise in advance if you already know this but the figure that you are getting is a string (originally a double) which needs to be converted to an integer because this is what the gauge requires (assumes you are using tgauge but progressbar and trackbar also require an integer). This is the routine I use to convert (there is probably a better one!):

function floatToInt(dblFigure: double): integer;
var
intRoundedFigure: int64;
begin
intRoundedFigure := round(dblFigure);
result := intRoundedFigure mod 65536;
end;

With the returned figure apply that to your gauge.

Hope this helps.

Cheers
Elliot