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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.