@@ -392,6 +392,7 @@ Public Function GetReports() As String
392
392
393
393
' Table for object types
394
394
If Not this.Categories Is Nothing Then
395
+ Set this.Categories = SortItemsByTime(this.Categories)
395
396
.Add strSpacer
396
397
.Add ListResult("Category" , "Count" , "Seconds" , lngCol), vbCrLf, strSpacer
397
398
For Each varKey In this.Categories.Keys
@@ -410,6 +411,7 @@ Public Function GetReports() As String
410
411
411
412
' Table for operations
412
413
If Not this.Operations Is Nothing Then
414
+ Set this.Operations = SortItemsByTime(this.Operations)
413
415
curTotal = 0
414
416
.Add strSpacer
415
417
.Add ListResult("Operations" , "Count" , "Seconds" , lngCol), vbCrLf, strSpacer
@@ -488,6 +490,64 @@ Private Function PadRight(strText As String, lngLen As Long, Optional lngMinTrai
488
490
End Function
489
491
490
492
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
+
491
551
'---------------------------------------------------------------------------------------
492
552
' Procedure : Reset
493
553
' Author : Adam Waller
0 commit comments