整理代码

This commit is contained in:
MrZ626
2021-02-07 15:02:15 +08:00
parent a8387de735
commit d3ad6ff7bf

View File

@@ -2,27 +2,19 @@ local clock = os.clock
local profile = {} local profile = {}
-- function labels local _labeled = {} -- function labels
local _labeled = {} local _defined = {} -- function definitions
-- function definitions local _tcalled = {} -- time of last call
local _defined = {} local _telapsed = {}-- total execution time
-- time of last call local _ncalls = {} -- number of calls
local _tcalled = {} local _internal = {}-- list of internal profiler functions
-- total execution time
local _telapsed = {}
-- number of calls
local _ncalls = {}
-- list of internal profiler functions
local _internal = {}
local getInfo = debug.getinfo local getInfo = debug.getinfo
function profile.hooker(event, line, info) function profile.hooker(event, line, info)
info = info or getInfo(2, 'fnS') info = info or getInfo(2, 'fnS')
local f = info.func local f = info.func
-- ignore the profiler itself if _internal[f] then return end-- ignore the profiler itself
if _internal[f] then return end if info.name then _labeled[f] = info.name end-- get the function name if available
-- get the function name if available
if info.name then _labeled[f] = info.name end
-- find the line definition -- find the line definition
if not _defined[f] then if not _defined[f] then
_defined[f] = info.short_src .. ":" .. info.linedefined _defined[f] = info.short_src .. ":" .. info.linedefined
@@ -95,7 +87,6 @@ function profile.comp(a, b)
end end
--- Iterates all functions that have been called since the profile was started. --- Iterates all functions that have been called since the profile was started.
-- @param n Number of results (optional)
function profile.query(limit) function profile.query(limit)
local t = {} local t = {}
for f, n in next, _ncalls do for f, n in next, _ncalls do