整理代码
This commit is contained in:
@@ -20,13 +20,9 @@ function profile.hooker(event, line, info)
|
||||
info = info or getInfo(2, 'fnS')
|
||||
local f = info.func
|
||||
-- ignore the profiler itself
|
||||
if _internal[f] or info.what ~= "Lua" then
|
||||
return
|
||||
end
|
||||
if _internal[f] or info.what ~= "Lua" then return end
|
||||
-- get the function name if available
|
||||
if info.name then
|
||||
_labeled[f] = info.name
|
||||
end
|
||||
if info.name then _labeled[f] = info.name end
|
||||
-- find the line definition
|
||||
if not _defined[f] then
|
||||
_defined[f] = info.short_src .. ":" .. info.linedefined
|
||||
@@ -49,13 +45,6 @@ function profile.hooker(event, line, info)
|
||||
end
|
||||
end
|
||||
|
||||
--- Sets a clock function to be used by the profiler.
|
||||
-- @param f Clock function that returns a number
|
||||
function profile.setclock(f)
|
||||
assert(type(f) == "function", "clock must be a function")
|
||||
clock = f
|
||||
end
|
||||
|
||||
--- Starts collecting data.
|
||||
function profile.start()
|
||||
if rawget(_G, 'jit') then
|
||||
@@ -92,24 +81,15 @@ end
|
||||
|
||||
--- Resets all collected data.
|
||||
function profile.reset()
|
||||
for f in next,_ncalls do
|
||||
_ncalls[f] = 0
|
||||
end
|
||||
for f in next,_telapsed do
|
||||
_telapsed[f] = 0
|
||||
end
|
||||
for f in next,_tcalled do
|
||||
_tcalled[f] = nil
|
||||
end
|
||||
for f in next, _ncalls do _ncalls[f] = 0 end
|
||||
for f in next, _telapsed do _telapsed[f] = 0 end
|
||||
for f in next, _tcalled do _tcalled[f] = nil end
|
||||
collectgarbage('collect')
|
||||
end
|
||||
|
||||
function profile.comp(a, b)
|
||||
local dt = _telapsed[b] - _telapsed[a]
|
||||
if dt == 0 then
|
||||
return _ncalls[b] < _ncalls[a]
|
||||
end
|
||||
return dt < 0
|
||||
return dt == 0 and _ncalls[b] < _ncalls[a] or dt < 0
|
||||
end
|
||||
|
||||
--- Iterates all functions that have been called since the profile was started.
|
||||
@@ -182,9 +162,7 @@ end
|
||||
|
||||
-- store all internal profiler functions
|
||||
for _, v in next, profile do
|
||||
if type(v) == "function" then
|
||||
_internal[v] = true
|
||||
end
|
||||
if type(v) == "function" then _internal[v] = true end
|
||||
end
|
||||
|
||||
return profile
|
||||
Reference in New Issue
Block a user