source: branches/2.19_branch/Library/ACLProfile.pas@ 338

Last change on this file since 338 was 17, checked in by RBRi, 19 years ago

+ Library

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1Unit 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.
8Interface
9
10procedure StartProfile( const Filename: string );
11
12procedure ProfileEvent( const Event: string );
13
14procedure StopProfile;
15
16Implementation
17
18uses
19{$ifdef os2}
20 OS2Def, PMWin,
21{$else}
22 Windows,
23{$endif}
24 SysUtils;
25
26var
27 ProfileStartTime: ULONG;
28 LastProfileTime: ULONG;
29 ProfileFile: TextFile;
30
31const
32 Profiling: boolean = false;
33
34function GetSystemMSCount: ULONG;
35begin
36{$ifdef os2}
37 Result:= WinGetCurrentTime( AppHandle );
38{$else}
39 Result:= GetTickCount;
40{$endif}
41end;
42
43procedure StartProfile( const Filename: string );
44begin
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;
61end;
62
63procedure ProfileEvent( const Event: string );
64var
65 ThisProfileTime: ULONG;
66begin
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 );
88end;
89
90procedure StopProfile;
91begin
92 if not Profiling then
93 exit;
94 ProfileEvent( 'Profile stop' );
95 Profiling:= false;
96end;
97
98Initialization
99End.
Note: See TracBrowser for help on using the repository browser.