| Last change
 on this file since 380 was             17, checked in by RBRi, 19 years ago | 
        
          | 
+ Library
 | 
        
          | 
              
Property                 svn:eol-style
 set to                 native | 
        
          | File size:
            1.9 KB | 
      
      
| Rev | Line |  | 
|---|
| [17] | 1 | Unit ACLProfile; | 
|---|
|  | 2 | // Crude profiling functions. Accurate to single milliseconds | 
|---|
|  | 3 | // (not just 1/18s). Writes profile to text file called 'profile' in | 
|---|
|  | 4 | // current directory. | 
|---|
|  | 5 | // Call ProfileEvent to log an event with time. | 
|---|
|  | 6 |  | 
|---|
|  | 7 | // Now logs delta times (time used) as well. | 
|---|
|  | 8 | Interface | 
|---|
|  | 9 |  | 
|---|
|  | 10 | procedure StartProfile( const Filename: string ); | 
|---|
|  | 11 |  | 
|---|
|  | 12 | procedure ProfileEvent( const Event: string ); | 
|---|
|  | 13 |  | 
|---|
|  | 14 | procedure StopProfile; | 
|---|
|  | 15 |  | 
|---|
|  | 16 | Implementation | 
|---|
|  | 17 |  | 
|---|
|  | 18 | uses | 
|---|
|  | 19 | {$ifdef os2} | 
|---|
|  | 20 | OS2Def, PMWin, | 
|---|
|  | 21 | {$else} | 
|---|
|  | 22 | Windows, | 
|---|
|  | 23 | {$endif} | 
|---|
|  | 24 | SysUtils; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | var | 
|---|
|  | 27 | ProfileStartTime: ULONG; | 
|---|
|  | 28 | LastProfileTime: ULONG; | 
|---|
|  | 29 | ProfileFile: TextFile; | 
|---|
|  | 30 |  | 
|---|
|  | 31 | const | 
|---|
|  | 32 | Profiling: boolean = false; | 
|---|
|  | 33 |  | 
|---|
|  | 34 | function GetSystemMSCount: ULONG; | 
|---|
|  | 35 | begin | 
|---|
|  | 36 | {$ifdef os2} | 
|---|
|  | 37 | Result:= WinGetCurrentTime( AppHandle ); | 
|---|
|  | 38 | {$else} | 
|---|
|  | 39 | Result:= GetTickCount; | 
|---|
|  | 40 | {$endif} | 
|---|
|  | 41 | end; | 
|---|
|  | 42 |  | 
|---|
|  | 43 | procedure StartProfile( const Filename: string ); | 
|---|
|  | 44 | begin | 
|---|
|  | 45 | if Profiling then | 
|---|
|  | 46 | begin | 
|---|
|  | 47 | ProfileEvent( 'Attempt to start profiling to: ' + Filename ); | 
|---|
|  | 48 | exit; | 
|---|
|  | 49 | end; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | ProfileStartTime:= GetSystemMSCount; | 
|---|
|  | 52 | LastProfileTime:= ProfileStartTime; | 
|---|
|  | 53 | Assign( ProfileFile, Filename ); | 
|---|
|  | 54 | Rewrite( ProfileFile ); | 
|---|
|  | 55 | WriteLn( ProfileFile, | 
|---|
|  | 56 | '---------------------------------------------------' ); | 
|---|
|  | 57 | Write( ProfileFile, | 
|---|
|  | 58 | 'Profile Start' ); | 
|---|
|  | 59 | Close( ProfileFile ); | 
|---|
|  | 60 | Profiling:= true; | 
|---|
|  | 61 | end; | 
|---|
|  | 62 |  | 
|---|
|  | 63 | procedure ProfileEvent( const Event: string ); | 
|---|
|  | 64 | var | 
|---|
|  | 65 | ThisProfileTime: ULONG; | 
|---|
|  | 66 | begin | 
|---|
|  | 67 | if not Profiling then | 
|---|
|  | 68 | exit; | 
|---|
|  | 69 | {$ifdef win32} | 
|---|
|  | 70 | FileMode := fmOpenReadWrite; | 
|---|
|  | 71 | {$else} | 
|---|
|  | 72 | FileMode := fmInOut; | 
|---|
|  | 73 | {$endif} | 
|---|
|  | 74 | Append( ProfileFile ); | 
|---|
|  | 75 | ThisProfileTime := GetSystemMSCount; | 
|---|
|  | 76 |  | 
|---|
|  | 77 | WriteLn( ProfileFile, | 
|---|
|  | 78 | ', Used: ' | 
|---|
|  | 79 | + IntToStr( ThisProfileTime - LastProfileTime ) ); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | Write( ProfileFile, | 
|---|
|  | 82 | Event + ': ' | 
|---|
|  | 83 | + IntToStr( ThisProfileTime - ProfileStartTime ) ); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | LastProfileTime:= ThisProfileTime; | 
|---|
|  | 86 |  | 
|---|
|  | 87 | Close( ProfileFile ); | 
|---|
|  | 88 | end; | 
|---|
|  | 89 |  | 
|---|
|  | 90 | procedure StopProfile; | 
|---|
|  | 91 | begin | 
|---|
|  | 92 | if not Profiling then | 
|---|
|  | 93 | exit; | 
|---|
|  | 94 | ProfileEvent( 'Profile stop' ); | 
|---|
|  | 95 | Profiling:= false; | 
|---|
|  | 96 | end; | 
|---|
|  | 97 |  | 
|---|
|  | 98 | Initialization | 
|---|
|  | 99 | End. | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.