整理代码
This commit is contained in:
@@ -20,13 +20,9 @@ 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
|
-- ignore the profiler itself
|
||||||
if _internal[f] or info.what ~= "Lua" then
|
if _internal[f] or info.what ~= "Lua" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
-- get the function name if available
|
-- get the function name if available
|
||||||
if info.name then
|
if info.name then _labeled[f] = info.name end
|
||||||
_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
|
||||||
@@ -49,13 +45,6 @@ function profile.hooker(event, line, info)
|
|||||||
end
|
end
|
||||||
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.
|
--- Starts collecting data.
|
||||||
function profile.start()
|
function profile.start()
|
||||||
if rawget(_G, 'jit') then
|
if rawget(_G, 'jit') then
|
||||||
@@ -92,24 +81,15 @@ end
|
|||||||
|
|
||||||
--- Resets all collected data.
|
--- Resets all collected data.
|
||||||
function profile.reset()
|
function profile.reset()
|
||||||
for f in next,_ncalls do
|
for f in next, _ncalls do _ncalls[f] = 0 end
|
||||||
_ncalls[f] = 0
|
for f in next, _telapsed do _telapsed[f] = 0 end
|
||||||
end
|
for f in next, _tcalled do _tcalled[f] = nil end
|
||||||
for f in next,_telapsed do
|
|
||||||
_telapsed[f] = 0
|
|
||||||
end
|
|
||||||
for f in next,_tcalled do
|
|
||||||
_tcalled[f] = nil
|
|
||||||
end
|
|
||||||
collectgarbage('collect')
|
collectgarbage('collect')
|
||||||
end
|
end
|
||||||
|
|
||||||
function profile.comp(a, b)
|
function profile.comp(a, b)
|
||||||
local dt = _telapsed[b] - _telapsed[a]
|
local dt = _telapsed[b] - _telapsed[a]
|
||||||
if dt == 0 then
|
return dt == 0 and _ncalls[b] < _ncalls[a] or dt < 0
|
||||||
return _ncalls[b] < _ncalls[a]
|
|
||||||
end
|
|
||||||
return dt < 0
|
|
||||||
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.
|
||||||
@@ -182,9 +162,7 @@ end
|
|||||||
|
|
||||||
-- store all internal profiler functions
|
-- store all internal profiler functions
|
||||||
for _, v in next, profile do
|
for _, v in next, profile do
|
||||||
if type(v) == "function" then
|
if type(v) == "function" then _internal[v] = true end
|
||||||
_internal[v] = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
Reference in New Issue
Block a user