Skip to content

Commit

Permalink
add yield sequence count to locals for debug purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
emptyrivers committed Jun 29, 2024
1 parent 1040d87 commit bc29e40
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions WeakAuras/WeakAuras.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,15 @@ function Private.Login(takeNewSnapshots)
for uid, hist in pairs(db.history) do
local histStore = histRepo:Set(uid, hist.data)
local migrationStore = migrationRepo:Set(uid, hist.migration)
coroutine.yield(1000)
coroutine.yield(1000, "login move old history")
end
-- history is now in archive so we can shrink WeakAurasSaved
db.history = nil
end


Private.Features:Hydrate()
coroutine.yield(3000)
coroutine.yield(3000, "login check uid corruption")

local toAdd = {};
loginFinished = false
Expand Down Expand Up @@ -1279,7 +1279,7 @@ function Private.Login(takeNewSnapshots)
else
nextCallback()
end
coroutine.yield(1000);
coroutine.yield(1000, "login post login callbacks");
nextCallback = loginQueue[1];
end

Expand All @@ -1288,7 +1288,7 @@ function Private.Login(takeNewSnapshots)
for _, region in pairs(Private.regions) do
if (region.region and region.region.RunDelayedActions) then
region.region:RunDelayedActions();
coroutine.yield(500)
coroutine.yield(500, "login delayed region actions");
end
end
end)
Expand Down Expand Up @@ -2356,7 +2356,7 @@ local function RepairDatabase()
if snapshot then
newDB[id] = nil
newDB[snapshot.id] = snapshot
coroutine.yield(1000)
coroutine.yield(1000, "repair get snapshot")
end
end
db.displays = newDB
Expand Down Expand Up @@ -2525,25 +2525,25 @@ local function loadOrder(tbl, idtable)
if not(loaded[data.parent]) then
local dependsOut = CopyTable(depends)
dependsOut[data.parent] = true
coroutine.yield(100)
coroutine.yield(100, "sort deps")
load(data.parent, dependsOut)
coroutine.yield(100)
coroutine.yield(100, "sort deps")
end
end
else
data.parent = nil;
end
end
if not(loaded[id]) then
coroutine.yield(100);
coroutine.yield(100, "sort deps");
loaded[id] = true;
tinsert(order, idtable[id])
end
end

for id, data in pairs(idtable) do
load(id, {});
coroutine.yield(100)
coroutine.yield(100, "sort deps")
end

return order
Expand Down Expand Up @@ -2599,7 +2599,7 @@ function Private.AddMany(tbl, takeSnapshots)
oldSnapshots[data.uid] = Private.GetMigrationSnapshot(data.uid)
end
Private.SetMigrationSnapshot(data.uid, data)
coroutine.yield(500)
coroutine.yield(2000, "addmany snapshot")
end
end

Expand All @@ -2620,7 +2620,7 @@ function Private.AddMany(tbl, takeSnapshots)
elseif data.regionType == "dynamicgroup" or data.regionType == "group" then
groups[data] = true
end
coroutine.yield(1000)
coroutine.yield(1000, "addmany modernize")
end
end

Expand All @@ -2635,14 +2635,14 @@ function Private.AddMany(tbl, takeSnapshots)
end
end
end
coroutine.yield(2000)
coroutine.yield(2000, "addmany add")
end

for id in pairs(anchorTargets) do
local data = idtable[id]
if data and not bads[data.id] and (data.parent == nil or idtable[data.parent].regionType ~= "dynamicgroup") then
Private.EnsureRegion(id)
coroutine.yield(100)
coroutine.yield(100, "addmany ensure anchor")
end
end

Expand All @@ -2656,7 +2656,7 @@ function Private.AddMany(tbl, takeSnapshots)
WeakAuras.Add(data)
end
end
coroutine.yield(1000);
coroutine.yield(1000, "addmany reload dynamic group");
end
end

Expand Down Expand Up @@ -4305,15 +4305,18 @@ local threads = {
size = 0,
---@type table<string, threadPriority>
prios = {},
---@type table<string, thread>
---@type table<string, threadData>
instant = {},
---@type table<string, thread>
---@type table<string, threadData>
urgent = {},
---@type table<string, thread>
---@type table<string, threadData>
normal = {},
---@type table<string, thread>
---@type table<string, threadData>
background = {},
};
---@class threadData
---@field thread thread
---@field sequence table<string, number> to help debug problems in threads
do

---@alias threadPriority 'urgent' | 'normal' | 'background'
Expand Down Expand Up @@ -4358,28 +4361,30 @@ do
end


---@param pool table<string, thread>
---@param pool table<string, threadData>
---@param finish number
---@param defaultEstimate number
local function runThreadPool(pool, finish, defaultEstimate)
local start = debugprofilestop()
if finish <= start then return end
local estimates = {}
local ok, val
local ok, val1, val2
local continue = false
repeat
continue = false
for name, thread in pairs(pool) do
for name, threadData in pairs(pool) do
local estimate = estimates[name] or defaultEstimate
if debugprofilestop() + estimate > finish then
break
else
continue = true
ok, val = coroutine.resume(thread)
ok, val1, val2 = coroutine.resume(threadData.thread)
if not ok then
geterrorhandler()(val .. '\n' .. debugstack(thread))
elseif coroutine.status(thread) ~= "dead" then
estimates[name] = type(val) == "number" and val or defaultEstimate
geterrorhandler()(val1 .. '\n' .. debugstack(threadData.thread))
elseif coroutine.status(threadData.thread) ~= "dead" then
estimates[name] = type(val1) == "number" and val1 or defaultEstimate
local sequence = val2 or ""
threadData.sequence[sequence] = (threadData.sequence[sequence] or 0) + 1
else
threads:Remove(name)
end
Expand Down

0 comments on commit bc29e40

Please sign in to comment.