Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get my application running time?

How to find out the time that my application is running since it started?

like image 265
Little Helper Avatar asked Dec 04 '22 05:12

Little Helper


1 Answers

Try the GetProcessTimes function

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Windows,
  SysUtils;

function FileTime2DateTime(FileTime: TFileTime): TDateTime;    //Convert then FileTime to TDatetime format
var
  LocalTime: TFileTime;
  DOSTime  : Integer;
begin
  FileTimeToLocalFileTime(FileTime, LocalTime);
  FileTimeToDosDateTime(LocalTime, LongRec(DOSTime).Hi, LongRec(DOSTime).Lo);
  Result := FileDateToDateTime(DOSTime);
end;

Var
  lpCreationTime, lpExitTime, lpKernelTime, lpUserTime: TFileTime;

begin
  try
    GetProcessTimes(GetCurrentProcess,lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
    Sleep(1000); //do something

    Writeln(Format('Running Time %s',[FormatDateTime('hh:nn:ss.zzz',Now-FileTime2DateTime(lpCreationTime))]));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
like image 86
RRUZ Avatar answered Dec 22 '22 10:12

RRUZ