How to handle FileTime format

I want to use the API function GetProcessTimes. I send all running processes to that funktion and want to know the CPUusage.
The problem is that getprocesstimes uses the Filetime Format. I dont know how to handle it. I need a formula that changes the value to percentages.

I use following to get the values:

var
PH:THandle;
 CreationTime, ExitTime, KernelTime, UserTime: FileTime;
i: integer;

begin
for i:=1 to numberofprocesses do begin
GetProcessTimes(PH, CreationTime, ExitTime, KernelTime, UserTime);

.... //Here a need the formula

I know the number of processes, but I don't know how to handle the values.
Could you help me about the formula to convert the values to get percentages?
My system has two CPUs. I like to view the usage for both CPUs seperatly.
redforceAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
hi again redforce,

here the conversions,
i guess, if you convert the filetime to Datetime, you can use your calculation without any changes

sample function

Function FileTimeToDateTime(FD : TFileTime) : TDatetime
var
  SD : TSystemTime;
begin
  FileTimeToSystemTime(FD,SD);
  Result := SystemTimeToDateTime(SD);
end;

use this in your calculation

(FileTimeToDateTime(lpkerneltime) + FileTimeToDateTime(lpusertime)) div (number of processors * FileTimeToDateTime(lpcreationtime) - FileTimeToDateTime(lpexittime))

hope this helps

meikl

0
 
redforceAuthor Commented:
Adjusted points to 10
0
 
kretzschmarCommented:
hi redforce,

you can transform the filetime with the api function FiletimeToSystemtime (or similar) to Systemtimeformat, then delphi has a function, if needed, SystemtimeToDateTime to transform Systemtime to Datetimeformat. let me know if you need a sample

meikl
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
redforceAuthor Commented:
An example wouldn't be bad. I've changed format to double with these functions. but I dont know how to use these values to get to the used Systemtime.

I've got the following formula. (I don't know if it works)

(lpkerneltime + lpusertime) div (number of processors * lpcreationtime - lpexittime)

All values are from getprocesstimes()


0
 
kretzschmarCommented:
redforce, are you here?
0
 
redforceAuthor Commented:
Sorry meikl, weekend ... I was away.
I tried your corversation function and it works.
You get the points.
But by the way: the values I get when running the formula couldn't be right.
something vith 4194629. A little worse isn't it? Do you think the formula is right? The funniest thing: the value changes only if I start a new process (4194629 - 1). This can't be the right formula to view the actuel CPU Usage.
Do you know the solution?
 
0
 
kretzschmarCommented:
hi redforce,

well, i never looked at the api-call u use,
but i will take a closer look to it.

this can take a bit time,
because it becomes night here.

dont worry about the values,
because the datetime-typ counts at 31.12.1899.

i leave this q open,
maybe i can provide a working sample.

until then

meikl
0
All Courses

From novice to tech pro — start learning today.