| 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, LogShutdown, LogSettings, LogParse, LogDisplay, LogSearch, LogViewStub, LogObjConstDest);
|
|---|
| 29 | LogAspects = SET OF LogAspect;
|
|---|
| 30 |
|
|---|
| 31 | Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | // -- Profiling --
|
|---|
| 35 |
|
|---|
| 36 | // Starts the timer
|
|---|
| 37 | Procedure PrfStartTimer;
|
|---|
| 38 |
|
|---|
| 39 | // Stops the timer
|
|---|
| 40 | Procedure PrfStopTimer;
|
|---|
| 41 |
|
|---|
| 42 | // Writes the eventDesctiption together with
|
|---|
| 43 | // the time since timer start to PMPrintF
|
|---|
| 44 | // Procedure PrfTraceEvent(const anEventDescription: String);
|
|---|
| 45 |
|
|---|
| 46 | const
|
|---|
| 47 | activeLogAspects : LogAspects = [
|
|---|
| 48 | LogStartup,
|
|---|
| 49 | // LogShutdown,
|
|---|
| 50 | // LogSettings,
|
|---|
| 51 | // LogParse,
|
|---|
| 52 | // LogDisplay,
|
|---|
| 53 | // LogSearch,
|
|---|
| 54 | LogViewStub,
|
|---|
| 55 | LogObjConstDest
|
|---|
| 56 | ];
|
|---|
| 57 |
|
|---|
| 58 | var
|
|---|
| 59 | startTime : ULONG;
|
|---|
| 60 | lastTime : ULONG;
|
|---|
| 61 |
|
|---|
| 62 | Implementation
|
|---|
| 63 |
|
|---|
| 64 | Function GetAspectPrefix(const aLogAspect: LogAspect): String;
|
|---|
| 65 | Begin
|
|---|
| 66 | Case aLogAspect of
|
|---|
| 67 | LogStartup : result := 'Startup';
|
|---|
| 68 | LogShutdown : result := 'Start';
|
|---|
| 69 | LogSettings : result := 'Settings';
|
|---|
| 70 | LogParse : result := 'Parse';
|
|---|
| 71 | LogDisplay : result := 'Display';
|
|---|
| 72 | LogSearch : result := 'Search';
|
|---|
| 73 | LogViewStub : result := 'ViewStub';
|
|---|
| 74 | LogObjConstDest : result := 'ObjConstDest';
|
|---|
| 75 | else result := 'Unknown';
|
|---|
| 76 | end;
|
|---|
| 77 | End;
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
|
|---|
| 81 | {$ifdef DEBUG}
|
|---|
| 82 | Var
|
|---|
| 83 | tmpMessage : String;
|
|---|
| 84 | tmpPCharMessage : PChar;
|
|---|
| 85 | {$endif}
|
|---|
| 86 | Begin
|
|---|
| 87 | {$ifdef DEBUG}
|
|---|
| 88 | if (aLogAspect IN activeLogAspects) then
|
|---|
| 89 | begin
|
|---|
| 90 | tmpMessage := 'Log[' + GetAspectPrefix(aLogAspect) + '] ' + anEventDescription;
|
|---|
| 91 |
|
|---|
| 92 | tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
|
|---|
| 93 | StrPCopy(tmpPCharMessage, tmpMessage);
|
|---|
| 94 |
|
|---|
| 95 | PmPrintfString(tmpPCharMessage);
|
|---|
| 96 | StrDispose(tmpPCharMessage);
|
|---|
| 97 | end;
|
|---|
| 98 | {$endif}
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | Function GetSystemMSCount: ULONG;
|
|---|
| 105 | Begin
|
|---|
| 106 | result:= WinGetCurrentTime(AppHandle);
|
|---|
| 107 | End;
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | Procedure PrfStartTimer;
|
|---|
| 111 | Begin
|
|---|
| 112 | {$ifdef DEBUG}
|
|---|
| 113 | startTime := GetSystemMSCount;
|
|---|
| 114 | lastTime := startTime;
|
|---|
| 115 | {$endif}
|
|---|
| 116 | End;
|
|---|
| 117 |
|
|---|
| 118 | Procedure PrfStopTimer;
|
|---|
| 119 | Begin
|
|---|
| 120 | End;
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | Procedure PrfTraceEvent(const anEventDescription: String);
|
|---|
| 124 | {$ifdef DEBUG}
|
|---|
| 125 | Var
|
|---|
| 126 | tmpTime : ULONG;
|
|---|
| 127 | tmpMessage : String;
|
|---|
| 128 | tmpPCharMessage : PChar;
|
|---|
| 129 | {$endif}
|
|---|
| 130 | Begin
|
|---|
| 131 | {$ifdef DEBUG}
|
|---|
| 132 | tmpTime := GetSystemMSCount;
|
|---|
| 133 | tmpMessage := 'Prf: ' + IntToStr(tmpTime - lastTime) + 'ms ' + anEventDescription + IntToStr(tmpTime - startTime) + 'ms since start';
|
|---|
| 134 |
|
|---|
| 135 | tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
|
|---|
| 136 | StrPCopy(tmpPCharMessage, tmpMessage);
|
|---|
| 137 |
|
|---|
| 138 | PmPrintfString(tmpPCharMessage);
|
|---|
| 139 | StrDispose(tmpPCharMessage);
|
|---|
| 140 |
|
|---|
| 141 | lastTime := GetSystemMSCount;
|
|---|
| 142 | {$endif}
|
|---|
| 143 | end;
|
|---|
| 144 | END.
|
|---|