home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / acl-lib.zip / ACLProfile.pas < prev    next >
Pascal/Delphi Source File  |  2000-07-27  |  1KB  |  76 lines

  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. Interface
  7.  
  8. procedure StartProfile;
  9.  
  10. procedure ProfileEvent( Event: string );
  11.  
  12. procedure StopProfile;
  13.  
  14. Implementation
  15.  
  16. uses
  17. {$ifdef os2}
  18.   OS2Def, PMWin,
  19. {$else}
  20.   Windows,
  21. {$endif}
  22.   SysUtils;
  23.  
  24. var
  25.   ProfileStartTime: ULONG;
  26.   ProfileFile: TextFile;
  27.  
  28. const
  29.   Profiling: boolean = false;
  30.  
  31. function GetSystemMSCount: ULONG;
  32. begin
  33. {$ifdef os2}
  34.   Result:= WinGetCurrentTime( AppHandle );
  35. {$else}
  36.   Result:= GetTickCount;
  37. {$endif}
  38. end;
  39.  
  40. procedure StartProfile;
  41. begin
  42.   ProfileStartTime:= GetSystemMSCount;
  43.   Assign( ProfileFile, 'profile' );
  44.   Rewrite( ProfileFile );
  45.   WriteLn( ProfileFile,
  46.            'Profile start' );
  47.   Close( ProfileFile );
  48.   Profiling:= true;
  49. end;
  50.  
  51. procedure ProfileEvent( Event: string );
  52. begin
  53.   if not Profiling then
  54.     exit;
  55.   Append( ProfileFile );
  56.   WriteLn( ProfileFile,
  57.            Event + ': '
  58.            + IntToStr( GetSystemMSCount - ProfileStartTime ) );
  59.   Close( ProfileFile );
  60. end;
  61.  
  62. procedure StopProfile;
  63. begin
  64.   if not Profiling then
  65.     exit;
  66.   Append( ProfileFile );
  67.   WriteLn( ProfileFile,
  68.            'Profile stop: '
  69.            + IntToStr( GetSystemMSCount - ProfileStartTime ) );
  70.   Close( ProfileFile );
  71.   Profiling:= false;
  72. end;
  73.  
  74. Initialization
  75. End.
  76.