Changeset 76 for trunk/NewView/DebugUnit.pas
- Timestamp:
- Feb 12, 2007, 9:35:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NewView/DebugUnit.pas
r70 r76 2 2 3 3 // NewView - a new OS/2 Help Viewer 4 // Copyright 2006 Ronald Brill (rbri at rbri dot de)4 // Copyright 2006/2007 Ronald Brill (rbri at rbri dot de) 5 5 // This software is released under the GNU Public License - see readme.txt 6 6 … … 8 8 9 9 Interface 10 11 {$define DEBUG}12 10 13 11 … … 18 16 SysUtils; 19 17 20 {$ifdef DEBUG}21 imports22 Function PmPrintfString(aString:PChar):BYTE; APIENTRY; 'PMPRINTF' NAME 'PmPrintfString';23 end;24 {$endif}25 18 26 19 // -- Logging -- … … 54 47 // Procedure PrfTraceEvent(const anEventDescription: String); 55 48 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 ]; 49 Procedure SetLogAspects(const aCommaSeparatedListOfAspectNames : String); 50 69 51 70 52 var 71 53 startTime : ULONG; 72 54 lastTime : ULONG; 55 PMPrintfModuleHandle : HMODULE; 56 PMPrintfString : Function(aString : PChar) : ULONG; APIENTRY; 57 activeLogAspects : LogAspects; 58 59 73 60 74 61 Implementation 62 uses 63 BseDos, 64 StringUtilsUnit; 65 66 FUNCTION LoadPMPrinfFLib : integer; 67 Var 68 tmpDllName : CString; 69 tmpErrorInfo : CString; 70 tmpProcedureName : CSTRING; 71 tmpProcedureAddress : POINTER; 72 tmpRC : APIRET; 73 74 begin 75 PMPrintfString := nil; 76 77 tmpDllName:='PMPRINTF'; 78 tmpRC := DosLoadModule(tmpErrorInfo, 255, tmpDllName, PMPrintfModuleHandle); 79 if tmpRC <> 0 then 80 begin 81 PMPrintfModuleHandle := 0; 82 result := 0; 83 exit; 84 end; 85 86 tmpProcedureName := 'PmPrintfString'; 87 tmpRC := DosQueryProcAddr(PMPrintfModuleHandle, 0, tmpProcedureName, tmpProcedureAddress); 88 if tmpRC <> 0 then 89 begin 90 DosFreeModule(PMPrintfModuleHandle); 91 PMPrintfModuleHandle := 0; 92 result := 0; 93 exit; 94 end; 95 96 PMPrintfString := tmpProcedureAddress; 97 result := 0; 98 end; 99 100 101 Procedure PMPrintf(const aString : String); 102 Var 103 tmpPCharMessage : PChar; 104 Begin 105 if (0 <> PMPrintfModuleHandle) then 106 begin 107 tmpPCharMessage := StrAlloc(length(aString) + 1); 108 StrPCopy(tmpPCharMessage, aString); 109 110 PmPrintfString(tmpPCharMessage); 111 112 StrDispose(tmpPCharMessage); 113 end; 114 end; 115 75 116 76 117 Function GetAspectPrefix(const aLogAspect: LogAspect): String; … … 92 133 93 134 135 Procedure SetLogAspects(const aCommaSeparatedListOfAspectNames : String); 136 Var 137 tmpAspects : TStringList; 138 i : Integer; 139 Begin 140 tmpAspects := TStringList.Create; 141 StrExtractStrings(tmpAspects, aCommaSeparatedListOfAspectNames, [','], #0); 142 143 for i:=0 to tmpAspects.count-1 do 144 begin 145 if tmpAspects[i] = 'LogStartup' then activeLogAspects := activeLogAspects + [ LogStartup ]; 146 if tmpAspects[i] = 'LogShutdown' then activeLogAspects := activeLogAspects + [ LogShutdown ]; 147 if tmpAspects[i] = 'LogSettings' then activeLogAspects := activeLogAspects + [ LogSettings ]; 148 if tmpAspects[i] = 'LogParse' then activeLogAspects := activeLogAspects + [ LogParse ]; 149 if tmpAspects[i] = 'LogDisplay' then activeLogAspects := activeLogAspects + [ LogDisplay ]; 150 if tmpAspects[i] = 'LogSearch' then activeLogAspects := activeLogAspects + [ LogSearch ]; 151 if tmpAspects[i] = 'LogNHM' then activeLogAspects := activeLogAspects + [ LogNHM ]; 152 if tmpAspects[i] = 'LogViewStub' then activeLogAspects := activeLogAspects + [ LogViewStub ]; 153 if tmpAspects[i] = 'LogObjConstDest' then activeLogAspects := activeLogAspects + [ LogObjConstDest ]; 154 if tmpAspects[i] = 'LogDebug' then activeLogAspects := activeLogAspects + [ LogDebug ]; 155 end; 156 157 tmpAspects.Destroy; 158 End; 159 160 94 161 Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String); 95 {$ifdef DEBUG}96 162 Var 97 163 tmpMessage : String; 98 tmpPCharMessage : PChar; 99 {$endif} 100 Begin 101 {$ifdef DEBUG} 164 Begin 102 165 if (aLogAspect IN activeLogAspects) then 103 166 begin 104 167 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 168 PmPrintf(tmpMessage); 169 end; 170 end; 116 171 117 172 … … 124 179 Procedure PrfStartTimer; 125 180 Begin 126 {$ifdef DEBUG}127 181 startTime := GetSystemMSCount; 128 182 lastTime := startTime; 129 {$endif} 130 End; 183 End; 184 131 185 132 186 Procedure PrfStopTimer; … … 136 190 137 191 Procedure PrfTraceEvent(const anEventDescription: String); 138 {$ifdef DEBUG}139 192 Var 140 193 tmpTime : ULONG; 141 194 tmpMessage : String; 142 tmpPCharMessage : PChar; 143 {$endif} 144 Begin 145 {$ifdef DEBUG} 195 Begin 146 196 tmpTime := GetSystemMSCount; 147 197 tmpMessage := 'Prf: ' + IntToStr(tmpTime - lastTime) + 'ms ' + anEventDescription + IntToStr(tmpTime - startTime) + 'ms since start'; 148 198 149 tmpPCharMessage := StrAlloc(length(tmpMessage) + 1); 150 StrPCopy(tmpPCharMessage, tmpMessage); 151 152 PmPrintfString(tmpPCharMessage); 153 StrDispose(tmpPCharMessage); 199 PMPrintf(tmpMessage); 154 200 155 201 lastTime := GetSystemMSCount; 156 {$endif} 157 end; 202 end; 203 204 205 Initialization 206 LoadPMPrinfFLib; 158 207 END.
Note:
See TracChangeset
for help on using the changeset viewer.