Get CPU Usage

Please discuss general Delphi programming topics here.

Get CPU Usage

Postby Gullb3rg » January 5th, 2007, 12:44 am

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.
Gullb3rg
Member
Member
 
Posts: 4
Joined: October 26th, 2006, 3:31 pm

Performance counters (component)

Postby eashton » January 24th, 2007, 9:44 pm

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
eashton
Active Member
Active Member
 
Posts: 8
Joined: January 24th, 2007, 7:16 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron