Skip to content

Commit a614fa5

Browse files
Sort items in performance report by total time
I have been wanting to do this for a while, but now we can see the list of components and operations sorted by the total time expended. This helps us identify potential bottlenecks in export/import operations.
1 parent f1383bc commit a614fa5

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Version Control.accda.src/modules/clsPerformance.cls

+60
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ Public Function GetReports() As String
392392

393393
' Table for object types
394394
If Not this.Categories Is Nothing Then
395+
Set this.Categories = SortItemsByTime(this.Categories)
395396
.Add strSpacer
396397
.Add ListResult("Category", "Count", "Seconds", lngCol), vbCrLf, strSpacer
397398
For Each varKey In this.Categories.Keys
@@ -410,6 +411,7 @@ Public Function GetReports() As String
410411

411412
' Table for operations
412413
If Not this.Operations Is Nothing Then
414+
Set this.Operations = SortItemsByTime(this.Operations)
413415
curTotal = 0
414416
.Add strSpacer
415417
.Add ListResult("Operations", "Count", "Seconds", lngCol), vbCrLf, strSpacer
@@ -488,6 +490,64 @@ Private Function PadRight(strText As String, lngLen As Long, Optional lngMinTrai
488490
End Function
489491

490492

493+
'---------------------------------------------------------------------------------------
494+
' Procedure : SortItemsByTime
495+
' Author : Adam Waller
496+
' Date : 4/4/2023
497+
' Purpose : Sort the items by total time in descending order to put the slowest
498+
' : items at the top of the list.
499+
'---------------------------------------------------------------------------------------
500+
'
501+
Private Function SortItemsByTime(dItems As Dictionary) As Dictionary
502+
503+
Dim varItems() As Variant
504+
Dim varKey As Variant
505+
Dim lngCnt As Long
506+
Dim strRecord As String
507+
Dim cItem As clsPerformanceItem
508+
Dim dSorted As Dictionary
509+
510+
' Create an array to build our items
511+
ReDim varItems(0 To dItems.Count - 1)
512+
513+
' The idea here is that we want to build a fixed width record with the time on
514+
' the left, and the key on the right. We will then sort this list of "records"
515+
' to get them sorted by time. However, since the sorting is in ascending order,
516+
' we will loop backwards through the resulting array to rebuild a dictionary
517+
' of items in descending order. We will split out the key and use this to get
518+
' a reference back to the original item in the source dictionary.
519+
520+
' Build our list of records
521+
For Each varKey In dItems.Keys
522+
' Create a record like this: "00062840.170000|Export Form Objects ..."
523+
strRecord = Format(dItems(varKey).Total, "00000000.000000") & "|" & PadRight(CStr(varKey), 100)
524+
' Add to array.
525+
varItems(lngCnt) = strRecord
526+
' Increment counter for array
527+
lngCnt = lngCnt + 1
528+
Next varKey
529+
530+
' Sort the array in ascending order
531+
QuickSort varItems
532+
533+
' Now, build a new dictionary with the sorted items
534+
' (We are walking backwards through the array to flip the sort to descending)
535+
Set dSorted = New Dictionary
536+
For lngCnt = dItems.Count - 1 To 0 Step -1
537+
' Parse key from record
538+
varKey = Trim(Split(varItems(lngCnt), "|")(1))
539+
' Reference performance item class
540+
Set cItem = dItems(varKey)
541+
' Add to dictionary of resorted items
542+
dSorted.Add varKey, cItem
543+
Next lngCnt
544+
545+
' Return the sorted dictionary
546+
Set SortItemsByTime = dSorted
547+
548+
End Function
549+
550+
491551
'---------------------------------------------------------------------------------------
492552
' Procedure : Reset
493553
' Author : Adam Waller

0 commit comments

Comments
 (0)