Felipe93
Ghost Member
LUA:
-- CATCH SCRIPTS THAT COPNSUMES CPU
local log_slow_exec_startExecProg = os.clock()
local log_slow_exec_currExecProg = ""
local log_slow_exec_ReportTime = 0.005 -- where 1 is 1 second and 0.005 is 5 ms
-- enable disable this logger
local ExtendedDebug = true
debug.sethook(function(event, line)
if ExtendedDebug and log_slow_exec_currExecProg ~= debug.getinfo(2).source then
if log_slow_exec_currExecProg ~= "" then
local execTime = os.clock() - log_slow_exec_startExecProg
if execTime > log_slow_exec_ReportTime then
print(string.format(">>> long file %s executed in %.3f ms", log_slow_exec_currExecProg, execTime*1000))
end
end
end
if ExtendedDebug and log_slow_exec_currExecProg ~= debug.getinfo(2).source then
-- init file changed
log_slow_exec_startExecProg = os.clock()
log_slow_exec_currExecProg = debug.getinfo(2).source
-- print ("source changed: " .. log_slow_exec_currExecProg) -- display source file changed for debugging only
end
end, "l")
local start = os.time()
local linecount = 0
debug.sethook(function(event, line)
linecount = linecount + 1
if os.time() - start >= 1 then
if linecount >= 1000000 then
print(string.format("possible infinite loop in file %s near line %s", debug.getinfo(2).source, line))
debug.sethook()
end
linecount = 0
start = os.time()
end
end, "l")
ThIs should catch the scripts instantly after server opens or the script must be used in order to check if its looping too long or infinite times?