1 | Unit DebugUnit;
|
---|
2 |
|
---|
3 | // NewView - a new OS/2 Help Viewer
|
---|
4 | // Copyright 2006 Ronald Brill (rbri at rbri dot de)
|
---|
5 | // This software is released under the GNU Public License - see readme.txt
|
---|
6 |
|
---|
7 | // Helper functions for debugging
|
---|
8 |
|
---|
9 | Interface
|
---|
10 |
|
---|
11 | {$define DEBUG}
|
---|
12 |
|
---|
13 |
|
---|
14 | uses
|
---|
15 | Classes,
|
---|
16 | OS2Def,
|
---|
17 | PMWin,
|
---|
18 | SysUtils;
|
---|
19 |
|
---|
20 | {$ifdef DEBUG}
|
---|
21 | imports
|
---|
22 | Function PmPrintfString(aString:PChar):BYTE; APIENTRY; 'PMPRINTF' NAME 'PmPrintfString';
|
---|
23 | end;
|
---|
24 | {$endif}
|
---|
25 |
|
---|
26 | // -- Logging --
|
---|
27 | Type
|
---|
28 | LogAspect = ( LogStartup,
|
---|
29 | LogShutdown,
|
---|
30 | LogSettings,
|
---|
31 | LogParse,
|
---|
32 | LogDisplay,
|
---|
33 | LogSearch,
|
---|
34 | LogNHM,
|
---|
35 | LogViewStub,
|
---|
36 | LogObjConstDest,
|
---|
37 | LogDebug
|
---|
38 | );
|
---|
39 | LogAspects = SET OF LogAspect;
|
---|
40 |
|
---|
41 | Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
|
---|
42 |
|
---|
43 |
|
---|
44 | // -- Profiling --
|
---|
45 |
|
---|
46 | // Starts the timer
|
---|
47 | Procedure PrfStartTimer;
|
---|
48 |
|
---|
49 | // Stops the timer
|
---|
50 | Procedure PrfStopTimer;
|
---|
51 |
|
---|
52 | // Writes the eventDesctiption together with
|
---|
53 | // the time since timer start to PMPrintF
|
---|
54 | // Procedure PrfTraceEvent(const anEventDescription: String);
|
---|
55 |
|
---|
56 | const
|
---|
57 | activeLogAspects : LogAspects = [
|
---|
58 | // LogStartup,
|
---|
59 | // LogShutdown,
|
---|
60 | // LogSettings,
|
---|
61 | // LogParse,
|
---|
62 | // LogDisplay,
|
---|
63 | // LogSearch,
|
---|
64 | LogNHM,
|
---|
65 | // LogViewStub,
|
---|
66 | // LogObjConstDest,
|
---|
67 | LogDebug
|
---|
68 | ];
|
---|
69 |
|
---|
70 | var
|
---|
71 | startTime : ULONG;
|
---|
72 | lastTime : ULONG;
|
---|
73 |
|
---|
74 | Implementation
|
---|
75 |
|
---|
76 | Function GetAspectPrefix(const aLogAspect: LogAspect): String;
|
---|
77 | Begin
|
---|
78 | Case aLogAspect of
|
---|
79 | LogStartup : result := 'Startup';
|
---|
80 | LogShutdown : result := 'Start';
|
---|
81 | LogSettings : result := 'Settings';
|
---|
82 | LogParse : result := 'Parse';
|
---|
83 | LogDisplay : result := 'Display';
|
---|
84 | LogSearch : result := 'Search';
|
---|
85 | LogNHM : result := 'NewHelpManager';
|
---|
86 | LogViewStub : result := 'ViewStub';
|
---|
87 | LogObjConstDest : result := 'ObjConstDest';
|
---|
88 | LogDebug : result := 'Debug';
|
---|
89 | else result := 'Unknown';
|
---|
90 | end;
|
---|
91 | End;
|
---|
92 |
|
---|
93 |
|
---|
94 | Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
|
---|
95 | {$ifdef DEBUG}
|
---|
96 | Var
|
---|
97 | tmpMessage : String;
|
---|
98 | tmpPCharMessage : PChar;
|
---|
99 | {$endif}
|
---|
100 | Begin
|
---|
101 | {$ifdef DEBUG}
|
---|
102 | if (aLogAspect IN activeLogAspects) then
|
---|
103 | begin
|
---|
104 | tmpMessage := 'Log[' + GetAspectPrefix(aLogAspect) + '] ' + anEventDescription;
|
---|
105 |
|
---|
106 | tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
|
---|
107 | StrPCopy(tmpPCharMessage, tmpMessage);
|
---|
108 |
|
---|
109 | PmPrintfString(tmpPCharMessage);
|
---|
110 | StrDispose(tmpPCharMessage);
|
---|
111 | end;
|
---|
112 | {$endif}
|
---|
113 | end;
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | Function GetSystemMSCount: ULONG;
|
---|
119 | Begin
|
---|
120 | result:= WinGetCurrentTime(AppHandle);
|
---|
121 | End;
|
---|
122 |
|
---|
123 |
|
---|
124 | Procedure PrfStartTimer;
|
---|
125 | Begin
|
---|
126 | {$ifdef DEBUG}
|
---|
127 | startTime := GetSystemMSCount;
|
---|
128 | lastTime := startTime;
|
---|
129 | {$endif}
|
---|
130 | End;
|
---|
131 |
|
---|
132 | Procedure PrfStopTimer;
|
---|
133 | Begin
|
---|
134 | End;
|
---|
135 |
|
---|
136 |
|
---|
137 | Procedure PrfTraceEvent(const anEventDescription: String);
|
---|
138 | {$ifdef DEBUG}
|
---|
139 | Var
|
---|
140 | tmpTime : ULONG;
|
---|
141 | tmpMessage : String;
|
---|
142 | tmpPCharMessage : PChar;
|
---|
143 | {$endif}
|
---|
144 | Begin
|
---|
145 | {$ifdef DEBUG}
|
---|
146 | tmpTime := GetSystemMSCount;
|
---|
147 | tmpMessage := 'Prf: ' + IntToStr(tmpTime - lastTime) + 'ms ' + anEventDescription + IntToStr(tmpTime - startTime) + 'ms since start';
|
---|
148 |
|
---|
149 | tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
|
---|
150 | StrPCopy(tmpPCharMessage, tmpMessage);
|
---|
151 |
|
---|
152 | PmPrintfString(tmpPCharMessage);
|
---|
153 | StrDispose(tmpPCharMessage);
|
---|
154 |
|
---|
155 | lastTime := GetSystemMSCount;
|
---|
156 | {$endif}
|
---|
157 | end;
|
---|
158 | END.
|
---|