Skip to content

Commit

Permalink
Add property to disable performance timing
Browse files Browse the repository at this point in the history
The overhead on performance timing is very low, but adding an option to disable it when an instance of the class is used internally for testing SQL formatting. #426
  • Loading branch information
joyfullservice committed Aug 18, 2023
1 parent 7616c6f commit dc3e191
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Version Control.accda.src/modules/clsPerformance.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Attribute VB_Exposed = False
Option Compare Database
Option Explicit

' Enable or disable timing operations
Public Enabled As Boolean

' Use type for private class variables
Private Type udtPerformance
Expand Down Expand Up @@ -53,6 +55,7 @@ Private Declare PtrSafe Function GetTimeAPI Lib "kernel32" Alias "QueryPerforman
'---------------------------------------------------------------------------------------
'
Public Sub StartTiming()
If Not Me.Enabled Then Exit Sub
Reset
Set this.Overall = New clsPerformanceItem
this.Overall.Start = MicroTimer
Expand All @@ -74,6 +77,8 @@ Public Property Get CallStack() As String

Dim lngCallStackPosition As Long

If Not Me.Enabled Then Exit Property

' Build out breadcrumb type call stack string
With New clsConcat
.AppendOnAdd = "."
Expand All @@ -99,6 +104,7 @@ End Property
'---------------------------------------------------------------------------------------
'
Public Sub CategoryStart(strName As String)
If Not Me.Enabled Then Exit Sub
If this.CategoryName <> vbNullString Then CategoryEnd
If this.Categories Is Nothing Then Set this.Categories = New Dictionary
StartTimer this.Categories, strName
Expand All @@ -114,6 +120,7 @@ End Sub
'---------------------------------------------------------------------------------------
'
Public Sub CategoryEnd(Optional lngCount As Long = 1)
If Not Me.Enabled Then Exit Sub
If this.CategoryName <> vbNullString And Not this.Categories Is Nothing Then
LapTimer this.Categories(this.CategoryName), lngCount
this.CategoryName = vbNullString
Expand All @@ -132,6 +139,8 @@ End Sub
'
Public Sub OperationStart(strName As String)

If Not Me.Enabled Then Exit Sub

' Ensure that we have created the operations dictionary
If this.Operations Is Nothing Then Set this.Operations = New Dictionary

Expand Down Expand Up @@ -167,6 +176,8 @@ Public Sub OperationEnd(Optional lngCount As Long = 1)

Dim strLastOperation As String

If Not Me.Enabled Then Exit Sub

' Verify that we are timing something, and record the elapsed time.
If this.OperationName <> vbNullString And Not this.Operations Is Nothing Then

Expand Down Expand Up @@ -216,6 +227,7 @@ End Property
'---------------------------------------------------------------------------------------
'
Public Sub EndTiming()
If Not Me.Enabled Then Exit Sub
LapTimer this.Overall, 1
End Sub

Expand Down Expand Up @@ -286,6 +298,8 @@ End Sub
'
Public Sub PauseTiming()

If Not Me.Enabled Then Exit Sub

' Lap overall time
LapTimer this.Overall, 0

Expand All @@ -309,6 +323,8 @@ End Sub
'
Public Sub ResumeTiming()

If Not Me.Enabled Then Exit Sub

' Resume overall time
If Not this.Overall Is Nothing Then this.Overall.Start = MicroTimer

Expand Down Expand Up @@ -351,6 +367,7 @@ End Function
'---------------------------------------------------------------------------------------
'
Public Property Get TotalTime() As Currency
If Not Me.Enabled Then Exit Function
If this.Overall Is Nothing Then
TotalTime = 0
Else
Expand All @@ -377,6 +394,8 @@ Public Function GetReports() As String
Dim lngCol(0 To 2) As Long
Dim strSpacer As String

If Not Me.Enabled Then Exit Function

' Set up column sizes
lngCol(0) = 30
lngCol(1) = 10
Expand Down Expand Up @@ -561,6 +580,7 @@ Public Sub Reset()
Set this.Categories = Nothing
this.OperationName = vbNullString
Set this.Operations = Nothing
Enabled = True
End Sub


Expand All @@ -576,4 +596,5 @@ Private Sub Class_Initialize()
' https://docs.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancefrequency
GetFrequencyAPI this.Frequency
this.intDigitsAfterDecimal = 2
Enabled = True
End Sub

0 comments on commit dc3e191

Please sign in to comment.