home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-02 | 2.0 KB | 95 lines | [TEXT/CWIE] |
- unit MySimpleProfile;
-
- interface
-
- uses
- Types;
-
- type
- MarkString = string[9];
-
- procedure StartupSimpleProfile;
- procedure MarkProfile(mark:MarkString);
-
- implementation
-
- uses
- Files,Timer,ToolUtils, MyMemory, MyStartup;
-
- const
- max_profile_marks = 1000;
-
- type
- ProfileMark=record
- mark:MarkString;
- time:longInt;
- end;
- ProfileMarksArray=array[1..max_profile_marks] of ProfileMark;
- ProfileMarksArrayPtr=^ProfileMarksArray;
-
- var
- start_time: UnsignedWide;
- profile_mark:longInt;
- profile_marks:ProfileMarksArrayPtr;
-
- procedure MarkProfile(mark:MarkString);
- var
- current_time: UnsignedWide;
- begin
- if (profile_marks<>nil) & (profile_mark<max_profile_marks) then begin
- Microseconds(current_time);
- Inc(profile_mark);
- profile_marks^[profile_mark].mark := mark;
- profile_marks^[profile_mark].time := current_time.lo - start_time.lo;
- end;
- end;
-
- function InitSimpleProfile(var msg: integer): OSStatus;
- begin
- msg := msg; { Unused }
- profile_mark := 0;
- InitSimpleProfile := MNewPtr(profile_marks, SizeOf(ProfileMarksArray));
- end;
-
- procedure FinishSimpleProfile;
- var
- fs:FSSpec;
- junk,err:OSErr;
- i:longInt;
- rn:integer;
- s,t:Str255;
- lasttime,thistime:longInt;
- count:longInt;
- begin
- junk:=FSMakeFSSpec(-1,2,'Profile Dump',fs);
- junk:=FSpDelete(fs);
- if profile_mark > 0 then begin
- err := FSpCreate(fs,'R*ch','TEXT',0);
- err := FSpOpenDF(fs,fsRdWrPerm,rn);
- if err=noErr then begin
- lasttime := profile_marks^[1].time;
- for i := 1 to profile_mark do begin
- s := profile_marks^[i].mark;
- thistime := profile_marks^[i].time;
- NumToString(thistime,t);
- s := concat(s, chr(9), t);
- NumToString(thistime-lasttime,t);
- s := concat(s, chr(9), t);
- lasttime := thistime;
- s := concat(s, chr(13));
- count := length(s);
- err := FSWrite(rn, count, @s[1]);
- end;
- junk := FSClose(rn);
- end;
- end;
- MDisposePtr(profile_marks);
- end;
-
- procedure StartupSimpleProfile;
- begin
- SetStartup(InitSimpleProfile, nil, 0, FinishSimpleProfile);
- end;
-
- end.
-