Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Core/MultiBot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1285,13 +1285,35 @@ local function MB_tostring(v)
return tostring(v)
end
function MultiBot.dprint(...)
if not MultiBot.debug then return end
local debugApi = MultiBot.Debug
if type(debugApi) == "table" and type(debugApi.IsEnabled) == "function" then
if not debugApi.IsEnabled("core") then
return
end
MultiBot.debug = true
elseif not MultiBot.debug then
return
end

local parts = {}
for i=1,select("#", ...) do
parts[#parts+1] = MB_tostring(select(i, ...))
end

local message = "|cffff7f00[MultiBot]|r " .. table.concat(parts, " ")
if type(debugApi) == "table" and type(debugApi.PrintRateLimited) == "function" then
local rateKey = "core.dprint." .. string.lower(tostring(select(1, ...) or "generic"))
debugApi.PrintRateLimited(rateKey, 0.2, "core", message)
return
end

if type(debugApi) == "table" and type(debugApi.Print) == "function" then
debugApi.Print("core", message)
return
end

if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
DEFAULT_CHAT_FRAME:AddMessage("|cffff7f00[MultiBot]|r ".. table.concat(parts, " "))
DEFAULT_CHAT_FRAME:AddMessage(message)
else
print("[MultiBot] ".. table.concat(parts, " "))
end
Expand Down
25 changes: 25 additions & 0 deletions Core/MultiBotAsync.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
if not MultiBot then return end

local function perfCount(counterName, delta)
local debugApi = MultiBot and MultiBot.Debug
if type(debugApi) ~= "table" or type(debugApi.IncrementCounter) ~= "function" or type(debugApi.IsPerfEnabled) ~= "function" or not debugApi.IsPerfEnabled() then
return
end

debugApi.IncrementCounter(counterName, delta)
end

local function perfDuration(counterName, elapsed)
local debugApi = MultiBot and MultiBot.Debug
if type(debugApi) ~= "table" or type(debugApi.AddDuration) ~= "function" or type(debugApi.IsPerfEnabled) ~= "function" or not debugApi.IsPerfEnabled() then
return
end

debugApi.AddDuration(counterName, elapsed)
end

local sharedTimerAfter = MultiBot.TimerAfter or _G.TimerAfter

if type(sharedTimerAfter) ~= "function" then
Expand All @@ -15,22 +33,28 @@ if type(sharedTimerAfter) ~= "function" then
end

sharedTimerAfter = function(delay, callback)
perfCount("scheduler.timerafter.calls")
if type(callback) ~= "function" then
return nil
end

local waitTime = math.max(tonumber(delay) or 0, 0)
perfDuration("scheduler.timerafter.delay_total", waitTime)

if type(C_Timer) == "table" and type(C_Timer.After) == "function" then
perfCount("scheduler.timerafter.ctime")
return C_Timer.After(waitTime, callback)
end

-- M11 ownership: keep this fallback OnUpdate local to the scheduler wrapper only.
-- Reason: legacy compatibility when C_Timer.After is unavailable.
perfCount("scheduler.timerafter.fallback")
local timerFrame = CreateFrame("Frame")
local elapsed = 0

timerFrame:SetScript("OnUpdate", function(self, dt)
perfCount("scheduler.fallback.onupdate.calls")
perfDuration("scheduler.fallback.onupdate.elapsed", tonumber(dt) or 0)
elapsed = elapsed + (tonumber(dt) or 0)
if elapsed < waitTime then
return
Expand All @@ -50,6 +74,7 @@ _G.TimerAfter = sharedTimerAfter
-- M11 scheduler contract:
-- TimerAfter/NextTick are the only delay APIs that should be used outside this file.
function MultiBot.NextTick(callback)
perfCount("scheduler.nexttick.calls")
if type(callback) ~= "function" then
return nil
end
Expand Down
Loading
Loading