home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "profiler"
- Option Explicit
-
- #If PROFILING Then
- Const MAX_SECONDS = 86400 ' number of seconds at midnight
-
- Dim iFileHandle As Integer ' handle for the output file
- Dim sngTimers(20) As Single ' storage for 20 simultaneous timers
- Dim iLastTimer As Integer ' last entry in the array used
- #End If
-
- Function MarkEndTime(sTag As String) As Integer
-
- #If PROFILING Then
- On Error GoTo Error_MarkEndTime
-
- Dim sngEndTime As Single, sngDifference As Single
-
- ' record the end time and adjust for the passage of midnight
- sngEndTime = Timer
- If sngEndTime < sngTimers(iLastTimer) Then sngEndTime = sngEndTime + MAX_SECONDS
-
- ' compute the elapsed time
- sngDifference = sngEndTime - sngTimers(iLastTimer)
-
- ' write it to a file, with a number of space that reflect
- ' its place in the stack of timers.
- Print #iFileHandle, Spc(iLastTimer); sTag; " "; sngDifference
-
- ' free an array entry for re-use
- iLastTimer = iLastTimer - 1
-
- MarkEndTime = True
- Exit Function
-
- Error_MarkEndTime:
- MarkEndTime = False
- Exit Function
-
- #Else
- MarkEndTime = True
- Exit Function
- #End If
-
- End Function
-
- Function MarkStartTime() As Integer
-
- #If PROFILING Then
- On Error GoTo Error_MarkStartTime
-
- Dim i As Integer
-
- ' get the next entry to use
- i = iLastTimer + 1
-
- ' record the starting time value
- sngTimers(i) = Timer
- iLastTimer = i
-
- MarkStartTime = True
- Exit Function
-
- Error_MarkStartTime:
- MarkStartTime = False
- Exit Function
-
- #Else
- MarkStartTime = True
- Exit Function
- #End If
-
- End Function
-
- Function StopProfiler() As Integer
-
- #If PROFILING Then
- On Error GoTo Error_StopProfiler
-
- ' close the output file.
- Close #iFileHandle
- StopProfiler = True
- Exit Function
-
- Error_StopProfiler:
- StopProfiler = False
- Exit Function
-
- #Else
- StopProfiler = True
- Exit Function
- #End If
-
- End Function
-
- Function StartProfiler(sFileName As String) As Integer
-
- #If PROFILING Then
- On Error GoTo Error_StartProfiler
-
- ' open an output file for the timing information
- iFileHandle = FreeFile
- Open sFileName For Output As #iFileHandle
-
- ' initialize the counters
- iLastTimer = 0
-
- StartProfiler = True
- Exit Function
-
- Error_StartProfiler:
- StartProfiler = False
- Exit Function
-
- #Else
- StartProfiler = True
- Exit Function
- #End If
-
- End Function
-
-