@@ -45,7 +45,8 @@ NAP.initialMetrics = {};
4545NAP .resetBaselineMetrics = NAP .initialMetrics ;
4646
4747NAP .totalMs = {};
48- NAP .totalTicks = {};
48+ NAP .loadedAtTick = {};
49+ NAP .tickNumber = 0 ;
4950NAP .peakMs = {};
5051NAP .snapshots = {
5152 --- @type NAP_Bucket[]
@@ -145,7 +146,7 @@ function NAP:ADDON_LOADED(addonName)
145146 self .loadedAddons [addonName ] = true ;
146147 self .addons [addonName ].loaded = true ;
147148 self .totalMs [addonName ] = 0 ;
148- self .totalTicks [addonName ] = 0 ;
149+ self .loadedAtTick [addonName ] = self . tickNumber ;
149150 self .peakMs [addonName ] = 0 ;
150151 self .snapshots .lastBucket .lastTick [addonName ] = {};
151152 for ms in pairs (msMetricMap ) do
174175function NAP :OnUpdate ()
175176 if not self .collectData then return end
176177
178+ self .tickNumber = self .tickNumber + 1 ;
179+
177180 local peakMs = self .peakMs ;
178181 local totalMs = self .totalMs ;
179- local totalTicks = self .totalTicks ;
180182 local currentMetrics = self .currentMetrics ;
181183
182184 local lastBucket = self .snapshots .lastBucket ;
@@ -188,7 +190,6 @@ function NAP:OnUpdate()
188190
189191 local getMetric = C_AddOnProfiler .GetAddOnMetric ;
190192 for addonName in pairs (self .loadedAddons ) do
191- totalTicks [addonName ] = totalTicks [addonName ] + 1 ;
192193 local lastTickMs = getMetric (addonName , Enum .AddOnProfilerMetric .LastTime );
193194 if lastTickMs > 0 then
194195 lastBucket .lastTick [addonName ][curTickIndex ] = lastTickMs ;
@@ -214,12 +215,13 @@ end
214215
215216function NAP :ResetMetrics ()
216217 self .resetBaselineMetrics = CopyTable (self .currentMetrics );
218+ self .tickNumber = 0 ;
219+ self .snapshots .buckets = {};
220+ self :InitNewBucket ();
217221 for addonName in pairs (self .loadedAddons ) do
218222 self .totalMs [addonName ] = 0 ;
219223 self .peakMs [addonName ] = 0 ;
220- self .totalTicks [addonName ] = 0 ;
221- self .snapshots .buckets = {};
222- self :InitNewBucket ();
224+ self .loadedAtTick [addonName ] = 0 ;
223225 end
224226end
225227
@@ -326,7 +328,7 @@ function NAP:PrepareFilteredData()
326328 end
327329 data .peakTime = self .peakMs [addonName ];
328330 data .totalMs = self .totalMs [addonName ];
329- data .numberOfTicks = self .totalTicks [addonName ];
331+ data .numberOfTicks = self .tickNumber - self . loadedAtTick [addonName ];
330332 else
331333 for bucket , startingTickIndex in pairs (withinHistory ) do
332334 data .numberOfTicks = data .numberOfTicks + ((bucket .curTickIndex - startingTickIndex ) + 1 );
@@ -363,6 +365,9 @@ function NAP:PrepareFilteredData()
363365 end
364366
365367 self .dataProvider = CreateDataProvider (self .filteredData )
368+ if self .sortComparator then
369+ self .dataProvider :SetSortComparator (self .sortComparator )
370+ end
366371end
367372
368373function NAP :InitUI ()
@@ -388,16 +393,12 @@ function NAP:InitUI()
388393 --- @param a NAP_ElementData
389394 --- @param b NAP_ElementData
390395 [ORDER_ASC ] = function (a , b )
391- return a [key ] < b [key ]
392- or a [key ] == b [key ]
393- and a .addonName < b .addonName ;
396+ return a [key ] < b [key ] or (a [key ] == b [key ] and a .addonName < b .addonName );
394397 end ,
395398 --- @param a NAP_ElementData
396399 --- @param b NAP_ElementData
397400 [ORDER_DESC ] = function (a , b )
398- return a [key ] > b [key ]
399- or a [key ] == b [key ]
400- and a .addonName < b .addonName ;
401+ return a [key ] > b [key ] or (a [key ] == b [key ] and a .addonName < b .addonName );
401402 end ,
402403 };
403404 end
@@ -406,7 +407,6 @@ function NAP:InitUI()
406407 justifyLeft = true ,
407408 title = " Addon Name" ,
408409 width = 300 ,
409- order = ORDER_ASC ,
410410 textFormatter = RAW_FORMAT ,
411411 textKey = " addonTitle" ,
412412 sortMethods = {
@@ -425,16 +425,14 @@ function NAP:InitUI()
425425 {
426426 title = " Boss Avg" ,
427427 width = 96 ,
428- order = ORDER_ASC ,
429428 textFormatter = TIME_FORMAT ,
430429 textKey = " encounterAvg" ,
431- tooltip = " Average time spent per frame during a boss encounter. Ignores the History Range" ,
430+ tooltip = " Average CPU time spent per frame during a boss encounter. Ignores the History Range" ,
432431 sortMethods = makeSortMethods (" encounterAvg" ),
433432 },
434433 {
435434 title = " Peak Time" ,
436435 width = 96 ,
437- order = ORDER_ASC ,
438436 textFormatter = TIME_FORMAT ,
439437 textKey = " peakTime" ,
440438 tooltip = " Biggest spike in ms, within the History Range." ,
@@ -443,16 +441,14 @@ function NAP:InitUI()
443441 {
444442 title = " Average" ,
445443 width = 96 ,
446- order = ORDER_ASC ,
447444 textFormatter = TIME_FORMAT ,
448445 textKey = " averageMs" ,
449- tooltip = " Average time spent per frame." ,
446+ tooltip = " Average CPU time spent per frame." ,
450447 sortMethods = makeSortMethods (" averageMs" ),
451448 },
452449 {
453450 title = " Total" ,
454451 width = 108 ,
455- order = ORDER_ASC ,
456452 textFormatter = TIME_FORMAT ,
457453 textKey = " totalMs" ,
458454 tooltip = " Total CPU time spent, within the History Range." ,
@@ -463,7 +459,6 @@ function NAP:InitUI()
463459 t_insert (COLUMN_INFO , {
464460 title = " Over " .. ms .. " ms" ,
465461 width = 80 + (strlen (ms ) * 5 ),
466- order = ORDER_ASC ,
467462 textFormatter = COUNTER_FORMAT ,
468463 textKey = msOptionFieldMap [ms ],
469464 tooltip = " How many times the addon took longer than " .. ms .. " ms per frame." ,
@@ -473,7 +468,6 @@ function NAP:InitUI()
473468 t_insert (COLUMN_INFO , {
474469 title = " Spike Sum" ,
475470 width = 96 ,
476- order = ORDER_ASC ,
477471 textFormatter = ROUND_TIME_FORMAT ,
478472 textKey = " overMsSum" ,
479473 tooltip = " Sum of all the separate spikes." ,
@@ -485,11 +479,13 @@ function NAP:InitUI()
485479 local UPDATE_INTERVAL = 1
486480 local continuousUpdate = true
487481
488- local function sortFilteredData ()
482+ local function updateSortComparator ()
483+ self .sortComparator = COLUMN_INFO [activeSort ].sortMethods [activeOrder ]
489484 if self .dataProvider then
490- self .dataProvider :SetSortComparator (COLUMN_INFO [ activeSort ]. sortMethods [ activeOrder ] )
485+ self .dataProvider :SetSortComparator (self . sortComparator )
491486 end
492487 end
488+ updateSortComparator ()
493489
494490 ---- ---------
495491 -- DISPLAY --
@@ -501,7 +497,6 @@ function NAP:InitUI()
501497 self .elapsed = (self .elapsed or 0 ) + elapsed
502498 if self .elapsed >= UPDATE_INTERVAL then
503499 NAP :PrepareFilteredData ()
504- sortFilteredData ()
505500
506501 local perc = self .ScrollBox :GetScrollPercentage ()
507502 self .ScrollBox :Flush ()
@@ -641,12 +636,15 @@ function NAP:InitUI()
641636 end
642637
643638 function headers :OnClick (index )
639+ local columnChanged = activeSort ~= index
644640 activeSort = index
645641
646- COLUMN_INFO [index ].order = COLUMN_INFO [index ].order * - 1
647- activeOrder = COLUMN_INFO [index ].order
648-
649- sortFilteredData ()
642+ if columnChanged then
643+ activeOrder = ORDER_DESC
644+ else
645+ activeOrder = activeOrder == ORDER_DESC and ORDER_ASC or ORDER_DESC
646+ end
647+ updateSortComparator ()
650648
651649 self :UpdateArrow (index )
652650 end
@@ -668,8 +666,15 @@ function NAP:InitUI()
668666 if notes and notes ~= " " then
669667 GameTooltip :AddLine (notes , 1 , 1 , 1 , true )
670668 end
671- GameTooltip :AddDoubleLine (" Peak Time (since game start):" , TIME_FORMAT (data .peakTime ), 1 , 0.92 , 0 , 1 , 1 , 1 )
672- GameTooltip :AddDoubleLine (" Encounter Avg:" , TIME_FORMAT (data .encounterAvg ), 1 , 0.92 , 0 , 1 , 1 , 1 )
669+ GameTooltip :AddLine (" " )
670+ if data .addonName == thisAddonName then
671+ GameTooltip :AddLine (" Note: The profiler has to do a lot of work while showing the UI, the numbers displayed here are not representative of the passive background CPU usage." , 1 , 1 , 1 , true )
672+ GameTooltip :AddLine (" " )
673+ end
674+ GameTooltip :AddDoubleLine (" Peak CPU time:" , TIME_FORMAT (data .peakTime ), 1 , 0.92 , 0 , 1 , 1 , 1 )
675+ GameTooltip :AddDoubleLine (" Average CPU time per frame:" , TIME_FORMAT (data .averageMs ), 1 , 0.92 , 0 , 1 , 1 , 1 )
676+ GameTooltip :AddDoubleLine (" Total CPU time:" , TIME_FORMAT (data .totalMs ), 1 , 0.92 , 0 , 1 , 1 , 1 )
677+ GameTooltip :AddDoubleLine (" Number of frames:" , RAW_FORMAT (data .numberOfTicks ), 1 , 0.92 , 0 , 1 , 1 , 1 )
673678 GameTooltip :Show ()
674679 end
675680 end
@@ -857,7 +862,6 @@ function NAP:InitUI()
857862
858863 updateButton :SetScript (" OnClick" , function ()
859864 NAP :PrepareFilteredData ()
860- sortFilteredData ()
861865
862866 local perc = display .ScrollBox :GetScrollPercentage ()
863867 display .ScrollBox :Flush ()
@@ -924,7 +928,9 @@ function NAP:InitUI()
924928 resetButton :SetOnClickHandler (function ()
925929 self :ResetMetrics ()
926930
927- display .elapsed = UPDATE_INTERVAL
931+ RunNextFrame (function ()
932+ display .elapsed = UPDATE_INTERVAL
933+ end )
928934 end )
929935 end
930936end
@@ -937,6 +943,7 @@ function NAP:EnableLogging()
937943 self .ToggleButton :SetText (" Disable" )
938944 DynamicResizeButton_Resize (self .ToggleButton )
939945
946+ self .eventFrame :Show ()
940947 self :StartPurgeTicker ()
941948
942949 self .ProfilerFrame .ScrollBox :Flush ()
@@ -948,11 +955,12 @@ function NAP:DisableLogging()
948955
949956 self .collectData = false
950957
958+ self .eventFrame :Hide ()
951959 if self .purgerTicker then
952960 self .purgerTicker :Cancel ()
953961 end
954962
955- t_wipe ( self . snapshots )
963+ self : ResetMetrics ( )
956964 t_wipe (self .filteredData )
957965 self .dataProvider = nil
958966end
0 commit comments