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:

 CreationTime, ExitTime, KernelTime, UserTime: FileTime;
i: integer;

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.
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
  SD : TSystemTime;
  Result := SystemTimeToDateTime(SD);

use this in your calculation

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

hope this helps


redforceAuthor Commented:
Adjusted points to 10
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

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()

redforce, are you here?
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?
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

All Courses

From novice to tech pro — start learning today.