81 lines
3.1 KiB
Lua
81 lines
3.1 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Only this optional diagnostic addon's own SavedVariables file is used.
|
|
local addonName = ...
|
|
local frame = CreateFrame("Frame")
|
|
local monotonic = GetTimePreciseSec or GetTime
|
|
local state, trip, previousTick
|
|
local maxTrips, beforeLimit, afterLimit = 8, 240, 240
|
|
|
|
local function readNumber(api)
|
|
if type(api) ~= "function" then return -1 end
|
|
local ok, value = pcall(api)
|
|
if not ok or (issecretvalue and issecretvalue(value)) or type(value) ~= "number" then return -1 end
|
|
return value
|
|
end
|
|
|
|
local function mark(event)
|
|
trip.events[#trip.events + 1] = {event, monotonic(), time()}
|
|
end
|
|
|
|
local function sample(_, elapsed)
|
|
local tick = monotonic()
|
|
-- time() is the local epoch in whole seconds. Each (tick, epoch) pair
|
|
-- bounds the clock offset for offline correlation with VERIFY_WORLD.
|
|
local row = {tick, time(), elapsed, previousTick and (tick - previousTick) or -1,
|
|
readNumber(GetFileStreamingStatus), readNumber(GetBackgroundLoadingStatus)}
|
|
previousTick = tick
|
|
if trip.hidden then
|
|
local rows = trip.after
|
|
rows[#rows + 1] = row
|
|
if #rows == afterLimit then frame:SetScript("OnUpdate", nil) end
|
|
else
|
|
if trip.enteredAt and tick-trip.enteredAt > 20 then
|
|
frame:SetScript("OnUpdate", nil)
|
|
return
|
|
end
|
|
trip.beforeCount = trip.beforeCount + 1
|
|
trip.before[(trip.beforeCount - 1) % beforeLimit + 1] = row
|
|
end
|
|
end
|
|
|
|
local function start()
|
|
trip = {events={}, before={}, after={}, beforeCount=0}
|
|
if #state.trips >= maxTrips then table.remove(state.trips, 1) end
|
|
state.trips[#state.trips + 1] = trip
|
|
previousTick = nil
|
|
frame:SetScript("OnUpdate", sample)
|
|
end
|
|
|
|
for _, event in ipairs({"ADDON_LOADED", "LOADING_SCREEN_ENABLED", "LOADING_SCREEN_DISABLED",
|
|
"PLAYER_ENTERING_WORLD", "PLAYER_LEAVING_WORLD"}) do
|
|
frame:RegisterEvent(event)
|
|
end
|
|
frame:SetScript("OnEvent", function(_, event, unit)
|
|
if event == "ADDON_LOADED" then
|
|
if unit ~= addonName then return end
|
|
state = WoWHybridLoadTiming
|
|
if type(state) ~= "table" or state.version ~= 1 or type(state.trips) ~= "table" then
|
|
state = {version=1, trips={}}
|
|
WoWHybridLoadTiming = state
|
|
end
|
|
start()
|
|
mark(0) -- first UI observation; the screen may already be showing
|
|
elseif state then
|
|
if event == "LOADING_SCREEN_ENABLED" then
|
|
if trip.hidden or trip.shown or trip.left then start() end
|
|
trip.shown = true
|
|
mark(1)
|
|
elseif event == "LOADING_SCREEN_DISABLED" then
|
|
if trip.hidden then return end
|
|
mark(2)
|
|
trip.hidden = true
|
|
frame:SetScript("OnUpdate", sample)
|
|
elseif event == "PLAYER_ENTERING_WORLD" then
|
|
if not trip.enteredAt then mark(3); trip.enteredAt = monotonic() end
|
|
elseif event == "PLAYER_LEAVING_WORLD" then
|
|
if not trip.left then mark(4); trip.left = true end
|
|
end
|
|
end
|
|
end)
|