unit debugandprofile;

interface
uses windows,sysutils;
procedure startprofiletimer(name : string);
procedure endprofiletimer;

type tprofilerec = record
  name : string;
  starttime : dword;
end;

var
timerstack : array[0..100] of tprofilerec;
stackcount : integer=-1;


implementation

procedure startprofiletimer(name : string);
var
mes : string;
begin
inc(stackcount);
timerstack[stackcount].starttime:=gettickcount;
mes:='PROFILE START: '+name+' @ '+inttostr(timerstack[stackcount].starttime);
timerstack[stackcount].name:=name;
outputdebugstring(pchar(mes));
end;

procedure endprofiletimer();
var
t : dword;
mes : string;
begin
t:=gettickcount;
mes:='PROFILE END: '+timerstack[stackcount].name+' @ '+inttostr(t)+' ELAPSED: '+inttostr(t-timerstack[stackcount].starttime);
outputdebugstring(pchar(mes));
if stackcount>0 then dec(stackcount);
end;

end.