source: trunk/NewView/DebugUnit.pas@ 44

Last change on this file since 44 was 43, checked in by RBRi, 19 years ago

% use new debug unit

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1Unit 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
9Interface
10
11{$define DEBUG}
12
13
14uses
15 Classes,
16 OS2Def,
17 PMWin,
18 SysUtils;
19
20{$ifdef DEBUG}
21imports
22 Function PmPrintfString(aString:PChar):BYTE; APIENTRY; 'PMPRINTF' NAME 'PmPrintfString';
23end;
24{$endif}
25
26 // -- Logging --
27 Type
28 LogAspect = (LogStartup, LogShutdown, LogSettings, LogParse, LogDisplay, LogSearch);
29
30 Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
31
32
33 // -- Profiling --
34
35 // Starts the timer
36 Procedure PrfStartTimer;
37
38 // Stops the timer
39 Procedure PrfStopTimer;
40
41 // Writes the eventDesctiption together with
42 // the time since timer start to PMPrintF
43 // Procedure PrfTraceEvent(const anEventDescription: String);
44
45
46var
47 startTime : ULONG;
48 lastTime : ULONG;
49
50Implementation
51
52 Function GetAspectPrefix(const aLogAspect: LogAspect): String;
53 Begin
54 Case aLogAspect of
55 LogStartup : result := 'Startup';
56 LogShutdown : result := 'Start';
57 LogSettings : result := 'Settings';
58 LogParse : result := 'Parse';
59 LogDisplay : result := 'Display';
60 LogSearch : result := 'Search';
61 else result := 'Unknown';
62 end;
63 End;
64
65
66 Procedure LogEvent(const aLogAspect: LogAspect; const anEventDescription: String);
67{$ifdef DEBUG}
68 Var
69 tmpMessage : String;
70 tmpPCharMessage : PChar;
71{$endif}
72 Begin
73{$ifdef DEBUG}
74 tmpMessage := 'Log[' + GetAspectPrefix(aLogAspect) + '] ' + anEventDescription;
75
76 tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
77 StrPCopy(tmpPCharMessage, tmpMessage);
78
79 PmPrintfString(tmpPCharMessage);
80 StrDispose(tmpPCharMessage);
81{$endif}
82 end;
83
84
85
86
87 Function GetSystemMSCount: ULONG;
88 Begin
89 result:= WinGetCurrentTime(AppHandle);
90 End;
91
92
93 Procedure PrfStartTimer;
94 Begin
95{$ifdef DEBUG}
96 startTime := GetSystemMSCount;
97 lastTime := startTime;
98{$endif}
99 End;
100
101 Procedure PrfStopTimer;
102 Begin
103 End;
104
105
106 Procedure PrfTraceEvent(const anEventDescription: String);
107{$ifdef DEBUG}
108 Var
109 tmpTime : ULONG;
110 tmpMessage : String;
111 tmpPCharMessage : PChar;
112{$endif}
113 Begin
114{$ifdef DEBUG}
115 tmpTime := GetSystemMSCount;
116 tmpMessage := 'Prf: ' + IntToStr(tmpTime - lastTime) + 'ms ' + anEventDescription + IntToStr(tmpTime - startTime) + 'ms since start';
117
118 tmpPCharMessage := StrAlloc(length(tmpMessage) + 1);
119 StrPCopy(tmpPCharMessage, tmpMessage);
120
121 PmPrintfString(tmpPCharMessage);
122 StrDispose(tmpPCharMessage);
123
124 lastTime := GetSystemMSCount;
125{$endif}
126 end;
127END.
Note: See TracBrowser for help on using the repository browser.