Skip to content

Commit 504cae8

Browse files
committed
Disabling profiling now no longer clears the list, and instead data is reset when enabling again
1 parent 00ee14e commit 504cae8

File tree

1 file changed

+60
-13
lines changed

1 file changed

+60
-13
lines changed

AddonProfiler.lua

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ do
7474
end
7575
end
7676

77+
--- collect all available data
78+
local ACTIVE_MODE = 'active';
79+
--- collect only total and peak data - disables history range
80+
--- @todo not yet implemented
81+
local PERFORMANCE_MODE = 'performance';
82+
--- collect no data at all, just reset the spike ms counters on reset - disables history range, and maybe show different columns?
83+
--- @todo not yet implemented
84+
local PASSIVE_MODE = 'passive';
85+
86+
--- @todo: add some radio buttons and logic to toggle between modes
87+
NAP.mode = ACTIVE_MODE;
88+
7789
--- @type table<string, { title: string, notes: string, loaded: boolean }>
7890
NAP.addons = {};
7991
--- @type table<string, boolean> # list of addon names
@@ -104,7 +116,7 @@ function NAP:Init()
104116
end
105117
end
106118

107-
self.eventFrame:SetScript('OnUpdate', function() self:OnUpdate() end);
119+
self.eventFrame:SetScript('OnUpdate', function() self:OnUpdateActiveMode() end);
108120
self.eventFrame:SetScript('OnEvent', function(_, event, ...)
109121
if self[event] then self[event](self, ...); end
110122
end);
@@ -130,7 +142,7 @@ function NAP:Init()
130142
end;
131143
RunNextFrame(function()
132144
if NumyProfiler then -- the irony of profiling the profiler (-:
133-
self.OnUpdate = NumyProfiler:Wrap(thisAddonName, 'ProfilerCore', 'OnUpdate', self.OnUpdate);
145+
self.OnUpdateActiveMode = NumyProfiler:Wrap(thisAddonName, 'ProfilerCore', 'OnUpdateActiveMode', self.OnUpdateActiveMode);
134146
self.PurgeOldData = NumyProfiler:Wrap(thisAddonName, 'ProfilerCore', 'PurgeOldData', self.PurgeOldData);
135147
end
136148
end);
@@ -177,7 +189,7 @@ function NAP:InitNewBucket()
177189
return lastBucket;
178190
end
179191

180-
function NAP:OnUpdate()
192+
function NAP:OnUpdateActiveMode()
181193
self.tickNumber = self.tickNumber + 1;
182194

183195
local lastBucket = self.snapshots.lastBucket;
@@ -193,7 +205,27 @@ function NAP:OnUpdate()
193205
for addonName in pairs(self.loadedAddons) do
194206
local lastTickMs = C_AddOnProfiler_GetAddOnMetric(addonName, Enum_AddOnProfilerMetric_LastTime);
195207
if lastTickMs > 0 then
208+
totalMs[addonName] = totalMs[addonName] + lastTickMs;
196209
lastTick[addonName][curTickIndex] = lastTickMs;
210+
if lastTickMs > peakMs[addonName] then
211+
peakMs[addonName] = lastTickMs;
212+
end
213+
end
214+
end
215+
end
216+
217+
--- performance mode OnUpdate script
218+
--- right now the only difference is that it doesn't store the lastTickMs
219+
--- more differences might come up in the future
220+
function NAP:OnUpdatePerformanceMode()
221+
self.tickNumber = self.tickNumber + 1;
222+
223+
local totalMs = self.totalMs;
224+
local peakMs = self.peakMs;
225+
226+
for addonName in pairs(self.loadedAddons) do
227+
local lastTickMs = C_AddOnProfiler_GetAddOnMetric(addonName, Enum_AddOnProfilerMetric_LastTime);
228+
if lastTickMs > 0 then
197229
totalMs[addonName] = totalMs[addonName] + lastTickMs;
198230
if lastTickMs > peakMs[addonName] then
199231
peakMs[addonName] = lastTickMs;
@@ -234,6 +266,9 @@ end
234266

235267
local BUCKET_CUTOFF = 2000; -- rather arbitrary number, but interestingly, the lower your fps, the less often actual work will be performed to purge old data ^^
236268
function NAP:PurgeOldData()
269+
if self.mode ~= ACTIVE_MODE then -- only active mode uses buckets
270+
return;
271+
end
237272
if self.snapshots.lastBucket.curTickIndex > BUCKET_CUTOFF then
238273
self:InitNewBucket();
239274
end
@@ -292,13 +327,22 @@ end
292327
---@field overMsSum number
293328

294329
function NAP:PrepareFilteredData()
295-
-- idc about recycling here, just wipe it
296-
t_wipe(self.filteredData)
297-
self.dataProvider = nil
298330

299-
if not self.collectData then return end
331+
local now = self.ProfilerFrame.frozenAt or GetTime();
332+
333+
local minTimestamp = now - self.curHistoryRange;
334+
335+
local prevTimestamp = self.ProfilerFrame.minTimeStamp;
336+
local prevMatch = self.ProfilerFrame.curMatch;
300337

301-
local minTimestamp = GetTime() - self.curHistoryRange;
338+
if prevTimestamp == minTimestamp and prevMatch == self.curMatch then
339+
return;
340+
end
341+
342+
t_wipe(self.filteredData);
343+
self.dataProvider = nil;
344+
self.ProfilerFrame.minTimeStamp = minTimestamp;
345+
self.ProfilerFrame.curMatch = self.curMatch;
302346

303347
local withinHistory = {};
304348
if 0 ~= self.curHistoryRange then
@@ -949,7 +993,7 @@ function NAP:InitUI()
949993

950994
local STATS_FORMAT = "|cfff8f8f2%s|r"
951995
function stats:Update()
952-
self:SetFormattedText(STATS_FORMAT, continuousUpdate and "Live Updating List" or "Paused")
996+
self:SetFormattedText(STATS_FORMAT, NAP.collectData and (continuousUpdate and "Live Updating List" or "Paused") or "List is |cffff0000frozen|r")
953997
end
954998

955999
self.ToggleButton = CreateFrame("Button", "$parentToggle", display, "UIPanelButtonTemplate, UIButtonTemplate")
@@ -964,6 +1008,7 @@ function NAP:InitUI()
9641008
else
9651009
self:EnableLogging()
9661010
end
1011+
display.Stats:Update()
9671012
end)
9681013

9691014
local resetButton = CreateFrame("Button", "$parentReset", display, "UIPanelButtonTemplate, UIButtonTemplate")
@@ -986,6 +1031,11 @@ function NAP:IsLogging()
9861031
end
9871032

9881033
function NAP:EnableLogging()
1034+
self.ProfilerFrame.frozenAt = nil
1035+
self:ResetMetrics()
1036+
t_wipe(self.filteredData)
1037+
self.dataProvider = nil
1038+
9891039
self.ToggleButton:SetText("Disable")
9901040
DynamicResizeButton_Resize(self.ToggleButton)
9911041

@@ -996,6 +1046,7 @@ function NAP:EnableLogging()
9961046
end
9971047

9981048
function NAP:DisableLogging()
1049+
self.ProfilerFrame.frozenAt = GetTime()
9991050
self.ToggleButton:SetText("Enable")
10001051
DynamicResizeButton_Resize(self.ToggleButton)
10011052

@@ -1005,10 +1056,6 @@ function NAP:DisableLogging()
10051056
if self.purgerTicker then
10061057
self.purgerTicker:Cancel()
10071058
end
1008-
1009-
self:ResetMetrics()
1010-
t_wipe(self.filteredData)
1011-
self.dataProvider = nil
10121059
end
10131060

10141061
function NAP:ToggleFrame()

0 commit comments

Comments
 (0)