home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-09 | 2.4 KB | 112 lines | [TEXT/CWIE] |
- unit MySimpleProfile;
-
- interface
-
- uses
- Types;
-
- procedure StartupSimpleProfile;
- procedure MarkProfile(mark:Str15);
-
- implementation
-
- uses
- Files,Timer,ToolUtils, TextUtils, Memory,
- MyMemory, MyStartup;
-
- const
- max_profile_marks = 10000;
-
- type
- MarkString = string[9];
-
- type
- ProfileMark=record
- time:longint;
- mark:MarkString;
- end;
- ProfileMarksArray=array[1..max_profile_marks] of ProfileMark;
- ProfileMarksArrayPtr=^ProfileMarksArray;
-
- var
- start_time: UnsignedWide;
- profile_mark:longint;
- profile_marks:ProfileMarksArrayPtr;
-
- procedure MarkProfile(mark:Str15);
- 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
- {$unused(msg)}
- profile_mark := 0;
- InitSimpleProfile := MNewPtr(profile_marks, SizeOf(ProfileMarksArray));
- end;
-
- procedure FinishSimpleProfile;
- var
- rn:integer;
- data: Handle;
- procedure FlushHandle;
- var
- err: OSErr;
- count: longint;
- begin
- count := GetHandleSize( data );
- HLock( data );
- err := FSWrite(rn, count, data^);
- HUnlock( data );
- SetHandleSize( data, 0 );
- end;
- var
- fs:FSSpec;
- junk,err:OSErr;
- i:longint;
- s,t:Str255;
- lasttime,thistime: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
- data := NewHandle( 0 );
- 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));
- err := PtrAndHand( @s[1], data, length(s) );
- if GetHandleSize( data ) > 8192 then begin
- FlushHandle;
- end;
- end;
- FlushHandle;
- junk := FSClose(rn);
- end;
- end;
- MDisposePtr(profile_marks);
- end;
-
- procedure StartupSimpleProfile;
- begin
- SetStartup(InitSimpleProfile, nil, 0, FinishSimpleProfile);
- end;
-
- end.
-